diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/EncryptSQLParsingEngine.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/EncryptSQLParsingEngine.java index 133ca06dbc0f4..23ab627769eee 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/EncryptSQLParsingEngine.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/EncryptSQLParsingEngine.java @@ -22,7 +22,6 @@ import org.apache.shardingsphere.core.metadata.table.ShardingTableMetaData; import org.apache.shardingsphere.core.parse.antlr.sql.statement.SQLStatement; import org.apache.shardingsphere.core.parse.cache.ParsingResultCache; -import org.apache.shardingsphere.core.parse.parser.sql.AbstractSQLStatement; import org.apache.shardingsphere.core.parse.parser.sql.SQLParserFactory; import org.apache.shardingsphere.core.rule.EncryptRule; @@ -61,9 +60,6 @@ public SQLStatement parse(final boolean useCache, final String sql) { return cachedSQLStatement.get(); } SQLStatement result = SQLParserFactory.newInstance(dbType, encryptRule, shardingTableMetaData, sql).parse(); - if (result instanceof AbstractSQLStatement) { - ((AbstractSQLStatement) result).setLogicSQL(sql); - } if (useCache) { parsingResultCache.put(sql, result); } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/SQLParsingEngine.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/SQLParsingEngine.java index 4e09cbc627433..8ae37c7f6d7d4 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/SQLParsingEngine.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/SQLParsingEngine.java @@ -25,7 +25,6 @@ import org.apache.shardingsphere.core.parse.cache.ParsingResultCache; import org.apache.shardingsphere.core.parse.lexer.LexerEngine; import org.apache.shardingsphere.core.parse.lexer.LexerEngineFactory; -import org.apache.shardingsphere.core.parse.parser.sql.AbstractSQLStatement; import org.apache.shardingsphere.core.parse.parser.sql.SQLParserFactory; import org.apache.shardingsphere.core.rule.ShardingRule; @@ -60,9 +59,6 @@ public SQLStatement parse(final boolean useCache) { } LexerEngine lexerEngine = LexerEngineFactory.newInstance(dbType, sql); SQLStatement result = SQLParserFactory.newInstance(dbType, shardingRule, lexerEngine, shardingTableMetaData, sql).parse(); - if (result instanceof AbstractSQLStatement) { - ((AbstractSQLStatement) result).setLogicSQL(sql); - } if (useCache) { parsingResultCache.put(sql, result); } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/SQLSegmentFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/SQLSegmentFiller.java index 847bf3719f106..71027452d7ced 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/SQLSegmentFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/SQLSegmentFiller.java @@ -38,9 +38,8 @@ public interface SQLSegmentFiller { * * @param sqlSegment SQL segment * @param sqlStatement SQL statement - * @param sql SQL * @param rule rule * @param shardingTableMetaData sharding table meta data */ - void fill(T sqlSegment, SQLStatement sqlStatement, String sql, R rule, ShardingTableMetaData shardingTableMetaData); + void fill(T sqlSegment, SQLStatement sqlStatement, R rule, ShardingTableMetaData shardingTableMetaData); } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/SQLStatementFillerEngine.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/SQLStatementFillerEngine.java index a661f35136c0a..df02e75420e26 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/SQLStatementFillerEngine.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/SQLStatementFillerEngine.java @@ -68,10 +68,11 @@ public SQLStatementFillerEngine(final ParsingRuleRegistry parsingRuleRegistry, @SneakyThrows public SQLStatement fill(final Collection sqlSegments, final SQLStatementRule rule) { SQLStatement result = rule.getSqlStatementClass().newInstance(); + result.setLogicSQL(sql); for (SQLSegment each : sqlSegments) { Optional filler = parsingRuleRegistry.findSQLSegmentFiller(databaseType, each.getClass()); if (filler.isPresent()) { - (filler.get()).fill(each, result, sql, this.rule, shardingTableMetaData); + (filler.get()).fill(each, result, this.rule, shardingTableMetaData); } } return result; diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dal/ShowParamFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dal/ShowParamFiller.java index 49b3b541c4e27..c18fb97ad33db 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dal/ShowParamFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dal/ShowParamFiller.java @@ -32,7 +32,7 @@ public final class ShowParamFiller implements SQLSegmentFiller { @Override - public void fill(final ShowParamSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final ShowParamSegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { ((ShowStatement) sqlStatement).setName(sqlSegment.getName()); } } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/ColumnDefinitionFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/ColumnDefinitionFiller.java index ec6baf8d96022..17d6707a98d6d 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/ColumnDefinitionFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/ColumnDefinitionFiller.java @@ -32,7 +32,7 @@ public final class ColumnDefinitionFiller implements SQLSegmentFiller { @Override - public void fill(final ColumnDefinitionSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final ColumnDefinitionSegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { ((CreateTableStatement) sqlStatement).getColumnDefinitions().add(sqlSegment); } } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/CommonTableFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/CommonTableFiller.java index 1046c8a84c2e3..41002a001c45f 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/CommonTableFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/CommonTableFiller.java @@ -32,7 +32,7 @@ public class CommonTableFiller implements SQLSegmentFiller { @Override - public void fill(final TableSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final TableSegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { sqlStatement.getTables().add(new Table(sqlSegment.getName(), sqlSegment.getAlias())); } } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/ConstraintDefinitionFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/ConstraintDefinitionFiller.java index 74ba4cc063775..954dff56ef194 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/ConstraintDefinitionFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/ConstraintDefinitionFiller.java @@ -35,7 +35,7 @@ public final class ConstraintDefinitionFiller implements SQLSegmentFiller { @Override - public void fill(final ConstraintDefinitionSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final ConstraintDefinitionSegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { if (sqlStatement instanceof CreateTableStatement) { fill(sqlSegment, (CreateTableStatement) sqlStatement); } else if (sqlStatement instanceof AlterTableStatement) { diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/IndexFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/IndexFiller.java index 571b3d3aa4809..982430aa31c3d 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/IndexFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/IndexFiller.java @@ -32,7 +32,7 @@ public final class IndexFiller implements SQLSegmentFiller { @Override - public void fill(final IndexSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final IndexSegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { IndexToken indexToken = sqlSegment.getToken(); if (!sqlStatement.getTables().isEmpty() && null == indexToken.getTableName()) { indexToken.setTableName(sqlStatement.getTables().getSingleTableName()); diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/AddColumnDefinitionFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/AddColumnDefinitionFiller.java index 437d5874fb8bf..a16b61a6d57a1 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/AddColumnDefinitionFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/AddColumnDefinitionFiller.java @@ -32,8 +32,7 @@ public final class AddColumnDefinitionFiller implements SQLSegmentFiller { @Override - public void fill(final AddColumnDefinitionSegment sqlSegment, - final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final AddColumnDefinitionSegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { AlterTableStatement alterTableStatement = (AlterTableStatement) sqlStatement; if (!alterTableStatement.findColumnDefinitionFromMetaData(sqlSegment.getColumnDefinition().getColumnName(), shardingTableMetaData).isPresent()) { alterTableStatement.getAddedColumnDefinitions().add(sqlSegment.getColumnDefinition()); diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/DropColumnDefinitionFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/DropColumnDefinitionFiller.java index 28d0685c28dcb..1bdeadd026fda 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/DropColumnDefinitionFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/DropColumnDefinitionFiller.java @@ -32,8 +32,7 @@ public final class DropColumnDefinitionFiller implements SQLSegmentFiller { @Override - public void fill(final DropColumnDefinitionSegment sqlSegment, - final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final DropColumnDefinitionSegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { ((AlterTableStatement) sqlStatement).getDroppedColumnNames().add(sqlSegment.getColumnName()); } } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/DropPrimaryKeyFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/DropPrimaryKeyFiller.java index 0586090af929f..e90b79a15f9a4 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/DropPrimaryKeyFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/DropPrimaryKeyFiller.java @@ -32,7 +32,7 @@ public final class DropPrimaryKeyFiller implements SQLSegmentFiller { @Override - public void fill(final DropPrimaryKeySegment sqlSegment, final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final DropPrimaryKeySegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { ((AlterTableStatement) sqlStatement).setDropPrimaryKey(true); } } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/ModifyColumnDefinitionFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/ModifyColumnDefinitionFiller.java index 6623fa91df203..b7a413cbbfc9a 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/ModifyColumnDefinitionFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/ModifyColumnDefinitionFiller.java @@ -34,8 +34,7 @@ public final class ModifyColumnDefinitionFiller implements SQLSegmentFiller { @Override - public void fill(final ModifyColumnDefinitionSegment sqlSegment, - final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final ModifyColumnDefinitionSegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { AlterTableStatement alterTableStatement = (AlterTableStatement) sqlStatement; Optional oldColumnName = sqlSegment.getOldColumnName(); if (oldColumnName.isPresent()) { diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/RenameColumnDefinitionFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/RenameColumnDefinitionFiller.java index 73e7330381c03..afaf82ae62c69 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/RenameColumnDefinitionFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/RenameColumnDefinitionFiller.java @@ -34,7 +34,7 @@ public final class RenameColumnDefinitionFiller implements SQLSegmentFiller { @Override - public void fill(final RenameColumnSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final RenameColumnSegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { AlterTableStatement alterTableStatement = (AlterTableStatement) sqlStatement; Optional oldColumnDefinition = alterTableStatement.findColumnDefinition(sqlSegment.getOldColumnName(), shardingTableMetaData); if (!oldColumnDefinition.isPresent()) { diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/RenameTableFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/RenameTableFiller.java index 66784f6541a01..27bed50468dd0 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/RenameTableFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/ddl/alter/RenameTableFiller.java @@ -32,7 +32,7 @@ public final class RenameTableFiller implements SQLSegmentFiller { @Override - public void fill(final RenameTableSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final RenameTableSegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { ((AlterTableStatement) sqlStatement).setNewTableName(sqlSegment.getNewTableName()); } } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dml/InsertColumnsFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dml/InsertColumnsFiller.java index 8e24109111f77..859e4b60ce2e7 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dml/InsertColumnsFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dml/InsertColumnsFiller.java @@ -38,7 +38,7 @@ public final class InsertColumnsFiller implements SQLSegmentFiller { @Override - public void fill(final InsertColumnsSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final InsertColumnsSegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { if (sqlStatement instanceof InsertStatement) { InsertStatement insertStatement = (InsertStatement) sqlStatement; if (sqlSegment.getColumns().isEmpty()) { diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/GroupByFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/GroupByFiller.java index 465f620a4fae3..13277cb62b75d 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/GroupByFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/GroupByFiller.java @@ -34,7 +34,7 @@ public final class GroupByFiller implements SQLSegmentFiller { @Override - public void fill(final GroupBySegment sqlSegment, final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final GroupBySegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { SelectStatement selectStatement = (SelectStatement) sqlStatement; selectStatement.setGroupByLastIndex(sqlSegment.getGroupByStopIndex()); for (OrderByItemSegment each : sqlSegment.getGroupByItems()) { diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/LimitFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/LimitFiller.java index b9c309f422578..745576cbdf522 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/LimitFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/LimitFiller.java @@ -39,7 +39,7 @@ public final class LimitFiller implements SQLSegmentFiller { @Override - public void fill(final LimitSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final LimitSegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { SelectStatement selectStatement = (SelectStatement) sqlStatement; selectStatement.setLimit(new Limit()); if (sqlSegment.getOffset().isPresent()) { diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/OrderByFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/OrderByFiller.java index 165cf3a2ad077..27f368affe320 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/OrderByFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/OrderByFiller.java @@ -33,7 +33,7 @@ public final class OrderByFiller implements SQLSegmentFiller { @Override - public void fill(final OrderBySegment sqlSegment, final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final OrderBySegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { SelectStatement selectStatement = (SelectStatement) sqlStatement; for (OrderByItemSegment each : sqlSegment.getOrderByItems()) { selectStatement.getOrderByItems().add(new OrderItemBuilder(selectStatement, each).createOrderItem()); diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/SelectClauseFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/SelectClauseFiller.java index f1f91e707df8f..98e66e02723a3 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/SelectClauseFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/SelectClauseFiller.java @@ -47,30 +47,30 @@ public final class SelectClauseFiller implements SQLSegmentFiller selectItemSegmentIterator = selectClauseSegment.getSelectItems().iterator(); SelectItemSegment firstSelectItemSegment = selectItemSegmentIterator.next(); Set distinctColumnNames = new LinkedHashSet<>(); DistinctSelectItem distinctSelectItem = null; int offset = 0; if (firstSelectItemSegment instanceof StarSelectItemSegment) { - selectItemFiller.fill(firstSelectItemSegment, selectStatement, sql, rule, shardingTableMetaData); + selectItemFiller.fill(firstSelectItemSegment, selectStatement, rule, shardingTableMetaData); selectStatement.getItems().add(new DistinctSelectItem(distinctColumnNames, Optional.absent())); } else if (firstSelectItemSegment instanceof ColumnSelectItemSegment) { ColumnSelectItemSegment columnSelectItemSegment = (ColumnSelectItemSegment) firstSelectItemSegment; @@ -78,14 +78,14 @@ private void fillDistinct(final SelectClauseSegment selectClauseSegment, selectStatement.getItems().add(distinctSelectItem); distinctColumnNames.add(columnSelectItemSegment.getName()); } else if (firstSelectItemSegment instanceof ExpressionSelectItemSegment) { - distinctSelectItem = createDistinctExpressionItem(selectStatement, sql, distinctColumnNames, (ExpressionSelectItemSegment) firstSelectItemSegment); + distinctSelectItem = createDistinctExpressionItem(selectStatement, distinctColumnNames, (ExpressionSelectItemSegment) firstSelectItemSegment); } else { offset = setDistinctFunctionAlias(firstSelectItemSegment, offset); - selectItemFiller.fill(firstSelectItemSegment, selectStatement, sql, rule, shardingTableMetaData); + selectItemFiller.fill(firstSelectItemSegment, selectStatement, rule, shardingTableMetaData); } while (selectItemSegmentIterator.hasNext()) { SelectItemSegment nextSelectItemSegment = selectItemSegmentIterator.next(); - selectItemFiller.fill(nextSelectItemSegment, selectStatement, sql, rule, shardingTableMetaData); + selectItemFiller.fill(nextSelectItemSegment, selectStatement, rule, shardingTableMetaData); if (nextSelectItemSegment instanceof ColumnSelectItemSegment) { offset = setDistinctFunctionAlias(nextSelectItemSegment, offset); distinctColumnNames.add(((ColumnSelectItemSegment) nextSelectItemSegment).getName()); @@ -108,10 +108,10 @@ private int setDistinctFunctionAlias(final SelectItemSegment selectItemSegment, return offset; } - private DistinctSelectItem createDistinctExpressionItem(final SelectStatement selectStatement, final String sql, final Set distinctColumnNames, + private DistinctSelectItem createDistinctExpressionItem(final SelectStatement selectStatement, final Set distinctColumnNames, final ExpressionSelectItemSegment expressionSelectItemSegment) { DistinctSelectItem distinctSelectItem = new DistinctSelectItem(distinctColumnNames, expressionSelectItemSegment.getAlias()); - String commonExpression = sql.substring(expressionSelectItemSegment.getStartIndex(), expressionSelectItemSegment.getStopIndex() + 1); + String commonExpression = selectStatement.getLogicSQL().substring(expressionSelectItemSegment.getStartIndex(), expressionSelectItemSegment.getStopIndex() + 1); int leftParenPosition = commonExpression.indexOf("("); if (0 <= leftParenPosition) { int rightParenPosition = commonExpression.lastIndexOf(")"); diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/SelectItemFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/SelectItemFiller.java index fce5f750aceff..874f9de297d2a 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/SelectItemFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/SelectItemFiller.java @@ -49,7 +49,7 @@ public final class SelectItemFiller implements SQLSegmentFiller { @Override - public void fill(final SQLSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final SQLSegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { if (!(sqlStatement instanceof SelectStatement)) { return; } @@ -67,11 +67,11 @@ public void fill(final SQLSegment sqlSegment, final SQLStatement sqlStatement, f return; } if (sqlSegment instanceof AggregationSelectItemSegment) { - fillAggregationSelectItemSegment((AggregationSelectItemSegment) sqlSegment, selectStatement, sql); + fillAggregationSelectItemSegment((AggregationSelectItemSegment) sqlSegment, selectStatement); return; } if (sqlSegment instanceof SubquerySegment) { - fillSubquerySegment((SubquerySegment) sqlSegment, sqlStatement, sql, rule, shardingTableMetaData); + fillSubquerySegment((SubquerySegment) sqlSegment, sqlStatement, rule, shardingTableMetaData); } } @@ -102,18 +102,18 @@ private void fillExpressionSelectItemSegment(final ExpressionSelectItemSegment s selectStatement.getItems().add(new CommonSelectItem(selectItemSegment.getExpression(), selectItemSegment.getAlias())); } - private void fillAggregationSelectItemSegment(final AggregationSelectItemSegment selectItemSegment, final SelectStatement selectStatement, final String sql) { + private void fillAggregationSelectItemSegment(final AggregationSelectItemSegment selectItemSegment, final SelectStatement selectStatement) { if (selectItemSegment instanceof AggregationDistinctSelectItemSegment) { - fillAggregationDistinctSelectItemSegment((AggregationDistinctSelectItemSegment) selectItemSegment, selectStatement, sql); + fillAggregationDistinctSelectItemSegment((AggregationDistinctSelectItemSegment) selectItemSegment, selectStatement); } else { - selectStatement.getItems().add(new AggregationSelectItem(selectItemSegment.getType(), - sql.substring(selectItemSegment.getInnerExpressionStartIndex(), selectItemSegment.getStopIndex() + 1), selectItemSegment.getAlias())); + selectStatement.getItems().add(new AggregationSelectItem(selectItemSegment.getType(), + selectStatement.getLogicSQL().substring(selectItemSegment.getInnerExpressionStartIndex(), selectItemSegment.getStopIndex() + 1), selectItemSegment.getAlias())); } } - private void fillAggregationDistinctSelectItemSegment(final AggregationDistinctSelectItemSegment selectItemSegment, final SelectStatement selectStatement, final String sql) { - selectStatement.getItems().add(new AggregationDistinctSelectItem(selectItemSegment.getType(), - sql.substring(selectItemSegment.getInnerExpressionStartIndex(), selectItemSegment.getStopIndex() + 1), selectItemSegment.getAlias(), selectItemSegment.getDistinctExpression())); + private void fillAggregationDistinctSelectItemSegment(final AggregationDistinctSelectItemSegment selectItemSegment, final SelectStatement selectStatement) { + selectStatement.getItems().add(new AggregationDistinctSelectItem(selectItemSegment.getType(), selectStatement.getLogicSQL().substring(selectItemSegment.getInnerExpressionStartIndex(), + selectItemSegment.getStopIndex() + 1), selectItemSegment.getAlias(), selectItemSegment.getDistinctExpression())); Optional derivedAlias = Optional.absent(); if (DerivedAlias.isDerivedAlias(selectItemSegment.getAlias().get())) { derivedAlias = Optional.of(selectItemSegment.getAlias().get()); @@ -121,7 +121,7 @@ private void fillAggregationDistinctSelectItemSegment(final AggregationDistinctS selectStatement.getSQLTokens().add(new AggregationDistinctToken(selectItemSegment.getStartIndex(), selectItemSegment.getStopIndex(), selectItemSegment.getDistinctExpression(), derivedAlias)); } - private void fillSubquerySegment(final SubquerySegment subquerySegment, final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { - new SubqueryFiller().fill(subquerySegment, sqlStatement, sql, rule, shardingTableMetaData); + private void fillSubquerySegment(final SubquerySegment subquerySegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + new SubqueryFiller().fill(subquerySegment, sqlStatement, rule, shardingTableMetaData); } } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/SubqueryFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/SubqueryFiller.java index 666b40fccfb41..0a7f7fc65ab95 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/SubqueryFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/dql/SubqueryFiller.java @@ -32,13 +32,13 @@ public final class SubqueryFiller implements SQLSegmentFiller { @Override - public void fill(final SubquerySegment sqlSegment, final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final SubquerySegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { SelectStatement selectStatement = (SelectStatement) sqlStatement; SelectStatement subqueryStatement = new SelectStatement(); subqueryStatement.setParentStatement(selectStatement); selectStatement.getSubqueryStatements().add(subqueryStatement); if (sqlSegment.getSelectClauseSegment().isPresent()) { - new SelectClauseFiller().fill(sqlSegment.getSelectClauseSegment().get(), subqueryStatement, sql, rule, shardingTableMetaData); + new SelectClauseFiller().fill(sqlSegment.getSelectClauseSegment().get(), subqueryStatement, rule, shardingTableMetaData); } if (sqlSegment.getFromWhereSegment().isPresent()) { // new FromWhereFiller().fill(sqlSegment.getFromWhereSegment().get(), subqueryStatement, sql, shardingTableMetaData); @@ -47,10 +47,10 @@ public void fill(final SubquerySegment sqlSegment, final SQLStatement sqlStateme return; } if (sqlSegment.getGroupBySegment().isPresent()) { - new GroupByFiller().fill(sqlSegment.getGroupBySegment().get(), subqueryStatement, sql, rule, shardingTableMetaData); + new GroupByFiller().fill(sqlSegment.getGroupBySegment().get(), subqueryStatement, rule, shardingTableMetaData); } if (sqlSegment.getOrderBySegment().isPresent()) { - new OrderByFiller().fill(sqlSegment.getOrderBySegment().get(), subqueryStatement, sql, rule, shardingTableMetaData); + new OrderByFiller().fill(sqlSegment.getOrderBySegment().get(), subqueryStatement, rule, shardingTableMetaData); } } } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/tcl/SetAutoCommitFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/tcl/SetAutoCommitFiller.java index 192c2c68bcc76..362a8ee2db29e 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/tcl/SetAutoCommitFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/common/tcl/SetAutoCommitFiller.java @@ -33,7 +33,7 @@ public final class SetAutoCommitFiller implements SQLSegmentFiller { @Override - public void fill(final SQLSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final SQLSegment sqlSegment, final SQLStatement sqlStatement, final BaseRule rule, final ShardingTableMetaData shardingTableMetaData) { SetAutoCommitSegment setAutoCommitSegment = (SetAutoCommitSegment) sqlSegment; ((SetAutoCommitStatement) sqlStatement).setAutoCommit(setAutoCommitSegment.isAutoCommit()); } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptDeleteFromWhereFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptDeleteFromWhereFiller.java index 7f85df1c6771b..ad9f380f63bd0 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptDeleteFromWhereFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptDeleteFromWhereFiller.java @@ -34,8 +34,8 @@ public class EncryptDeleteFromWhereFiller extends EncryptFromWhereFiller { @Override - public void fill(final FromWhereSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final EncryptRule encryptRule, final ShardingTableMetaData shardingTableMetaData) { - super.fill(sqlSegment, sqlStatement, sql, encryptRule, shardingTableMetaData); + public void fill(final FromWhereSegment sqlSegment, final SQLStatement sqlStatement, final EncryptRule encryptRule, final ShardingTableMetaData shardingTableMetaData) { + super.fill(sqlSegment, sqlStatement, encryptRule, shardingTableMetaData); DeleteFromWhereSegment deleteFromWhereSegment = (DeleteFromWhereSegment) sqlSegment; DMLStatement dmlStatement = (DMLStatement) sqlStatement; dmlStatement.setDeleteStatement(true); diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptFromWhereFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptFromWhereFiller.java index 1946bb75d1a5b..64f2a8d5ec869 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptFromWhereFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptFromWhereFiller.java @@ -29,16 +29,15 @@ * @author duhongjun */ public class EncryptFromWhereFiller implements SQLSegmentFiller { - + @Override - public void fill(final FromWhereSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final EncryptRule encryptRule, + public void fill(final FromWhereSegment sqlSegment, final SQLStatement sqlStatement, final EncryptRule encryptRule, final ShardingTableMetaData shardingTableMetaData) { - new EncryptOrConditionFiller().fill(sqlSegment.getConditions(), sqlStatement, sql, encryptRule, shardingTableMetaData); + new EncryptOrConditionFiller().fill(sqlSegment.getConditions(), sqlStatement, encryptRule, shardingTableMetaData); int count = 0; while (count < sqlSegment.getParameterCount()) { sqlStatement.increaseParametersIndex(); count++; } } - } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptOrConditionFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptOrConditionFiller.java index 49f1fb5b2446c..db302039f6d2a 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptOrConditionFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptOrConditionFiller.java @@ -46,12 +46,12 @@ public class EncryptOrConditionFiller implements SQLSegmentFiller { @Override - public void fill(final OrConditionSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final EncryptRule encryptRule, + public void fill(final OrConditionSegment sqlSegment, final SQLStatement sqlStatement, final EncryptRule encryptRule, final ShardingTableMetaData shardingTableMetaData) { Map columnNameToTable = new HashMap<>(); Map columnNameCount = new HashMap<>(); fillColumnTableMap(sqlStatement, shardingTableMetaData, columnNameToTable, columnNameCount); - filterCondition(shardingTableMetaData, sqlStatement, sqlSegment, sql, encryptRule, columnNameToTable, columnNameCount); + filterCondition(shardingTableMetaData, sqlStatement, sqlSegment, encryptRule); } private void fillColumnTableMap(final SQLStatement sqlStatement, final ShardingTableMetaData shardingTableMetaData, @@ -73,9 +73,8 @@ private void fillColumnTableMap(final SQLStatement sqlStatement, final ShardingT } } } - - private OrCondition filterCondition(final ShardingTableMetaData shardingTableMetaData, final SQLStatement sqlStatement, final OrConditionSegment orCondition, final String sql, - final EncryptRule encryptRule, final Map columnNameToTable, final Map columnNameCount) { + + private OrCondition filterCondition(final ShardingTableMetaData shardingTableMetaData, final SQLStatement sqlStatement, final OrConditionSegment orCondition, final EncryptRule encryptRule) { OrCondition result = new OrCondition(); for (AndConditionSegment each : orCondition.getAndConditions()) { for (ConditionSegment condition : each.getConditions()) { @@ -83,13 +82,13 @@ private OrCondition filterCondition(final ShardingTableMetaData shardingTableMet continue; } Column column = new Column(condition.getColumn().getName(), getTableName(shardingTableMetaData, sqlStatement, condition)); - fillEncryptCondition(column, condition, encryptRule, sqlStatement, sql); + fillEncryptCondition(column, condition, encryptRule, sqlStatement); } } return result; } - private void fillEncryptCondition(final Column column, final ConditionSegment condition, final EncryptRule encryptRule, final SQLStatement sqlStatement, final String sql) { + private void fillEncryptCondition(final Column column, final ConditionSegment condition, final EncryptRule encryptRule, final SQLStatement sqlStatement) { if (!encryptRule.getEncryptorEngine().getShardingEncryptor(column.getTableName(), column.getName()).isPresent()) { return; } @@ -100,7 +99,7 @@ private void fillEncryptCondition(final Column column, final ConditionSegment co } else { andCondition = sqlStatement.getEncryptConditions().getOrCondition().getAndConditions().get(0); } - andCondition.getConditions().add(condition.getExpression().buildCondition(column, sql)); + andCondition.getConditions().add(condition.getExpression().buildCondition(column, sqlStatement.getLogicSQL())); sqlStatement.getSQLTokens().add(new EncryptColumnToken(condition.getColumn().getStartIndex(), condition.getStopIndex(), column, true)); } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptSetAssignmentsFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptSetAssignmentsFiller.java index b7b3f6282aa40..1d8bd92c49f36 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptSetAssignmentsFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptSetAssignmentsFiller.java @@ -46,13 +46,13 @@ public final class EncryptSetAssignmentsFiller implements SQLSegmentFiller { @Override - public void fill(final SetAssignmentsSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final EncryptRule encryptRule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final SetAssignmentsSegment sqlSegment, final SQLStatement sqlStatement, final EncryptRule encryptRule, final ShardingTableMetaData shardingTableMetaData) { InsertStatement insertStatement = (InsertStatement) sqlStatement; String tableName = insertStatement.getTables().getSingleTableName(); for (ColumnSegment each : sqlSegment.getColumns()) { fillColumn(each, insertStatement, tableName); } - InsertValue insertValue = getInsertValue(sqlSegment, sql); + InsertValue insertValue = getInsertValue(sqlSegment, sqlStatement.getLogicSQL()); insertStatement.getInsertValues().getValues().add(insertValue); insertStatement.setParametersIndex(insertValue.getParametersCount()); insertStatement.getSQLTokens().add(new InsertValuesToken(sqlSegment.getStartIndex(), DefaultKeyword.SET)); diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptUpdateSetWhereFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptUpdateSetWhereFiller.java index 37c18d59790bb..46f5ffa1d44b2 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptUpdateSetWhereFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/EncryptUpdateSetWhereFiller.java @@ -41,20 +41,20 @@ public class EncryptUpdateSetWhereFiller extends EncryptDeleteFromWhereFiller { @Override - public void fill(final FromWhereSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final EncryptRule encryptRule, final ShardingTableMetaData shardingTableMetaData) { - super.fill(sqlSegment, sqlStatement, sql, encryptRule, shardingTableMetaData); + public void fill(final FromWhereSegment sqlSegment, final SQLStatement sqlStatement, final EncryptRule encryptRule, final ShardingTableMetaData shardingTableMetaData) { + super.fill(sqlSegment, sqlStatement, encryptRule, shardingTableMetaData); UpdateSetWhereSegment updateSetWhereSegment = (UpdateSetWhereSegment) sqlSegment; DMLStatement dmlStatement = (DMLStatement) sqlStatement; String updateTable = dmlStatement.getUpdateTableAlias().values().iterator().next(); for (Entry each : updateSetWhereSegment.getUpdateColumns().entrySet()) { - fillEncryptCondition(each, updateTable, sql, encryptRule, dmlStatement); + fillEncryptCondition(each, updateTable, encryptRule, dmlStatement); } dmlStatement.setDeleteStatement(false); } - private void fillEncryptCondition(final Entry entry, final String updateTable, final String sql, final EncryptRule encryptRule, final DMLStatement dmlStatement) { + private void fillEncryptCondition(final Entry entry, final String updateTable, final EncryptRule encryptRule, final DMLStatement dmlStatement) { Column column = new Column(entry.getKey().getName(), updateTable); - Optional expression = entry.getValue().convertToSQLExpression(sql); + Optional expression = entry.getValue().convertToSQLExpression(dmlStatement.getLogicSQL()); Preconditions.checkState(expression.isPresent()); dmlStatement.getUpdateColumnValues().put(column, expression.get()); if (!encryptRule.getEncryptorEngine().getShardingEncryptor(column.getTableName(), column.getName()).isPresent()) { diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/insert/EncryptInsertValuesFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/insert/EncryptInsertValuesFiller.java index 6528d03faee28..7fe8d0f7870a1 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/insert/EncryptInsertValuesFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/encrypt/dml/insert/EncryptInsertValuesFiller.java @@ -40,9 +40,9 @@ public final class EncryptInsertValuesFiller implements SQLSegmentFiller { @Override - public void fill(final InsertValuesSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final EncryptRule encryptRule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final InsertValuesSegment sqlSegment, final SQLStatement sqlStatement, final EncryptRule encryptRule, final ShardingTableMetaData shardingTableMetaData) { InsertStatement insertStatement = (InsertStatement) sqlStatement; - InsertValue insertValue = getInsertValue(sqlSegment, sql); + InsertValue insertValue = getInsertValue(sqlSegment, insertStatement.getLogicSQL()); insertStatement.getInsertValues().getValues().add(insertValue); insertStatement.setParametersIndex(insertStatement.getParametersIndex() + insertValue.getParametersCount()); } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/DeleteFromWhereFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/DeleteFromWhereFiller.java index 2408edeb23114..30eb6bfb5d6d3 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/DeleteFromWhereFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/DeleteFromWhereFiller.java @@ -34,8 +34,8 @@ public class DeleteFromWhereFiller extends FromWhereFiller { @Override - public void fill(final FromWhereSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { - super.fill(sqlSegment, sqlStatement, sql, shardingRule, shardingTableMetaData); + public void fill(final FromWhereSegment sqlSegment, final SQLStatement sqlStatement, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { + super.fill(sqlSegment, sqlStatement, shardingRule, shardingTableMetaData); DeleteFromWhereSegment deleteFromWhereSegment = (DeleteFromWhereSegment) sqlSegment; DMLStatement dmlStatement = (DMLStatement) sqlStatement; dmlStatement.setDeleteStatement(true); diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/FromWhereFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/FromWhereFiller.java index c858efe68c266..c55c2bfd794f3 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/FromWhereFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/FromWhereFiller.java @@ -31,8 +31,8 @@ public class FromWhereFiller implements SQLSegmentFiller { @Override - public void fill(final FromWhereSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { - new OrConditionFiller().fill(sqlSegment.getConditions(), sqlStatement, sql, shardingRule, shardingTableMetaData); + public void fill(final FromWhereSegment sqlSegment, final SQLStatement sqlStatement, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { + new OrConditionFiller().fill(sqlSegment.getConditions(), sqlStatement, shardingRule, shardingTableMetaData); int count = 0; while (count < sqlSegment.getParameterCount()) { sqlStatement.increaseParametersIndex(); diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/OrConditionFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/OrConditionFiller.java index 27d449b8218f6..35a6aa8122d6f 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/OrConditionFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/OrConditionFiller.java @@ -53,8 +53,9 @@ public final class OrConditionFiller implements SQLSegmentFiller { @Override - public void fill(final OrConditionSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { - sqlStatement.getRouteConditions().getOrCondition().getAndConditions().addAll(buildCondition(sqlSegment, sqlStatement, sql, shardingRule, shardingTableMetaData).getAndConditions()); + public void fill(final OrConditionSegment sqlSegment, final SQLStatement sqlStatement, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { + sqlStatement.getRouteConditions().getOrCondition().getAndConditions().addAll( + buildCondition(sqlSegment, sqlStatement, shardingRule, shardingTableMetaData).getAndConditions()); } /** @@ -62,17 +63,15 @@ public void fill(final OrConditionSegment sqlSegment, final SQLStatement sqlStat * * @param sqlSegment SQL segment * @param sqlStatement SQL statement - * @param sql SQL * @param shardingRule databases and tables sharding rule * @param shardingTableMetaData sharding table meta data * @return or condition */ - public OrCondition buildCondition( - final OrConditionSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { + public OrCondition buildCondition(final OrConditionSegment sqlSegment, final SQLStatement sqlStatement, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { Map columnNameToTable = new HashMap<>(); Map columnNameCount = new HashMap<>(); fillColumnTableMap(sqlStatement, shardingTableMetaData, columnNameToTable, columnNameCount); - return filterCondition(shardingTableMetaData, sqlStatement, sqlSegment, sql, shardingRule); + return filterCondition(shardingTableMetaData, sqlStatement, sqlSegment, shardingRule); } private void fillColumnTableMap(final SQLStatement sqlStatement, final ShardingTableMetaData shardingTableMetaData, @@ -95,8 +94,7 @@ private void fillColumnTableMap(final SQLStatement sqlStatement, final ShardingT } } - private OrCondition filterCondition( - final ShardingTableMetaData shardingTableMetaData, final SQLStatement sqlStatement, final OrConditionSegment orCondition, final String sql, final ShardingRule shardingRule) { + private OrCondition filterCondition(final ShardingTableMetaData shardingTableMetaData, final SQLStatement sqlStatement, final OrConditionSegment orCondition, final ShardingRule shardingRule) { OrCondition result = new OrCondition(); for (AndConditionSegment each : orCondition.getAndConditions()) { List shardingCondition = new LinkedList<>(); @@ -118,7 +116,7 @@ private OrCondition filterCondition( } } if (needSharding) { - fillResult(shardingTableMetaData, sqlStatement, shardingRule, result, shardingCondition, sql); + fillResult(shardingTableMetaData, sqlStatement, shardingRule, result, shardingCondition); } else { result.getAndConditions().clear(); break; @@ -133,7 +131,7 @@ private OrCondition filterCondition( continue; } Column column = new Column(condition.getColumn().getName(), getTableName(shardingTableMetaData, shardingRule, sqlStatement, condition)); - fillEncryptCondition(column, condition, shardingRule, sqlStatement, sql); + fillEncryptCondition(column, condition, shardingRule, sqlStatement); } } return result; @@ -149,8 +147,8 @@ private void addTableTokenForColumn(final ShardingTableMetaData shardingTableMet } } - private void fillResult(final ShardingTableMetaData shardingTableMetaData, final SQLStatement sqlStatement, final ShardingRule shardingRule, final OrCondition orCondition, - final List shardingCondition, final String sql) { + private void fillResult(final ShardingTableMetaData shardingTableMetaData, + final SQLStatement sqlStatement, final ShardingRule shardingRule, final OrCondition orCondition, final List shardingCondition) { if (shardingCondition.isEmpty()) { return; } @@ -159,11 +157,11 @@ private void fillResult(final ShardingTableMetaData shardingTableMetaData, final for (ConditionSegment eachCondition : shardingCondition) { Optional tableName = getTableName(sqlStatement, eachCondition); Column column = new Column(eachCondition.getColumn().getName(), tableName.isPresent() ? tableName.get() : getTableName(shardingTableMetaData, shardingRule, sqlStatement, eachCondition)); - andConditionResult.getConditions().add(eachCondition.getExpression().buildCondition(column, sql)); + andConditionResult.getConditions().add(eachCondition.getExpression().buildCondition(column, sqlStatement.getLogicSQL())); } } - private void fillEncryptCondition(final Column column, final ConditionSegment condition, final ShardingRule shardingRule, final SQLStatement sqlStatement, final String sql) { + private void fillEncryptCondition(final Column column, final ConditionSegment condition, final ShardingRule shardingRule, final SQLStatement sqlStatement) { if (!shardingRule.getShardingEncryptorEngine().getShardingEncryptor(column.getTableName(), column.getName()).isPresent()) { return; } @@ -174,7 +172,7 @@ private void fillEncryptCondition(final Column column, final ConditionSegment co } else { andCondition = sqlStatement.getEncryptConditions().getOrCondition().getAndConditions().get(0); } - andCondition.getConditions().add(condition.getExpression().buildCondition(column, sql)); + andCondition.getConditions().add(condition.getExpression().buildCondition(column, sqlStatement.getLogicSQL())); sqlStatement.getSQLTokens().add(new EncryptColumnToken(condition.getColumn().getStartIndex(), condition.getStopIndex(), column, true)); } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/SetAssignmentsFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/SetAssignmentsFiller.java index 2fa4a5aa068a1..1d7275fa49d54 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/SetAssignmentsFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/SetAssignmentsFiller.java @@ -52,7 +52,7 @@ public final class SetAssignmentsFiller implements SQLSegmentFiller { @Override - public void fill(final SetAssignmentsSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final SetAssignmentsSegment sqlSegment, final SQLStatement sqlStatement, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { InsertStatement insertStatement = (InsertStatement) sqlStatement; String tableName = insertStatement.getTables().getSingleTableName(); for (ColumnSegment each : sqlSegment.getColumns()) { @@ -67,7 +67,7 @@ public void fill(final SetAssignmentsSegment sqlSegment, final SQLStatement sqlS int parametersCount = 0; List columnValues = new LinkedList<>(); for (CommonExpressionSegment each : sqlSegment.getValues()) { - SQLExpression columnValue = getColumnValue(insertStatement, sql, shardingRule, andCondition, columns.next(), each); + SQLExpression columnValue = getColumnValue(insertStatement, shardingRule, andCondition, columns.next(), each); columnValues.add(columnValue); if (columnValue instanceof SQLPlaceholderExpression) { parametersCount++; @@ -99,12 +99,12 @@ private int getColumnCountExcludeAssistedQueryColumns(final InsertStatement inse return insertStatement.getColumns().size(); } - private SQLExpression getColumnValue(final InsertStatement insertStatement, - final String sql, final ShardingRule shardingRule, final AndCondition andCondition, final Column column, final CommonExpressionSegment expressionSegment) { - Optional result = expressionSegment.convertToSQLExpression(sql); + private SQLExpression getColumnValue(final InsertStatement insertStatement, + final ShardingRule shardingRule, final AndCondition andCondition, final Column column, final CommonExpressionSegment expressionSegment) { + Optional result = expressionSegment.convertToSQLExpression(insertStatement.getLogicSQL()); Preconditions.checkState(result.isPresent()); fillShardingCondition(shardingRule, andCondition, column, expressionSegment, result.get()); - fillGeneratedKeyCondition(insertStatement, sql, shardingRule, column, expressionSegment); + fillGeneratedKeyCondition(insertStatement, shardingRule, column, expressionSegment); return result.get(); } @@ -118,11 +118,10 @@ private void fillShardingCondition(final ShardingRule shardingRule, } } - private void fillGeneratedKeyCondition(final InsertStatement insertStatement, - final String sql, final ShardingRule shardingRule, final Column column, final CommonExpressionSegment expressionSegment) { + private void fillGeneratedKeyCondition(final InsertStatement insertStatement, final ShardingRule shardingRule, final Column column, final CommonExpressionSegment expressionSegment) { Optional generateKeyColumnName = shardingRule.findGenerateKeyColumnName(insertStatement.getTables().getSingleTableName()); if (generateKeyColumnName.isPresent() && generateKeyColumnName.get().equalsIgnoreCase(column.getName())) { - insertStatement.getGeneratedKeyConditions().add(createGeneratedKeyCondition(column, expressionSegment, sql)); + insertStatement.getGeneratedKeyConditions().add(createGeneratedKeyCondition(column, expressionSegment, insertStatement.getLogicSQL())); } } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/TableFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/TableFiller.java index 0b2f30df01875..8d75c496c2cef 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/TableFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/TableFiller.java @@ -33,7 +33,7 @@ public final class TableFiller implements SQLSegmentFiller { @Override - public void fill(final TableSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final TableSegment sqlSegment, final SQLStatement sqlStatement, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { boolean fill = false; String tableName = sqlSegment.getName(); if (shardingRule.contains(tableName) || shardingRule.isBroadcastTable(tableName) || shardingRule.findBindingTableRule(tableName).isPresent() diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/UpdateSetWhereFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/UpdateSetWhereFiller.java index a40ff955e1cca..4b2d5fc9272de 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/UpdateSetWhereFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/UpdateSetWhereFiller.java @@ -41,25 +41,25 @@ public final class UpdateSetWhereFiller extends DeleteFromWhereFiller { @Override - public void fill(final FromWhereSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { - super.fill(sqlSegment, sqlStatement, sql, shardingRule, shardingTableMetaData); + public void fill(final FromWhereSegment sqlSegment, final SQLStatement sqlStatement, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { + super.fill(sqlSegment, sqlStatement, shardingRule, shardingTableMetaData); UpdateSetWhereSegment updateSetWhereSegment = (UpdateSetWhereSegment) sqlSegment; DMLStatement dmlStatement = (DMLStatement) sqlStatement; String updateTable = dmlStatement.getUpdateTableAlias().values().iterator().next(); for (Entry entry : updateSetWhereSegment.getUpdateColumns().entrySet()) { Column column = new Column(entry.getKey().getName(), updateTable); - Optional expression = entry.getValue().convertToSQLExpression(sql); + Optional expression = entry.getValue().convertToSQLExpression(sqlStatement.getLogicSQL()); Preconditions.checkState(expression.isPresent()); dmlStatement.getUpdateColumnValues().put(column, expression.get()); - fillEncryptCondition(entry.getKey(), entry.getValue(), updateTable, sql, shardingRule, dmlStatement); + fillEncryptCondition(entry.getKey(), entry.getValue(), updateTable, shardingRule, dmlStatement); } dmlStatement.setDeleteStatement(false); } private void fillEncryptCondition(final ColumnSegment columnSegment, final ExpressionSegment expressionSegment, - final String updateTable, final String sql, final ShardingRule shardingRule, final DMLStatement dmlStatement) { + final String updateTable, final ShardingRule shardingRule, final DMLStatement dmlStatement) { Column column = new Column(columnSegment.getName(), updateTable); - Optional expression = expressionSegment.convertToSQLExpression(sql); + Optional expression = expressionSegment.convertToSQLExpression(dmlStatement.getLogicSQL()); Preconditions.checkState(expression.isPresent()); dmlStatement.getUpdateColumnValues().put(column, expression.get()); if (!shardingRule.getShardingEncryptorEngine().getShardingEncryptor(column.getTableName(), column.getName()).isPresent()) { diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/insert/InsertDuplicateKeyColumnsFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/insert/InsertDuplicateKeyColumnsFiller.java index 3ab07e247c729..c070e876c73b2 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/insert/InsertDuplicateKeyColumnsFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/insert/InsertDuplicateKeyColumnsFiller.java @@ -35,7 +35,7 @@ public final class InsertDuplicateKeyColumnsFiller implements SQLSegmentFiller { @Override - public void fill(final InsertValuesSegment sqlSegment, final SQLStatement sqlStatement, final String sql, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final InsertValuesSegment sqlSegment, final SQLStatement sqlStatement, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { InsertStatement insertStatement = (InsertStatement) sqlStatement; removeGenerateKeyColumn(insertStatement, shardingRule, sqlSegment.getValues().size()); int columnCount = getColumnCountExcludeAssistedQueryColumns(insertStatement, shardingRule, shardingTableMetaData); @@ -59,7 +59,7 @@ public void fill(final InsertValuesSegment sqlSegment, final SQLStatement sqlSta int parametersCount = 0; List columnValues = new LinkedList<>(); for (CommonExpressionSegment each : sqlSegment.getValues()) { - SQLExpression columnValue = getColumnValue(insertStatement, sql, shardingRule, andCondition, columns.next(), each); + SQLExpression columnValue = getColumnValue(insertStatement, shardingRule, andCondition, columns.next(), each); columnValues.add(columnValue); if (columnValue instanceof SQLPlaceholderExpression) { parametersCount++; @@ -91,11 +91,11 @@ private void removeGenerateKeyColumn(final InsertStatement insertStatement, fina } private SQLExpression getColumnValue(final InsertStatement insertStatement, - final String sql, final ShardingRule shardingRule, final AndCondition andCondition, final Column column, final CommonExpressionSegment expressionSegment) { - Optional result = expressionSegment.convertToSQLExpression(sql); + final ShardingRule shardingRule, final AndCondition andCondition, final Column column, final CommonExpressionSegment expressionSegment) { + Optional result = expressionSegment.convertToSQLExpression(insertStatement.getLogicSQL()); Preconditions.checkState(result.isPresent()); fillShardingCondition(shardingRule, andCondition, column, expressionSegment, result.get()); - fillGeneratedKeyCondition(insertStatement, sql, shardingRule, column, expressionSegment); + fillGeneratedKeyCondition(insertStatement, insertStatement.getLogicSQL(), shardingRule, column, expressionSegment); return result.get(); } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/select/SubqueryConditionFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/select/SubqueryConditionFiller.java index 917da4d2ee50c..3bda595e5d3c0 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/select/SubqueryConditionFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/filler/sharding/dml/select/SubqueryConditionFiller.java @@ -34,12 +34,11 @@ public final class SubqueryConditionFiller implements SQLSegmentFiller { @Override - public void fill(final SubqueryConditionSegment sqlSegment, final SQLStatement sqlStatement, final String sql, - final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { + public void fill(final SubqueryConditionSegment sqlSegment, final SQLStatement sqlStatement, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { SelectStatement selectStatement = (SelectStatement) sqlStatement; OrConditionFiller orConditionFiller = new OrConditionFiller(); for (OrConditionSegment each : sqlSegment.getOrConditions()) { - selectStatement.getSubqueryConditions().add(orConditionFiller.buildCondition(each, sqlStatement, sql, shardingRule, shardingTableMetaData)); + selectStatement.getSubqueryConditions().add(orConditionFiller.buildCondition(each, sqlStatement, shardingRule, shardingTableMetaData)); } } } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/sql/statement/SQLStatement.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/sql/statement/SQLStatement.java index 5eb1e92e1e123..debbb4ab0249a 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/sql/statement/SQLStatement.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/antlr/sql/statement/SQLStatement.java @@ -91,4 +91,11 @@ public interface SQLStatement { * @return logic SQL */ String getLogicSQL(); + + /** + * Set logic SQL. + * + * @param logicTable logic SQL + */ + void setLogicSQL(String logicTable); }