Skip to content

Commit

Permalink
Refactor DialectPipelineSQLBuilder.wrapWithPageQuery() (apache#32717)
Browse files Browse the repository at this point in the history
* Refactor DialectPipelineSQLBuilder.wrapWithPageQuery()

* Refactor DialectPipelineSQLBuilder.wrapWithPageQuery()

* Refactor DialectPipelineSQLBuilder.wrapWithPageQuery()

* Refactor DialectPipelineSQLBuilder.wrapWithPageQuery()

* Refactor DialectPipelineSQLBuilder.wrapWithPageQuery()
  • Loading branch information
terrymanu authored Aug 28, 2024
1 parent f737919 commit a2819c3
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,5 @@ default Optional<String> buildQueryCurrentPositionSQL() {
* @param sql SQL
* @return wrapped SQL
*/
default String wrapWithPageQuery(String sql) {
return sql + " LIMIT ?";
}
String wrapWithPageQuery(String sql);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ class PipelineDataConsistencyCalculateSQLBuilderTest {
void assertBuildQueryRangeOrderingSQLWithoutQueryCondition() {
String actual = pipelineSQLBuilder.buildQueryRangeOrderingSQL(null, "t_order", COLUMN_NAMES, UNIQUE_KEYS,
new QueryRange(1, true, 5), SHARDING_COLUMNS_NAMES);
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>=? AND order_id<=? ORDER BY order_id ASC, status ASC, user_id ASC LIMIT ?"));
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>=? AND order_id<=? ORDER BY order_id ASC, status ASC, user_id ASC"));
actual = pipelineSQLBuilder.buildQueryRangeOrderingSQL(null, "t_order", COLUMN_NAMES, UNIQUE_KEYS,
new QueryRange(1, false, 5), SHARDING_COLUMNS_NAMES);
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>? AND order_id<=? ORDER BY order_id ASC, status ASC, user_id ASC LIMIT ?"));
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>? AND order_id<=? ORDER BY order_id ASC, status ASC, user_id ASC"));
actual = pipelineSQLBuilder.buildQueryRangeOrderingSQL(null, "t_order", COLUMN_NAMES, UNIQUE_KEYS,
new QueryRange(1, false, null), SHARDING_COLUMNS_NAMES);
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>? ORDER BY order_id ASC, status ASC, user_id ASC LIMIT ?"));
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>? ORDER BY order_id ASC, status ASC, user_id ASC"));
actual = pipelineSQLBuilder.buildQueryRangeOrderingSQL(null, "t_order", COLUMN_NAMES, UNIQUE_KEYS,
new QueryRange(null, false, 5), SHARDING_COLUMNS_NAMES);
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id<=? ORDER BY order_id ASC, status ASC, user_id ASC LIMIT ?"));
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id<=? ORDER BY order_id ASC, status ASC, user_id ASC"));
actual = pipelineSQLBuilder.buildQueryRangeOrderingSQL(null, "t_order", COLUMN_NAMES, UNIQUE_KEYS,
new QueryRange(null, false, null), SHARDING_COLUMNS_NAMES);
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order ORDER BY order_id ASC, status ASC, user_id ASC LIMIT ?"));
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order ORDER BY order_id ASC, status ASC, user_id ASC"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ class PipelineInventoryDumpSQLBuilderTest {
@Test
void assertBuildDivisibleSQL() {
String actual = inventoryDumpSQLBuilder.buildDivisibleSQL(new BuildDivisibleSQLParameter(null, "t_order", Arrays.asList("order_id", "user_id", "status"), "order_id", true, true));
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>=? AND order_id<=? ORDER BY order_id ASC LIMIT ?"));
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>=? AND order_id<=? ORDER BY order_id ASC"));
actual = inventoryDumpSQLBuilder.buildDivisibleSQL(new BuildDivisibleSQLParameter(null, "t_order", Arrays.asList("order_id", "user_id", "status"), "order_id", false, true));
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>? AND order_id<=? ORDER BY order_id ASC LIMIT ?"));
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>? AND order_id<=? ORDER BY order_id ASC"));
}

@Test
void assertBuildUnlimitedDivisibleSQL() {
String actual = inventoryDumpSQLBuilder.buildDivisibleSQL(new BuildDivisibleSQLParameter(null, "t_order", Arrays.asList("order_id", "user_id", "status"), "order_id", true, false));
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>=? ORDER BY order_id ASC LIMIT ?"));
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>=? ORDER BY order_id ASC"));
actual = inventoryDumpSQLBuilder.buildDivisibleSQL(new BuildDivisibleSQLParameter(null, "t_order", Arrays.asList("order_id", "user_id", "status"), "order_id", false, false));
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>? ORDER BY order_id ASC LIMIT ?"));
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>? ORDER BY order_id ASC"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public Collection<String> buildCreateTableSQLs(final DataSource dataSource, fina
return Collections.emptyList();
}

@Override
public String wrapWithPageQuery(final String sql) {
return sql;
}

@Override
public String getDatabaseType() {
return "FIXTURE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public Collection<String> buildCreateTableSQLs(final DataSource dataSource, fina
throw new CreateTableSQLGenerateException(tableName);
}

@Override
public String wrapWithPageQuery(final String sql) {
return sql + " LIMIT ?";
}

@Override
public String getDatabaseType() {
return "MySQL";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public Optional<String> buildQueryCurrentPositionSQL() {
return Optional.of("SELECT * FROM pg_current_xlog_location()");
}

@Override
public String wrapWithPageQuery(final String sql) {
return sql + " LIMIT ?";
}

@Override
public String getDatabaseType() {
return "openGauss";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public Optional<String> buildQueryCurrentPositionSQL() {
return Optional.of("SELECT * FROM pg_current_wal_lsn()");
}

@Override
public String wrapWithPageQuery(final String sql) {
return sql + " LIMIT ?";
}

@Override
public String getDatabaseType() {
return "PostgreSQL";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public Collection<String> buildCreateTableSQLs(final DataSource dataSource, fina
return Collections.singleton(PipelineContextUtils.getCreateOrderTableSchema());
}

@Override
public String wrapWithPageQuery(final String sql) {
return sql + " LIMIT ?";
}

@Override
public String getDatabaseType() {
return "H2";
Expand Down

0 comments on commit a2819c3

Please sign in to comment.