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 811e673343c Fix pipeline e2e tests for opengauss (#34226)
811e673343c is described below

commit 811e673343c78d2e89fd485ca1f17abb05ed8c6e
Author: Haoran Meng <[email protected]>
AuthorDate: Thu Jan 2 19:37:54 2025 +0800

    Fix pipeline e2e tests for opengauss (#34226)
---
 .../pipeline/core/metadata/generator/PipelineDDLDecorator.java   | 9 +++++----
 .../opengauss/sqlbuilder/OpenGaussPipelineSQLBuilder.java        | 9 ++++++++-
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLDecorator.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLDecorator.java
index d66f840447c..82fffc4f8eb 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLDecorator.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLDecorator.java
@@ -154,22 +154,23 @@ public final class PipelineDDLDecorator {
         if (queryContext.toLowerCase().startsWith(SET_SEARCH_PATH_PREFIX)) {
             return Optional.empty();
         }
-        return Optional.of(replaceTableNameWithPrefix(queryContext, schemaName 
+ ".", databaseName, parserEngine));
+        return Optional.of(replaceTableNameWithPrefix(queryContext, 
schemaName, databaseName, parserEngine));
     }
     
-    private String replaceTableNameWithPrefix(final String sql, final String 
prefix, final String databaseName, final SQLParserEngine parserEngine) {
+    private String replaceTableNameWithPrefix(final String sql, final String 
schemaName, final String databaseName, final SQLParserEngine parserEngine) {
         SQLStatementContext sqlStatementContext = parseSQL(databaseName, 
parserEngine, sql);
         if (sqlStatementContext instanceof CreateTableStatementContext || 
sqlStatementContext instanceof CommentStatementContext
                 || sqlStatementContext instanceof CreateIndexStatementContext 
|| sqlStatementContext instanceof AlterTableStatementContext) {
             if (((TableAvailable) 
sqlStatementContext).getTablesContext().getSimpleTables().isEmpty()) {
                 return sql;
             }
-            if (((TableAvailable) 
sqlStatementContext).getTablesContext().getSchemaName().isPresent()) {
+            Optional<String> sqlSchemaName = ((TableAvailable) 
sqlStatementContext).getTablesContext().getSchemaName();
+            if (sqlSchemaName.isPresent() && 
sqlSchemaName.get().equals(schemaName)) {
                 return sql;
             }
             Map<SQLSegment, String> replaceMap = new 
TreeMap<>(Comparator.comparing(SQLSegment::getStartIndex));
             TableNameSegment tableNameSegment = ((TableAvailable) 
sqlStatementContext).getTablesContext().getSimpleTables().iterator().next().getTableName();
-            replaceMap.put(tableNameSegment, prefix + 
tableNameSegment.getIdentifier().getValue());
+            replaceMap.put(tableNameSegment, schemaName + "." + 
tableNameSegment.getIdentifier().getValue());
             return doDecorateActualTable(replaceMap, sql);
         }
         return sql;
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 c8bed443030..11f31994fa2 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
@@ -70,7 +70,14 @@ public final class OpenGaussPipelineSQLBuilder implements 
DialectPipelineSQLBuil
                 ResultSet resultSet = 
statement.executeQuery(String.format("SELECT * FROM pg_get_tabledef('%s.%s')", 
schemaName, tableName))) {
             if (resultSet.next()) {
                 // TODO use ";" to split is not always correct if return 
value's comments contains ";"
-                return 
Arrays.asList(resultSet.getString("pg_get_tabledef").split(";"));
+                Collection<String> defSQLs = 
Arrays.asList(resultSet.getString("pg_get_tabledef").split(";"));
+                return defSQLs.stream().map(sql -> {
+                    String targetPrefix = "ALTER TABLE " + tableName;
+                    if (sql.trim().startsWith(targetPrefix)) {
+                        return sql.replaceFirst(targetPrefix, "ALTER TABLE " + 
schemaName + "." + tableName);
+                    }
+                    return sql;
+                }).collect(Collectors.toList());
             }
         }
         throw new CreateTableSQLGenerateException(tableName);

Reply via email to