This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new f63ccfca9c3 Condition value support is null (#27410)
f63ccfca9c3 is described below
commit f63ccfca9c3f5d624612de7ef18d30923c1ede8b
Author: ZhangCheng <[email protected]>
AuthorDate: Mon Jul 24 14:10:26 2023 +0800
Condition value support is null (#27410)
* condition value support is null
* fix
* Support oracle select into clause parsing
---
.../ConditionValueCompareOperatorGenerator.java | 10 ++++++++--
.../ConditionValueGeneratorFactoryTest.java | 22 ++++++++++++++++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueCompareOperatorGenerator.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueCompareOperatorGenerator.java
index 2e86c8ed78a..a30566e077d 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueCompareOperatorGenerator.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueCompareOperatorGenerator.java
@@ -53,11 +53,13 @@ public final class ConditionValueCompareOperatorGenerator
implements ConditionVa
private static final String AT_LEAST = ">=";
- private static final Collection<String> OPERATORS = new
HashSet<>(Arrays.asList(EQUAL, GREATER_THAN, LESS_THAN, AT_LEAST, AT_MOST));
+ private static final String IS = "IS";
+
+ private static final Collection<String> OPERATORS = new
HashSet<>(Arrays.asList(EQUAL, GREATER_THAN, LESS_THAN, AT_LEAST, AT_MOST, IS));
@Override
public Optional<ShardingConditionValue> generate(final
BinaryOperationExpression predicate, final Column column, final List<Object>
params, final TimestampServiceRule timestampServiceRule) {
- String operator = predicate.getOperator();
+ String operator = predicate.getOperator().toUpperCase();
if (!isSupportedOperator(operator)) {
return Optional.empty();
}
@@ -88,6 +90,10 @@ public final class ConditionValueCompareOperatorGenerator
implements ConditionVa
return Optional.of(new
RangeShardingConditionValue<>(columnName, tableName, Range.atMost(comparable),
parameterMarkerIndexes));
case AT_LEAST:
return Optional.of(new
RangeShardingConditionValue<>(columnName, tableName, Range.atLeast(comparable),
parameterMarkerIndexes));
+ case IS:
+ return "null".equalsIgnoreCase(String.valueOf(comparable))
+ ? Optional.of(new
ListShardingConditionValue<>(columnName, tableName, new
ArrayList<>(Collections.singleton(null)), parameterMarkerIndexes))
+ : Optional.empty();
default:
return Optional.empty();
}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/ConditionValueGeneratorFactoryTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/ConditionValueGeneratorFactoryTest.java
index 5cd55c704d1..c7af365ae71 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/ConditionValueGeneratorFactoryTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/ConditionValueGeneratorFactoryTest.java
@@ -86,4 +86,26 @@ class ConditionValueGeneratorFactoryTest {
assertThat(actual.get().getColumnName(),
is(expected.get().getColumnName()));
assertThat(actual.get().getTableName(),
is(expected.get().getTableName()));
}
+
+ @Test
+ void assertGenerateBinaryOperationIsExpression() {
+ ConditionValueCompareOperatorGenerator
conditionValueCompareOperatorGenerator = new
ConditionValueCompareOperatorGenerator();
+ BinaryOperationExpression rightValue = new
BinaryOperationExpression(0, 0, mock(ColumnSegment.class), new
LiteralExpressionSegment(0, 0, "null"), "IS", null);
+ Optional<ShardingConditionValue> actual =
conditionValueCompareOperatorGenerator.generate(rightValue, column, new
LinkedList<>(), mock(TimestampServiceRule.class));
+ Optional<ShardingConditionValue> expected =
ConditionValueGeneratorFactory.generate(rightValue, column, new LinkedList<>(),
mock(TimestampServiceRule.class));
+ assertTrue(actual.isPresent() && expected.isPresent());
+ assertThat(actual.get().getTableName(),
is(expected.get().getTableName()));
+ assertThat(actual.get().getColumnName(),
is(expected.get().getColumnName()));
+ }
+
+ @Test
+ void assertGenerateBinaryOperationIsLowerCaseExpression() {
+ ConditionValueCompareOperatorGenerator
conditionValueCompareOperatorGenerator = new
ConditionValueCompareOperatorGenerator();
+ BinaryOperationExpression rightValue = new
BinaryOperationExpression(0, 0, mock(ColumnSegment.class), new
LiteralExpressionSegment(0, 0, "null"), "is", null);
+ Optional<ShardingConditionValue> actual =
conditionValueCompareOperatorGenerator.generate(rightValue, column, new
LinkedList<>(), mock(TimestampServiceRule.class));
+ Optional<ShardingConditionValue> expected =
ConditionValueGeneratorFactory.generate(rightValue, column, new LinkedList<>(),
mock(TimestampServiceRule.class));
+ assertTrue(actual.isPresent() && expected.isPresent());
+ assertThat(actual.get().getTableName(),
is(expected.get().getTableName()));
+ assertThat(actual.get().getColumnName(),
is(expected.get().getColumnName()));
+ }
}