From c506346676b1e021d04c40f97bdf0b7129c75ea4 Mon Sep 17 00:00:00 2001 From: ZhangCheng Date: Fri, 20 Dec 2024 09:59:46 +0800 Subject: [PATCH] Refactor get column to get column segment in encrypt condition (#34107) --- .../rewrite/condition/EncryptCondition.java | 8 +++++--- .../condition/EncryptConditionEngine.java | 16 +++++++++------- .../condition/impl/EncryptBinaryCondition.java | 8 +++++--- .../condition/impl/EncryptInCondition.java | 7 ++++--- .../EncryptSQLRewriteContextDecorator.java | 7 ++++--- .../EncryptPredicateParameterRewriter.java | 4 ++-- ...InsertPredicateRightValueTokenGenerator.java | 2 +- ...ncryptPredicateRightValueTokenGenerator.java | 17 ++++++++++------- .../impl/EncryptBinaryConditionTest.java | 10 ++++++---- .../condition/impl/EncryptInConditionTest.java | 4 +++- 10 files changed, 49 insertions(+), 34 deletions(-) diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptCondition.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptCondition.java index af320e1ff41ea..848bf03b225fe 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptCondition.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptCondition.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.encrypt.rewrite.condition; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; + import java.util.Map; /** @@ -25,11 +27,11 @@ public interface EncryptCondition { /** - * Get column name. + * Get column segment. * - * @return column name + * @return column segment */ - String getColumnName(); + ColumnSegment getColumnSegment(); /** * Get table name. diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java index b44cb42d32e1e..ecee22e14e1ae 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java @@ -30,6 +30,8 @@ import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.ExpressionExtractor; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BetweenExpression; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; @@ -41,8 +43,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubqueryExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.AndPredicate; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.ExpressionExtractor; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; import java.util.Collection; import java.util.HashSet; @@ -122,7 +123,8 @@ private void addEncryptConditions(final Collection encryptCond return; } for (ColumnSegment each : ColumnExtractor.extract(expression)) { - String tableName = expressionTableNames.getOrDefault(each.getExpression(), ""); + ColumnSegmentBoundInfo columnBoundInfo = each.getColumnBoundInfo(); + String tableName = columnBoundInfo.getOriginalTable().getValue().isEmpty() ? expressionTableNames.getOrDefault(each.getExpression(), "") : columnBoundInfo.getOriginalTable().getValue(); Optional encryptTable = rule.findEncryptTable(tableName); if (encryptTable.isPresent() && encryptTable.get().isEncryptColumn(each.getIdentifier().getValue())) { createEncryptCondition(expression, tableName).ifPresent(encryptConditions::add); @@ -184,8 +186,8 @@ private Optional createCompareEncryptCondition(final String ta } private EncryptBinaryCondition createEncryptBinaryOperationCondition(final String tableName, final BinaryOperationExpression expression, final ExpressionSegment compareRightValue) { - String columnName = ((ColumnSegment) expression.getLeft()).getIdentifier().getValue(); - return new EncryptBinaryCondition(columnName, tableName, expression.getOperator(), compareRightValue.getStartIndex(), expression.getStopIndex(), compareRightValue); + ColumnSegment columnSegment = (ColumnSegment) expression.getLeft(); + return new EncryptBinaryCondition(columnSegment, tableName, expression.getOperator(), compareRightValue.getStartIndex(), expression.getStopIndex(), compareRightValue); } private static Optional createInEncryptCondition(final String tableName, final InExpression inExpression, final ExpressionSegment inRightValue) { @@ -201,7 +203,7 @@ private static Optional createInEncryptCondition(final String if (expressionSegments.isEmpty()) { return Optional.empty(); } - String columnName = ((ColumnSegment) inExpression.getLeft()).getIdentifier().getValue(); - return Optional.of(new EncryptInCondition(columnName, tableName, inRightValue.getStartIndex(), inRightValue.getStopIndex(), expressionSegments)); + ColumnSegment columnSegment = (ColumnSegment) inExpression.getLeft(); + return Optional.of(new EncryptInCondition(columnSegment, tableName, inRightValue.getStartIndex(), inRightValue.getStopIndex(), expressionSegments)); } } diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptBinaryCondition.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptBinaryCondition.java index a345ef0d7c6bb..16572e68993db 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptBinaryCondition.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptBinaryCondition.java @@ -21,6 +21,7 @@ import lombok.Getter; import lombok.ToString; import org.apache.shardingsphere.encrypt.rewrite.condition.EncryptCondition; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.FunctionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment; @@ -37,7 +38,7 @@ @ToString public final class EncryptBinaryCondition implements EncryptCondition { - private final String columnName; + private final ColumnSegment columnSegment; private final String tableName; @@ -53,8 +54,9 @@ public final class EncryptBinaryCondition implements EncryptCondition { private final Map positionValueMap = new LinkedHashMap<>(); - public EncryptBinaryCondition(final String columnName, final String tableName, final String operator, final int startIndex, final int stopIndex, final ExpressionSegment expressionSegment) { - this.columnName = columnName; + public EncryptBinaryCondition(final ColumnSegment columnSegment, final String tableName, final String operator, final int startIndex, final int stopIndex, + final ExpressionSegment expressionSegment) { + this.columnSegment = columnSegment; this.tableName = tableName; this.operator = operator; this.startIndex = startIndex; diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptInCondition.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptInCondition.java index 7f6801f6d2af2..4a47a0261d5d5 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptInCondition.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptInCondition.java @@ -21,6 +21,7 @@ import lombok.Getter; import lombok.ToString; import org.apache.shardingsphere.encrypt.rewrite.condition.EncryptCondition; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.ParameterMarkerExpressionSegment; @@ -37,7 +38,7 @@ @ToString public final class EncryptInCondition implements EncryptCondition { - private final String columnName; + private final ColumnSegment columnSegment; private final String tableName; @@ -49,8 +50,8 @@ public final class EncryptInCondition implements EncryptCondition { private final Map positionValueMap = new LinkedHashMap<>(); - public EncryptInCondition(final String columnName, final String tableName, final int startIndex, final int stopIndex, final List expressionSegments) { - this.columnName = columnName; + public EncryptInCondition(final ColumnSegment columnSegment, final String tableName, final int startIndex, final int stopIndex, final List expressionSegments) { + this.columnSegment = columnSegment; this.tableName = tableName; this.startIndex = startIndex; this.stopIndex = stopIndex; diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java index c79fe379b8a7e..045a014ba0094 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java @@ -86,15 +86,16 @@ private Collection createEncryptConditions(final EncryptRule r return createEncryptConditions(rule, sqlRewriteContext, sqlStatementContext); } - private Collection createEncryptConditions(final EncryptRule rule, final SQLRewriteContext sqlRewriteContext, final SQLStatementContext sqlStatementContext) { + private Collection createEncryptConditions(final EncryptRule rule, final SQLRewriteContext sqlRewriteContext, + final SQLStatementContext sqlStatementContext) { if (!(sqlStatementContext instanceof WhereAvailable)) { return Collections.emptyList(); } Collection allSubqueryContexts = SQLStatementContextExtractor.getAllSubqueryContexts(sqlStatementContext); Collection whereSegments = SQLStatementContextExtractor.getWhereSegments((WhereAvailable) sqlStatementContext, allSubqueryContexts); Collection columnSegments = SQLStatementContextExtractor.getColumnSegments((WhereAvailable) sqlStatementContext, allSubqueryContexts); - return new EncryptConditionEngine( - rule, sqlRewriteContext.getDatabase()).createEncryptConditions(whereSegments, columnSegments, sqlStatementContext, sqlRewriteContext.getDatabase().getName()); + return new EncryptConditionEngine(rule, sqlRewriteContext.getDatabase()).createEncryptConditions(whereSegments, columnSegments, sqlStatementContext, + sqlRewriteContext.getDatabase().getName()); } private void rewriteParameters(final SQLRewriteContext sqlRewriteContext, final Collection parameterRewriters) { diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptPredicateParameterRewriter.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptPredicateParameterRewriter.java index ffe18e38314e1..54d8ad7127a45 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptPredicateParameterRewriter.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptPredicateParameterRewriter.java @@ -84,8 +84,8 @@ public void rewrite(final ParameterBuilder paramBuilder, final SQLStatementConte } private List getEncryptedValues(final String schemaName, final EncryptCondition encryptCondition, final List originalValues) { - String tableName = encryptCondition.getTableName(); - String columnName = encryptCondition.getColumnName(); + String tableName = encryptCondition.getColumnSegment().getColumnBoundInfo().getOriginalTable().getValue(); + String columnName = encryptCondition.getColumnSegment().getIdentifier().getValue(); EncryptTable encryptTable = rule.getEncryptTable(tableName); EncryptColumn encryptColumn = encryptTable.getEncryptColumn(columnName); if (encryptCondition instanceof EncryptBinaryCondition && "LIKE".equals(((EncryptBinaryCondition) encryptCondition).getOperator()) && encryptColumn.getLikeQuery().isPresent()) { diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptInsertPredicateRightValueTokenGenerator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptInsertPredicateRightValueTokenGenerator.java index 9f1681ec853f0..b067040abaa0b 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptInsertPredicateRightValueTokenGenerator.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptInsertPredicateRightValueTokenGenerator.java @@ -19,7 +19,6 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; -import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.aware.DatabaseAware; import org.apache.shardingsphere.encrypt.rewrite.aware.EncryptConditionsAware; import org.apache.shardingsphere.encrypt.rewrite.condition.EncryptCondition; import org.apache.shardingsphere.encrypt.rule.EncryptRule; @@ -28,6 +27,7 @@ import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.CollectionSQLTokenGenerator; +import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.aware.DatabaseAware; import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.aware.ParametersAware; import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken; diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateRightValueTokenGenerator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateRightValueTokenGenerator.java index 91309f39c480c..01c815b1ee007 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateRightValueTokenGenerator.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateRightValueTokenGenerator.java @@ -20,7 +20,6 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import org.apache.shardingsphere.encrypt.exception.metadata.MissingMatchedEncryptQueryAlgorithmException; -import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.aware.DatabaseAware; import org.apache.shardingsphere.encrypt.rewrite.aware.EncryptConditionsAware; import org.apache.shardingsphere.encrypt.rewrite.condition.EncryptCondition; import org.apache.shardingsphere.encrypt.rewrite.condition.EncryptConditionValues; @@ -40,6 +39,7 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.CollectionSQLTokenGenerator; +import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.aware.DatabaseAware; import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.aware.ParametersAware; import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.FunctionSegment; @@ -49,6 +49,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Optional; /** * Predicate right value token generator for encrypt. @@ -77,7 +78,8 @@ public Collection generateSQLTokens(final SQLStatementContext sqlState String schemaName = ((TableAvailable) sqlStatementContext).getTablesContext().getSchemaName() .orElseGet(() -> new DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDefaultSchemaName(database.getName())); for (EncryptCondition each : encryptConditions) { - rule.findEncryptTable(each.getTableName()).ifPresent(optional -> result.add(generateSQLToken(schemaName, optional, each))); + Optional encryptTable = rule.findEncryptTable(each.getTableName()); + encryptTable.ifPresent(optional -> result.add(generateSQLToken(schemaName, optional, each))); } return result; } @@ -98,15 +100,16 @@ private SQLToken generateSQLToken(final String schemaName, final EncryptTable en } private List getEncryptedValues(final String schemaName, final EncryptTable encryptTable, final EncryptCondition encryptCondition, final List originalValues) { - EncryptColumn encryptColumn = encryptTable.getEncryptColumn(encryptCondition.getColumnName()); + EncryptColumn encryptColumn = encryptTable.getEncryptColumn(encryptCondition.getColumnSegment().getIdentifier().getValue()); if (encryptCondition instanceof EncryptBinaryCondition && "LIKE".equalsIgnoreCase(((EncryptBinaryCondition) encryptCondition).getOperator())) { LikeQueryColumnItem likeQueryColumnItem = encryptColumn.getLikeQuery() - .orElseThrow(() -> new MissingMatchedEncryptQueryAlgorithmException(encryptTable.getTable(), encryptCondition.getColumnName(), "LIKE")); - return likeQueryColumnItem.encrypt(database.getName(), schemaName, encryptCondition.getTableName(), encryptCondition.getColumnName(), originalValues); + .orElseThrow(() -> new MissingMatchedEncryptQueryAlgorithmException(encryptTable.getTable(), encryptCondition.getColumnSegment().getIdentifier().getValue(), "LIKE")); + return likeQueryColumnItem.encrypt(database.getName(), schemaName, encryptCondition.getTableName(), encryptCondition.getColumnSegment().getIdentifier().getValue(), originalValues); } return encryptColumn.getAssistedQuery() - .map(optional -> optional.encrypt(database.getName(), schemaName, encryptCondition.getTableName(), encryptCondition.getColumnName(), originalValues)) - .orElseGet(() -> encryptColumn.getCipher().encrypt(database.getName(), schemaName, encryptCondition.getTableName(), encryptCondition.getColumnName(), originalValues)); + .map(optional -> optional.encrypt(database.getName(), schemaName, encryptCondition.getTableName(), encryptCondition.getColumnSegment().getIdentifier().getValue(), originalValues)) + .orElseGet(() -> encryptColumn.getCipher().encrypt(database.getName(), schemaName, encryptCondition.getTableName(), encryptCondition.getColumnSegment().getIdentifier().getValue(), + originalValues)); } private Map getPositionValues(final Collection valuePositions, final List encryptValues) { diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptBinaryConditionTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptBinaryConditionTest.java index 9a18fef1b8529..a12da4dac89f1 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptBinaryConditionTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptBinaryConditionTest.java @@ -17,10 +17,12 @@ package org.apache.shardingsphere.encrypt.rewrite.condition.impl; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.FunctionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.ParameterMarkerExpressionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; import java.util.Collections; @@ -34,14 +36,14 @@ class EncryptBinaryConditionTest { @Test void assertNewInstanceWithParameterMarkerExpression() { - EncryptBinaryCondition actual = new EncryptBinaryCondition("col", null, null, 0, 0, new ParameterMarkerExpressionSegment(0, 0, 1)); + EncryptBinaryCondition actual = new EncryptBinaryCondition(new ColumnSegment(0, 0, new IdentifierValue("col")), null, null, 0, 0, new ParameterMarkerExpressionSegment(0, 0, 1)); assertThat(actual.getPositionIndexMap(), is(Collections.singletonMap(0, 1))); assertTrue(actual.getPositionValueMap().isEmpty()); } @Test void assertNewInstanceWithLiteralExpression() { - EncryptBinaryCondition actual = new EncryptBinaryCondition("col", null, null, 0, 0, new LiteralExpressionSegment(0, 0, "foo")); + EncryptBinaryCondition actual = new EncryptBinaryCondition(new ColumnSegment(0, 0, new IdentifierValue("col")), null, null, 0, 0, new LiteralExpressionSegment(0, 0, "foo")); assertTrue(actual.getPositionIndexMap().isEmpty()); assertThat(actual.getPositionValueMap(), is(Collections.singletonMap(0, "foo"))); } @@ -52,7 +54,7 @@ void assertNewInstanceWithConcatFunctionExpression() { functionSegment.getParameters().add(new LiteralExpressionSegment(0, 0, "foo")); functionSegment.getParameters().add(new ParameterMarkerExpressionSegment(0, 0, 1)); functionSegment.getParameters().add(mock(ExpressionSegment.class)); - EncryptBinaryCondition actual = new EncryptBinaryCondition("col", null, null, 0, 0, functionSegment); + EncryptBinaryCondition actual = new EncryptBinaryCondition(new ColumnSegment(0, 0, new IdentifierValue("col")), null, null, 0, 0, functionSegment); assertThat(actual.getPositionIndexMap(), is(Collections.singletonMap(1, 1))); assertThat(actual.getPositionValueMap(), is(Collections.singletonMap(0, "foo"))); } @@ -63,7 +65,7 @@ void assertNewInstanceWithNotConcatFunctionExpression() { functionSegment.getParameters().add(new LiteralExpressionSegment(0, 0, "foo")); functionSegment.getParameters().add(new ParameterMarkerExpressionSegment(0, 0, 1)); functionSegment.getParameters().add(mock(ExpressionSegment.class)); - EncryptBinaryCondition actual = new EncryptBinaryCondition("col", null, null, 0, 0, functionSegment); + EncryptBinaryCondition actual = new EncryptBinaryCondition(new ColumnSegment(0, 0, new IdentifierValue("col")), null, null, 0, 0, functionSegment); assertTrue(actual.getPositionIndexMap().isEmpty()); assertTrue(actual.getPositionValueMap().isEmpty()); } diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptInConditionTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptInConditionTest.java index 8653a506c331b..31ae4bc80dd37 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptInConditionTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/condition/impl/EncryptInConditionTest.java @@ -17,9 +17,11 @@ package org.apache.shardingsphere.encrypt.rewrite.condition.impl; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.ParameterMarkerExpressionSegment; +import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; import java.util.Arrays; @@ -35,7 +37,7 @@ class EncryptInConditionTest { @Test void assertNewInstance() { List expressions = Arrays.asList(new ParameterMarkerExpressionSegment(0, 0, 0), new LiteralExpressionSegment(0, 0, "foo"), mock(ExpressionSegment.class)); - EncryptInCondition actual = new EncryptInCondition("foo_col", null, 0, 0, expressions); + EncryptInCondition actual = new EncryptInCondition(new ColumnSegment(0, 0, new IdentifierValue("foo_col")), null, 0, 0, expressions); assertThat(actual.getPositionIndexMap(), is(Collections.singletonMap(0, 0))); assertThat(actual.getPositionValueMap(), is(Collections.singletonMap(1, "foo"))); }