From a2819c34a0f4f444ea876d51108f0b9177857450 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Thu, 29 Aug 2024 01:35:21 +0800 Subject: [PATCH] Refactor DialectPipelineSQLBuilder.wrapWithPageQuery() (#32717) * Refactor DialectPipelineSQLBuilder.wrapWithPageQuery() * Refactor DialectPipelineSQLBuilder.wrapWithPageQuery() * Refactor DialectPipelineSQLBuilder.wrapWithPageQuery() * Refactor DialectPipelineSQLBuilder.wrapWithPageQuery() * Refactor DialectPipelineSQLBuilder.wrapWithPageQuery() --- .../sqlbuilder/dialect/DialectPipelineSQLBuilder.java | 4 +--- ...PipelineDataConsistencyCalculateSQLBuilderTest.java | 10 +++++----- .../PipelineInventoryDumpSQLBuilderTest.java | 8 ++++---- .../sqlbuilder/fixture/FixturePipelineSQLBuilder.java | 5 +++++ .../mysql/sqlbuilder/MySQLPipelineSQLBuilder.java | 5 +++++ .../sqlbuilder/OpenGaussPipelineSQLBuilder.java | 5 +++++ .../sqlbuilder/PostgreSQLPipelineSQLBuilder.java | 5 +++++ .../fixture/h2/sqlbuilder/H2PipelineSQLBuilder.java | 5 +++++ 8 files changed, 35 insertions(+), 12 deletions(-) diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/dialect/DialectPipelineSQLBuilder.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/dialect/DialectPipelineSQLBuilder.java index 3c190ce57ba5b..accd35edae626 100644 --- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/dialect/DialectPipelineSQLBuilder.java +++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/dialect/DialectPipelineSQLBuilder.java @@ -107,7 +107,5 @@ default Optional buildQueryCurrentPositionSQL() { * @param sql SQL * @return wrapped SQL */ - default String wrapWithPageQuery(String sql) { - return sql + " LIMIT ?"; - } + String wrapWithPageQuery(String sql); } diff --git a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/PipelineDataConsistencyCalculateSQLBuilderTest.java b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/PipelineDataConsistencyCalculateSQLBuilderTest.java index 90ff549657dd0..86754b92e37e1 100644 --- a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/PipelineDataConsistencyCalculateSQLBuilderTest.java +++ b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/PipelineDataConsistencyCalculateSQLBuilderTest.java @@ -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 diff --git a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/PipelineInventoryDumpSQLBuilderTest.java b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/PipelineInventoryDumpSQLBuilderTest.java index b72dd4f44e164..4984b9ad0a1c0 100644 --- a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/PipelineInventoryDumpSQLBuilderTest.java +++ b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/PipelineInventoryDumpSQLBuilderTest.java @@ -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 diff --git a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/fixture/FixturePipelineSQLBuilder.java b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/fixture/FixturePipelineSQLBuilder.java index 66087b5f63dcb..e831ef9f4aee9 100644 --- a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/fixture/FixturePipelineSQLBuilder.java +++ b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/fixture/FixturePipelineSQLBuilder.java @@ -41,6 +41,11 @@ public Collection buildCreateTableSQLs(final DataSource dataSource, fina return Collections.emptyList(); } + @Override + public String wrapWithPageQuery(final String sql) { + return sql; + } + @Override public String getDatabaseType() { return "FIXTURE"; diff --git a/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/sqlbuilder/MySQLPipelineSQLBuilder.java b/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/sqlbuilder/MySQLPipelineSQLBuilder.java index a06fa80441bd0..0d1a9b9a5ab9a 100644 --- a/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/sqlbuilder/MySQLPipelineSQLBuilder.java +++ b/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/sqlbuilder/MySQLPipelineSQLBuilder.java @@ -77,6 +77,11 @@ public Collection 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"; diff --git a/kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/sqlbuilder/OpenGaussPipelineSQLBuilder.java b/kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/sqlbuilder/OpenGaussPipelineSQLBuilder.java index 534710f5b1db7..0ee8e65ebf094 100644 --- a/kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/sqlbuilder/OpenGaussPipelineSQLBuilder.java +++ b/kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/sqlbuilder/OpenGaussPipelineSQLBuilder.java @@ -81,6 +81,11 @@ public Optional 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"; diff --git a/kernel/data-pipeline/dialect/postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/PostgreSQLPipelineSQLBuilder.java b/kernel/data-pipeline/dialect/postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/PostgreSQLPipelineSQLBuilder.java index 181f2fecb4d9d..2991ee4377dbd 100644 --- a/kernel/data-pipeline/dialect/postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/PostgreSQLPipelineSQLBuilder.java +++ b/kernel/data-pipeline/dialect/postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/sqlbuilder/PostgreSQLPipelineSQLBuilder.java @@ -126,6 +126,11 @@ public Optional 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"; diff --git a/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/fixture/h2/sqlbuilder/H2PipelineSQLBuilder.java b/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/fixture/h2/sqlbuilder/H2PipelineSQLBuilder.java index 79254e833dbb2..aa3d2b3dcaa31 100644 --- a/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/fixture/h2/sqlbuilder/H2PipelineSQLBuilder.java +++ b/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/fixture/h2/sqlbuilder/H2PipelineSQLBuilder.java @@ -42,6 +42,11 @@ public Collection 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";