From 1ac9953e9848ccd6a43d8f0a65bb72cc45fdbf5f Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Tue, 19 Sep 2023 14:41:53 +0800 Subject: [PATCH 1/3] Minimal refactor of oracle dml statement parameter parse --- .../EncryptInsertValuesTokenGenerator.java | 50 ++++++++++++------- .../statement/OracleStatementVisitor.java | 29 ++++++++--- .../type/OracleDALStatementVisitor.java | 6 ++- .../type/OracleDMLStatementVisitor.java | 19 +++---- .../src/main/resources/case/dml/insert.xml | 6 +-- .../resources/case/dml/select-pagination.xml | 4 +- .../resources/case/dml/select-sub-query.xml | 2 +- 7 files changed, 75 insertions(+), 41 deletions(-) diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/insert/EncryptInsertValuesTokenGenerator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/insert/EncryptInsertValuesTokenGenerator.java index 93d9fe050ca9c..5de7cc6453111 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/insert/EncryptInsertValuesTokenGenerator.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/insert/EncryptInsertValuesTokenGenerator.java @@ -30,7 +30,6 @@ import org.apache.shardingsphere.infra.binder.context.segment.insert.values.InsertValueContext; import org.apache.shardingsphere.infra.binder.context.segment.insert.values.expression.DerivedLiteralExpressionSegment; import org.apache.shardingsphere.infra.binder.context.segment.insert.values.expression.DerivedParameterMarkerExpressionSegment; -import org.apache.shardingsphere.infra.binder.context.segment.insert.values.expression.DerivedSimpleExpressionSegment; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry; @@ -41,9 +40,11 @@ import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.InsertValuesToken; import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.UseDefaultInsertColumnsToken; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.InsertValuesSegment; +import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.ParameterMarkerExpressionSegment; +import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue; import java.util.Collection; import java.util.Iterator; @@ -143,14 +144,15 @@ private void encryptToken(final InsertValue insertValueToken, final String schem int columnIndex = useDefaultInsertColumnsToken .map(optional -> ((UseDefaultInsertColumnsToken) optional).getColumns().indexOf(columnName)).orElseGet(() -> insertStatementContext.getColumnNames().indexOf(columnName)); Object originalValue = insertValueContext.getLiteralValue(columnIndex).orElse(null); - setCipherColumn(schemaName, tableName, encryptColumn, insertValueToken, insertValueContext.getValueExpressions().get(columnIndex), columnIndex, originalValue); + ExpressionSegment valueExpression = insertValueContext.getValueExpressions().get(columnIndex); + setCipherColumn(schemaName, tableName, encryptColumn, insertValueToken, valueExpression, columnIndex, originalValue); int indexDelta = 1; if (encryptColumn.getAssistedQuery().isPresent()) { - addAssistedQueryColumn(schemaName, tableName, encryptColumn, insertValueContext, insertValueToken, columnIndex, indexDelta, originalValue); + addAssistedQueryColumn(schemaName, tableName, encryptColumn, insertValueToken, valueExpression, columnIndex, indexDelta, originalValue); indexDelta++; } if (encryptColumn.getLikeQuery().isPresent()) { - addLikeQueryColumn(schemaName, tableName, encryptColumn, insertValueContext, insertValueToken, columnIndex, indexDelta, originalValue); + addLikeQueryColumn(schemaName, tableName, encryptColumn, insertValueToken, valueExpression, columnIndex, indexDelta, originalValue); } } } @@ -163,31 +165,45 @@ private void setCipherColumn(final String schemaName, final String tableName, fi } } - private void addAssistedQueryColumn(final String schemaName, final String tableName, final EncryptColumn encryptColumn, - final InsertValueContext insertValueContext, final InsertValue insertValueToken, final int columnIndex, final int indexDelta, final Object originalValue) { + private void addAssistedQueryColumn(final String schemaName, final String tableName, final EncryptColumn encryptColumn, final InsertValue insertValueToken, + final ExpressionSegment valueExpression, final int columnIndex, final int indexDelta, final Object originalValue) { Optional assistedQueryColumnItem = encryptColumn.getAssistedQuery(); Preconditions.checkState(assistedQueryColumnItem.isPresent()); Object derivedValue = assistedQueryColumnItem.get().encrypt(databaseName, schemaName, tableName, encryptColumn.getName(), originalValue); - addDerivedColumn(insertValueContext, insertValueToken, columnIndex, indexDelta, derivedValue); + addDerivedColumn(insertValueToken, valueExpression, columnIndex, indexDelta, derivedValue, assistedQueryColumnItem.get().getName()); } - private void addLikeQueryColumn(final String schemaName, final String tableName, final EncryptColumn encryptColumn, - final InsertValueContext insertValueContext, final InsertValue insertValueToken, final int columnIndex, final int indexDelta, final Object originalValue) { + private void addLikeQueryColumn(final String schemaName, final String tableName, final EncryptColumn encryptColumn, final InsertValue insertValueToken, + final ExpressionSegment valueExpression, final int columnIndex, final int indexDelta, final Object originalValue) { Optional likeQueryColumnItem = encryptColumn.getLikeQuery(); Preconditions.checkState(likeQueryColumnItem.isPresent()); Object derivedValue = likeQueryColumnItem.get().encrypt(databaseName, schemaName, tableName, encryptColumn.getName(), originalValue); - addDerivedColumn(insertValueContext, insertValueToken, columnIndex, indexDelta, derivedValue); + addDerivedColumn(insertValueToken, valueExpression, columnIndex, indexDelta, derivedValue, likeQueryColumnItem.get().getName()); } - private void addDerivedColumn(final InsertValueContext insertValueContext, final InsertValue insertValueToken, final int columnIndex, final int indexDelta, final Object derivedValue) { - DerivedSimpleExpressionSegment derivedExpressionSegment = isAddLiteralExpressionSegment(insertValueContext, columnIndex) - ? new DerivedLiteralExpressionSegment(derivedValue) - : new DerivedParameterMarkerExpressionSegment(getParameterIndexCount(insertValueToken)); - insertValueToken.getValues().add(columnIndex + indexDelta, derivedExpressionSegment); + private void addDerivedColumn(final InsertValue insertValueToken, final ExpressionSegment valueExpression, final int columnIndex, final int indexDelta, final Object derivedValue, + final String derivedColumnName) { + ExpressionSegment derivedExpression; + if (valueExpression instanceof LiteralExpressionSegment) { + derivedExpression = new DerivedLiteralExpressionSegment(derivedValue); + } else if (valueExpression instanceof ParameterMarkerExpressionSegment) { + derivedExpression = new DerivedParameterMarkerExpressionSegment(getParameterIndexCount(insertValueToken)); + } else if (valueExpression instanceof ColumnSegment) { + derivedExpression = createColumnSegment((ColumnSegment) valueExpression, derivedColumnName); + } else { + derivedExpression = valueExpression; + } + insertValueToken.getValues().add(columnIndex + indexDelta, derivedExpression); } - private boolean isAddLiteralExpressionSegment(final InsertValueContext insertValueContext, final int columnIndex) { - return insertValueContext.getParameters().isEmpty() || insertValueContext.getValueExpressions().get(columnIndex) instanceof LiteralExpressionSegment; + private ColumnSegment createColumnSegment(final ColumnSegment originalColumn, final String columnName) { + ColumnSegment result = new ColumnSegment(originalColumn.getStartIndex(), originalColumn.getStopIndex(), new IdentifierValue(columnName, originalColumn.getIdentifier().getQuoteCharacter())); + result.setNestedObjectAttributes(originalColumn.getNestedObjectAttributes()); + originalColumn.getOwner().ifPresent(result::setOwner); + result.setColumnBoundedInfo(originalColumn.getColumnBoundedInfo()); + result.setOtherUsingColumnBoundedInfo(originalColumn.getOtherUsingColumnBoundedInfo()); + result.setVariable(originalColumn.isVariable()); + return result; } private int getParameterIndexCount(final InsertValue insertValueToken) { diff --git a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/OracleStatementVisitor.java b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/OracleStatementVisitor.java index 4854c9107f0c5..c17be79e6cf2d 100644 --- a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/OracleStatementVisitor.java +++ b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/OracleStatementVisitor.java @@ -31,9 +31,9 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.BitValueLiteralsContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.BooleanLiteralsContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.BooleanPrimaryContext; -import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CastFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CaseExpressionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CaseWhenContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CastFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CharFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ColumnNameContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ColumnNamesContext; @@ -45,8 +45,8 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DateTimeLiteralsContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DatetimeExprContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ExprContext; -import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ExtractFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ExprListContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ExtractFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.FeatureFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.FirstOrLastValueFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.FormatFunctionContext; @@ -79,8 +79,8 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TableNameContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TableNamesContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ToDateFunctionContext; -import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TrimFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TranslateFunctionContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TrimFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.TypeNameContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.UnreservedWordContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ViewNameContext; @@ -180,11 +180,13 @@ @Getter public abstract class OracleStatementVisitor extends OracleStatementBaseVisitor { - private final Collection parameterMarkerSegments = new LinkedList<>(); + private final Collection globalParameterMarkerSegments = new LinkedList<>(); + + private final Collection statementParameterMarkerSegments = new LinkedList<>(); @Override public final ASTNode visitParameterMarker(final ParameterMarkerContext ctx) { - return new ParameterMarkerValue(parameterMarkerSegments.size(), ParameterMarkerType.QUESTION); + return new ParameterMarkerValue(globalParameterMarkerSegments.size(), ParameterMarkerType.QUESTION); } @Override @@ -537,7 +539,8 @@ private ASTNode createExpressionSegment(final ASTNode astNode, final ParserRuleC ParameterMarkerValue parameterMarker = (ParameterMarkerValue) astNode; ParameterMarkerExpressionSegment segment = new ParameterMarkerExpressionSegment(context.start.getStartIndex(), context.stop.getStopIndex(), parameterMarker.getValue(), parameterMarker.getType()); - parameterMarkerSegments.add(segment); + globalParameterMarkerSegments.add(segment); + statementParameterMarkerSegments.add(segment); return segment; } if (astNode instanceof SubquerySegment) { @@ -559,7 +562,8 @@ public final ASTNode visitSimpleExpr(final SimpleExprContext ctx) { if (null != ctx.parameterMarker()) { ParameterMarkerValue parameterMarker = (ParameterMarkerValue) visit(ctx.parameterMarker()); ParameterMarkerExpressionSegment segment = new ParameterMarkerExpressionSegment(startIndex, stopIndex, parameterMarker.getValue(), parameterMarker.getType()); - parameterMarkerSegments.add(segment); + globalParameterMarkerSegments.add(segment); + statementParameterMarkerSegments.add(segment); return segment; } if (null != ctx.literals()) { @@ -1172,4 +1176,15 @@ public final ASTNode visitDataTypeLength(final DataTypeLengthContext ctx) { protected String getOriginalText(final ParserRuleContext ctx) { return ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); } + + /** + * Pop all statement parameter marker segments. + * + * @return all statement parameter marker segments + */ + protected Collection popAllStatementParameterMarkerSegments() { + Collection result = new LinkedList<>(statementParameterMarkerSegments); + statementParameterMarkerSegments.clear(); + return result; + } } diff --git a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDALStatementVisitor.java b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDALStatementVisitor.java index 1b01372814de9..cf7ab2bc57036 100644 --- a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDALStatementVisitor.java +++ b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDALStatementVisitor.java @@ -20,6 +20,7 @@ import org.apache.shardingsphere.sql.parser.api.ASTNode; import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DALStatementVisitor; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AlterResourceCostContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ExecuteContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ExplainContext; import org.apache.shardingsphere.sql.parser.oracle.visitor.statement.OracleStatementVisitor; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -40,7 +41,8 @@ public ASTNode visitAlterResourceCost(final AlterResourceCostContext ctx) { public ASTNode visitExplain(final ExplainContext ctx) { OracleExplainStatement result = new OracleExplainStatement(); OracleDMLStatementVisitor visitor = new OracleDMLStatementVisitor(); - visitor.getParameterMarkerSegments().addAll(getParameterMarkerSegments()); + getGlobalParameterMarkerSegments().addAll(visitor.getGlobalParameterMarkerSegments()); + getStatementParameterMarkerSegments().addAll(visitor.getStatementParameterMarkerSegments()); if (null != ctx.insert()) { result.setStatement((SQLStatement) visitor.visit(ctx.insert())); } else if (null != ctx.delete()) { @@ -50,7 +52,7 @@ public ASTNode visitExplain(final ExplainContext ctx) { } else if (null != ctx.select()) { result.setStatement((SQLStatement) visitor.visit(ctx.select())); } - result.addParameterMarkerSegments(getParameterMarkerSegments()); + result.addParameterMarkerSegments(ctx.getParent() instanceof ExecuteContext ? getGlobalParameterMarkerSegments() : popAllStatementParameterMarkerSegments()); return result; } } diff --git a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDMLStatementVisitor.java b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDMLStatementVisitor.java index 39c6223ae87b0..3e1aaa7db6368 100644 --- a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDMLStatementVisitor.java +++ b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDMLStatementVisitor.java @@ -39,6 +39,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DmlSubqueryClauseContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DmlTableClauseContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DuplicateSpecificationContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ExecuteContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ExprContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ExpressionListContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ForUpdateClauseContext; @@ -62,8 +63,8 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.LockTableContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.MergeAssignmentContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.MergeAssignmentValueContext; -import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.MergeContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.MergeColumnValueContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.MergeContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.MergeInsertClauseContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.MergeInsertColumnContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.MergeSetAssignmentsClauseContext; @@ -208,7 +209,7 @@ public ASTNode visitUpdate(final UpdateContext ctx) { if (null != ctx.whereClause()) { result.setWhere((WhereSegment) visit(ctx.whereClause())); } - result.addParameterMarkerSegments(getParameterMarkerSegments()); + result.addParameterMarkerSegments(ctx.getParent() instanceof ExecuteContext ? getGlobalParameterMarkerSegments() : popAllStatementParameterMarkerSegments()); return result; } @@ -299,7 +300,9 @@ public ASTNode visitUpdateSetValueClause(final UpdateSetValueClauseContext ctx) @Override public ASTNode visitInsert(final InsertContext ctx) { // TODO :FIXME, since there is no segment for insertValuesClause, InsertStatement is created by sub rule. - return null == ctx.insertSingleTable() ? visit(ctx.insertMultiTable()) : visit(ctx.insertSingleTable()); + OracleInsertStatement result = (OracleInsertStatement) (null == ctx.insertSingleTable() ? visit(ctx.insertMultiTable()) : visit(ctx.insertSingleTable())); + result.addParameterMarkerSegments(ctx.getParent() instanceof ExecuteContext ? getGlobalParameterMarkerSegments() : popAllStatementParameterMarkerSegments()); + return result; } @Override @@ -313,7 +316,6 @@ public ASTNode visitInsertSingleTable(final InsertSingleTableContext ctx) { SubquerySegment subquerySegment = new SubquerySegment(ctx.selectSubquery().start.getStartIndex(), ctx.selectSubquery().stop.getStopIndex(), subquery); result.setInsertSelect(subquerySegment); } - result.addParameterMarkerSegments(getParameterMarkerSegments()); return result; } @@ -326,7 +328,6 @@ private Collection createInsertValuesSegments(final Assignm @Override public ASTNode visitInsertMultiTable(final InsertMultiTableContext ctx) { OracleInsertStatement result = new OracleInsertStatement(); - result.setInsertSelect(new SubquerySegment(ctx.selectSubquery().start.getStartIndex(), ctx.selectSubquery().stop.getStopIndex(), (OracleSelectStatement) visit(ctx.selectSubquery()))); result.setMultiTableInsertType(null != ctx.conditionalInsertClause() && null != ctx.conditionalInsertClause().FIRST() ? MultiTableInsertType.FIRST : MultiTableInsertType.ALL); List multiTableElementContexts = ctx.multiTableElement(); if (null != multiTableElementContexts && !multiTableElementContexts.isEmpty()) { @@ -337,7 +338,7 @@ public ASTNode visitInsertMultiTable(final InsertMultiTableContext ctx) { } else { result.setMultiTableConditionalIntoSegment((MultiTableConditionalIntoSegment) visit(ctx.conditionalInsertClause())); } - result.addParameterMarkerSegments(getParameterMarkerSegments()); + result.setInsertSelect(new SubquerySegment(ctx.selectSubquery().start.getStartIndex(), ctx.selectSubquery().stop.getStopIndex(), (OracleSelectStatement) visit(ctx.selectSubquery()))); return result; } @@ -387,7 +388,7 @@ public ASTNode visitDelete(final DeleteContext ctx) { if (null != ctx.whereClause()) { result.setWhere((WhereSegment) visit(ctx.whereClause())); } - result.addParameterMarkerSegments(getParameterMarkerSegments()); + result.addParameterMarkerSegments(ctx.getParent() instanceof ExecuteContext ? getGlobalParameterMarkerSegments() : popAllStatementParameterMarkerSegments()); return result; } @@ -416,7 +417,7 @@ public ASTNode visitMultiTableElement(final MultiTableElementContext ctx) { @Override public ASTNode visitSelect(final SelectContext ctx) { OracleSelectStatement result = (OracleSelectStatement) visit(ctx.selectSubquery()); - result.addParameterMarkerSegments(getParameterMarkerSegments()); + result.addParameterMarkerSegments(ctx.getParent() instanceof ExecuteContext ? getGlobalParameterMarkerSegments() : popAllStatementParameterMarkerSegments()); if (null != ctx.forUpdateClause()) { result.setLock((LockSegment) visit(ctx.forUpdateClause())); } @@ -535,7 +536,7 @@ public ASTNode visitSelectSubquery(final SelectSubqueryContext ctx) { if (null != ctx.orderByClause()) { result.setOrderBy((OrderBySegment) visit(ctx.orderByClause())); } - result.addParameterMarkerSegments(getParameterMarkerSegments()); + result.addParameterMarkerSegments(ctx.getParent() instanceof ExecuteContext ? getGlobalParameterMarkerSegments() : popAllStatementParameterMarkerSegments()); return result; } diff --git a/test/it/parser/src/main/resources/case/dml/insert.xml b/test/it/parser/src/main/resources/case/dml/insert.xml index 34c2b6b610784..7c69aca33e2ff 100644 --- a/test/it/parser/src/main/resources/case/dml/insert.xml +++ b/test/it/parser/src/main/resources/case/dml/insert.xml @@ -1364,7 +1364,7 @@ - + @@ -1388,7 +1388,7 @@ - +
@@ -1412,7 +1412,7 @@ - +
diff --git a/test/it/parser/src/main/resources/case/dml/select-pagination.xml b/test/it/parser/src/main/resources/case/dml/select-pagination.xml index 268fc4fc1f740..ec28c8481e9fc 100644 --- a/test/it/parser/src/main/resources/case/dml/select-pagination.xml +++ b/test/it/parser/src/main/resources/case/dml/select-pagination.xml @@ -1627,7 +1627,7 @@ - @@ -1637,7 +1637,7 @@ - diff --git a/test/it/parser/src/main/resources/case/dml/select-sub-query.xml b/test/it/parser/src/main/resources/case/dml/select-sub-query.xml index c6d128750bc32..f07dc55427765 100644 --- a/test/it/parser/src/main/resources/case/dml/select-sub-query.xml +++ b/test/it/parser/src/main/resources/case/dml/select-sub-query.xml @@ -108,7 +108,7 @@ - From 8e7276e85160a3ba610e300259577bff73c6b459 Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Tue, 19 Sep 2023 14:45:41 +0800 Subject: [PATCH 2/3] fix build error --- .../type/OracleDDLStatementVisitor.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java index 20c623fc534ab..802ec6c4fb2ef 100644 --- a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java +++ b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDDLStatementVisitor.java @@ -64,10 +64,10 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AuditContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AuditTraditionalContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.AuditUnifiedContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ColumnClausesContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ColumnDefinitionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ColumnNameContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ColumnOrVirtualDefinitionContext; -import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ColumnClausesContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CommentContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ConstraintClausesContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateClusterContext; @@ -85,6 +85,8 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateIndexContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateInmemoryJoinGroupContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateLockdownProfileContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateMaterializedViewContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateMaterializedViewLogContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreatePFileContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateProcedureContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateRestorePointContext; @@ -94,8 +96,6 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateSynonymContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateTableContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateTablespaceContext; -import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateMaterializedViewContext; -import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateMaterializedViewLogContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateTypeContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateViewContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DataTypeDefinitionContext; @@ -108,7 +108,6 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropDatabaseLinkContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropDimensionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropDirectoryContext; -import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropProfileContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropDiskgroupContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropEditionContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropFlashbackArchiveContext; @@ -127,6 +126,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropPackageContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropPluggableDatabaseContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropProcedureContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropProfileContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropRestorePointContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropRollbackSegmentContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DropSequenceContext; @@ -144,8 +144,8 @@ import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.IndexNameContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.IndexTypeNameContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.InlineConstraintContext; -import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ModifyCollectionRetrievalContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ModifyColPropertiesContext; +import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ModifyCollectionRetrievalContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ModifyColumnSpecificationContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.ModifyConstraintClauseContext; import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.NestedTableTypeSpecContext; @@ -246,6 +246,8 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateIndexStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateInmemoryJoinGroupStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateLockdownProfileStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateMaterializedViewLogStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateMaterializedViewStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateNestedTableTypeStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateObjectTypeStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreatePFileStatement; @@ -258,10 +260,8 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateSynonymStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateTableStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateTablespaceStatement; -import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateMaterializedViewStatement; -import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateMaterializedViewLogStatement; -import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateViewStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateVarrayTypeStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateViewStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDisassociateStatisticsStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropClusterStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropContextStatement; @@ -318,11 +318,12 @@ public final class OracleDDLStatementVisitor extends OracleStatementVisitor impl public ASTNode visitCreateView(final CreateViewContext ctx) { OracleCreateViewStatement result = new OracleCreateViewStatement(); OracleDMLStatementVisitor visitor = new OracleDMLStatementVisitor(); - visitor.getParameterMarkerSegments().addAll(getParameterMarkerSegments()); + getGlobalParameterMarkerSegments().addAll(visitor.getGlobalParameterMarkerSegments()); + getStatementParameterMarkerSegments().addAll(visitor.getStatementParameterMarkerSegments()); result.setView((SimpleTableSegment) visit(ctx.viewName())); result.setSelect((SelectStatement) visitor.visit(ctx.select())); result.setViewDefinition(getOriginalText(ctx.select())); - result.addParameterMarkerSegments(getParameterMarkerSegments()); + result.addParameterMarkerSegments(getGlobalParameterMarkerSegments()); return result; } From da0e27961b2fd21603e9b0ce8bd2c45bc62b4ff8 Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Tue, 19 Sep 2023 15:13:39 +0800 Subject: [PATCH 3/3] fix sql parser test case --- .../oracle/visitor/statement/type/OracleDMLStatementVisitor.java | 1 + 1 file changed, 1 insertion(+) diff --git a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDMLStatementVisitor.java b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDMLStatementVisitor.java index 3e1aaa7db6368..d97e9933e7626 100644 --- a/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDMLStatementVisitor.java +++ b/parser/sql/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/type/OracleDMLStatementVisitor.java @@ -411,6 +411,7 @@ public ASTNode visitMultiTableElement(final MultiTableElementContext ctx) { if (null != ctx.insertValuesClause()) { result.getValues().addAll(createInsertValuesSegments(ctx.insertValuesClause().assignmentValues())); } + result.addParameterMarkerSegments(ctx.getParent() instanceof ExecuteContext ? getGlobalParameterMarkerSegments() : popAllStatementParameterMarkerSegments()); return result; }