@Test public void testRemoveSampleClauseFromQuery() throws Exception { String q1Expected = "SELECT * FROM x WHERE 1=1"; String q2Expected = "SELECT * FROM x WHERE x.a < 10 AND 1=1"; String q3Expected = "SELECT * FROM x WHERE x.a < 10 AND x.b = 20 AND 1=1"; String q1Parsed = postgresqlExtractor.removeSampleClauseFromQuery(QUERY_1); String q2Parsed = postgresqlExtractor.removeSampleClauseFromQuery(QUERY_2); String q3Parsed = postgresqlExtractor.removeSampleClauseFromQuery(QUERY_3); assertEquals(q1Parsed, q1Expected); assertEquals(q2Parsed, q2Expected); assertEquals(q3Parsed, q3Expected); }
@Override public String removeSampleClauseFromQuery(String query) { if (StringUtils.isBlank(query)) { return null; } String limitString = ""; String inputQuery = query.toLowerCase(); int limitIndex = inputQuery.indexOf(" limit"); if (limitIndex > 0) { limitString = query.substring(limitIndex); } if (inputQuery.contains(" where ")) { String newQuery = query.replace(limitString, " AND 1=1"); if (newQuery.toLowerCase().contains(" where and 1=1")) { return query.replace(limitString, " 1=1"); } return newQuery; } return query.replace(limitString, " where 1=1"); }
PostgresqlExtractor extends JdbcExtractor { @Override public String removeSampleClauseFromQuery(String query) { if (StringUtils.isBlank(query)) { return null; } String limitString = ""; String inputQuery = query.toLowerCase(); int limitIndex = inputQuery.indexOf(" limit"); if (limitIndex > 0) { limitString = query.substring(limitIndex); } if (inputQuery.contains(" where ")) { String newQuery = query.replace(limitString, " AND 1=1"); if (newQuery.toLowerCase().contains(" where and 1=1")) { return query.replace(limitString, " 1=1"); } return newQuery; } return query.replace(limitString, " where 1=1"); } }
PostgresqlExtractor extends JdbcExtractor { @Override public String removeSampleClauseFromQuery(String query) { if (StringUtils.isBlank(query)) { return null; } String limitString = ""; String inputQuery = query.toLowerCase(); int limitIndex = inputQuery.indexOf(" limit"); if (limitIndex > 0) { limitString = query.substring(limitIndex); } if (inputQuery.contains(" where ")) { String newQuery = query.replace(limitString, " AND 1=1"); if (newQuery.toLowerCase().contains(" where and 1=1")) { return query.replace(limitString, " 1=1"); } return newQuery; } return query.replace(limitString, " where 1=1"); } PostgresqlExtractor(WorkUnitState workUnitState); }
PostgresqlExtractor extends JdbcExtractor { @Override public String removeSampleClauseFromQuery(String query) { if (StringUtils.isBlank(query)) { return null; } String limitString = ""; String inputQuery = query.toLowerCase(); int limitIndex = inputQuery.indexOf(" limit"); if (limitIndex > 0) { limitString = query.substring(limitIndex); } if (inputQuery.contains(" where ")) { String newQuery = query.replace(limitString, " AND 1=1"); if (newQuery.toLowerCase().contains(" where and 1=1")) { return query.replace(limitString, " 1=1"); } return newQuery; } return query.replace(limitString, " where 1=1"); } PostgresqlExtractor(WorkUnitState workUnitState); @Override String getHourPredicateCondition(String column, long value, String valueFormat, String operator); @Override String getDatePredicateCondition(String column, long value, String valueFormat, String operator); @Override String getTimestampPredicateCondition(String column, long value, String valueFormat, String operator); @Override List<Command> getSchemaMetadata(String schema, String entity); @Override List<Command> getHighWatermarkMetadata(String schema, String entity, String watermarkColumn,
      List<Predicate> predicateList); @Override List<Command> getCountMetadata(String schema, String entity, WorkUnit workUnit, List<Predicate> predicateList); @Override List<Command> getDataMetadata(String schema, String entity, WorkUnit workUnit, List<Predicate> predicateList); @Override String getConnectionUrl(); @Override Map<String, String> getDataTypeMap(); @Override String getWatermarkSourceFormat(WatermarkType watermarkType); @Override long exractSampleRecordCountFromQuery(String query); @Override String removeSampleClauseFromQuery(String query); @Override String constructSampleClause(); @Override String getLeftDelimitedIdentifier(); @Override String getRightDelimitedIdentifier(); @Override Iterator<JsonElement> getRecordSetFromSourceApi(String schema, String entity, WorkUnit workUnit,
      List<Predicate> predicateList); }
PostgresqlExtractor extends JdbcExtractor { @Override public String removeSampleClauseFromQuery(String query) { if (StringUtils.isBlank(query)) { return null; } String limitString = ""; String inputQuery = query.toLowerCase(); int limitIndex = inputQuery.indexOf(" limit"); if (limitIndex > 0) { limitString = query.substring(limitIndex); } if (inputQuery.contains(" where ")) { String newQuery = query.replace(limitString, " AND 1=1"); if (newQuery.toLowerCase().contains(" where and 1=1")) { return query.replace(limitString, " 1=1"); } return newQuery; } return query.replace(limitString, " where 1=1"); } PostgresqlExtractor(WorkUnitState workUnitState); @Override String getHourPredicateCondition(String column, long value, String valueFormat, String operator); @Override String getDatePredicateCondition(String column, long value, String valueFormat, String operator); @Override String getTimestampPredicateCondition(String column, long value, String valueFormat, String operator); @Override List<Command> getSchemaMetadata(String schema, String entity); @Override List<Command> getHighWatermarkMetadata(String schema, String entity, String watermarkColumn,
      List<Predicate> predicateList); @Override List<Command> getCountMetadata(String schema, String entity, WorkUnit workUnit, List<Predicate> predicateList); @Override List<Command> getDataMetadata(String schema, String entity, WorkUnit workUnit, List<Predicate> predicateList); @Override String getConnectionUrl(); @Override Map<String, String> getDataTypeMap(); @Override String getWatermarkSourceFormat(WatermarkType watermarkType); @Override long exractSampleRecordCountFromQuery(String query); @Override String removeSampleClauseFromQuery(String query); @Override String constructSampleClause(); @Override String getLeftDelimitedIdentifier(); @Override String getRightDelimitedIdentifier(); @Override Iterator<JsonElement> getRecordSetFromSourceApi(String schema, String entity, WorkUnit workUnit,
      List<Predicate> predicateList);  }