why return empty when just one conditon is empty #32131
Replies: 7 comments
-
Hi @IcebergXTY |
Beta Was this translation helpful? Give feedback.
-
@RaigorJiang Of course, I push here. |
Beta Was this translation helpful? Give feedback.
-
@IcebergXTY There is no sharding key when database routing, so all data sources are routed. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
@IcebergXTY Because you said that there was an empty sharding condition. |
Beta Was this translation helpful? Give feedback.
-
That's the question, I have set all the values, but shardingsphere consider there is no |
Beta Was this translation helpful? Give feedback.
-
As said in the first, the code here are weird. private Collection<ShardingCondition> createShardingConditions(final ExpressionSegment expression, final List<Object> params, final Map<String, String> columnExpressionTableNames) {
Collection<AndPredicate> andPredicates = ExpressionExtractUtil.getAndPredicates(expression);
Collection<ShardingCondition> result = new LinkedList<>();
for (AndPredicate each : andPredicates) {
Map<Column, Collection<ShardingConditionValue>> shardingConditionValues = createShardingConditionValueMap(each.getPredicates(), params, columnExpressionTableNames);
// If any `AndPredicate` is empty, then all this method will return empty
if (shardingConditionValues.isEmpty()) {
return Collections.emptyList();
}
ShardingCondition shardingCondition = createShardingCondition(shardingConditionValues);
shardingCondition.setStartIndex(expression.getStartIndex());
result.add(shardingCondition);
}
return result;
} |
Beta Was this translation helpful? Give feedback.
-
Question
code location。(shardingshphere 5.3.2)
See the sql below
shardingsphere will analyse two
AndPredicate
, one istenant_code = ? platform_code = ? and shop_code = ? and order_date between ? and ? and (data_source_id = ? and cost_item_name = ?)
and the other isdata_source_id = ? and cost_item_name = ?
.We use
tenant_code = ? platform_code = ? and shop_code = ?
as table sharding rule so theshardingConditionValues
from the firstAndPredicate
is OK, but the second is empty. But in the code above, if there is any emptyshardingConditionValues
, it will returnCollections.emptyList()
which raise an error in our project.I wonder to know why return empty when just one conditon is empty here 🤨
Beta Was this translation helpful? Give feedback.
All reactions