You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2025/02/21 10:14:36 UTC
(shardingsphere) branch master updated: Fix InventoryDumper first time dump SQL without ORDER BY on multiple columns unique key table (#34736)
This is an automated email from the ASF dual-hosted git repository.
menghaoran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 449db05e343 Fix InventoryDumper first time dump SQL without ORDER BY on multiple columns unique key table (#34736)
449db05e343 is described below
commit 449db05e343185d1b2a68399fda9ac535208552f
Author: Hongsheng Zhong <zh...@apache.org>
AuthorDate: Fri Feb 21 18:14:29 2025 +0800
Fix InventoryDumper first time dump SQL without ORDER BY on multiple columns unique key table (#34736)
---
.../core/ingest/dumper/inventory/InventoryDumper.java | 3 +++
.../sqlbuilder/sql/PipelineInventoryDumpSQLBuilder.java | 16 ++++++++++++++++
.../sql/PipelineInventoryDumpSQLBuilderTest.java | 4 ++++
3 files changed, 23 insertions(+)
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/dumper/inventory/InventoryDumper.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/dumper/inventory/InventoryDumper.java
index c3bdd93aca3..b744834efee 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/dumper/inventory/InventoryDumper.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/dumper/inventory/InventoryDumper.java
@@ -332,6 +332,9 @@ public final class InventoryDumper extends AbstractPipelineLifecycleRunnable imp
private String buildFetchAllSQLWithStreamingQuery() {
String schemaName = dumperContext.getCommonContext().getTableAndSchemaNameMapper().getSchemaName(dumperContext.getLogicTableName());
List<String> columnNames = dumperContext.getQueryColumnNames();
+ if (dumperContext.hasUniqueKey()) {
+ return sqlBuilder.buildFetchAllSQL(schemaName, dumperContext.getActualTableName(), columnNames, dumperContext.getUniqueKeyColumns().get(0).getName());
+ }
return sqlBuilder.buildFetchAllSQL(schemaName, dumperContext.getActualTableName(), columnNames);
}
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/sql/PipelineInventoryDumpSQLBuilder.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/sql/PipelineInventoryDumpSQLBuilder.java
index 0127b570605..324013c60d0 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/sql/PipelineInventoryDumpSQLBuilder.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/sql/PipelineInventoryDumpSQLBuilder.java
@@ -104,4 +104,20 @@ public final class PipelineInventoryDumpSQLBuilder {
String queryColumns = columnNames.stream().map(sqlSegmentBuilder::getEscapedIdentifier).collect(Collectors.joining(","));
return String.format("SELECT %s FROM %s", queryColumns, qualifiedTableName);
}
+
+ /**
+ * Build fetch all inventory dump SQL.
+ *
+ * @param schemaName schema name
+ * @param tableName tableName
+ * @param columnNames column names
+ * @param uniqueKey unique key
+ * @return built SQL
+ */
+ public String buildFetchAllSQL(final String schemaName, final String tableName, final Collection<String> columnNames, final String uniqueKey) {
+ String qualifiedTableName = sqlSegmentBuilder.getQualifiedTableName(schemaName, tableName);
+ String queryColumns = columnNames.stream().map(sqlSegmentBuilder::getEscapedIdentifier).collect(Collectors.joining(","));
+ String quotedUniqueKey = sqlSegmentBuilder.getEscapedIdentifier(uniqueKey);
+ return String.format("SELECT %s FROM %s ORDER BY %s ASC", queryColumns, qualifiedTableName, quotedUniqueKey);
+ }
}
diff --git a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/sql/PipelineInventoryDumpSQLBuilderTest.java b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/sql/PipelineInventoryDumpSQLBuilderTest.java
index f721527dc1c..839a51664e6 100644
--- a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/sql/PipelineInventoryDumpSQLBuilderTest.java
+++ b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/sql/PipelineInventoryDumpSQLBuilderTest.java
@@ -65,5 +65,9 @@ class PipelineInventoryDumpSQLBuilderTest {
assertThat(actual, is("SELECT order_id,user_id,status FROM t_order"));
actual = sqlBuilder.buildFetchAllSQL(null, "t_order", Collections.singletonList("*"));
assertThat(actual, is("SELECT * FROM t_order"));
+ actual = sqlBuilder.buildFetchAllSQL(null, "t_order", Arrays.asList("order_id", "user_id", "status"), "order_id");
+ assertThat(actual, is("SELECT order_id,user_id,status FROM t_order ORDER BY order_id ASC"));
+ actual = sqlBuilder.buildFetchAllSQL(null, "t_order", Collections.singletonList("*"), "order_id");
+ assertThat(actual, is("SELECT * FROM t_order ORDER BY order_id ASC"));
}
}