maedhroz commented on code in PR #4222:
URL: https://github.com/apache/cassandra/pull/4222#discussion_r3011093357
##########
test/harry/main/org/apache/cassandra/harry/model/ASTSingleTableModel.java:
##########
@@ -1088,6 +1110,118 @@ else if (c instanceof Conditional.In)
return Pair.create(partitionKeys, other);
}
+ private boolean containsRangeConditionOnClustering(List<Conditional>
conditionals)
+ {
+ for (Conditional cond : conditionals)
+ {
+ if (cond instanceof Conditional.Where)
+ {
+ Conditional.Where where = (Conditional.Where) cond;
+ if (factory.clusteringColumns.contains(where.lhs))
+ {
+ switch (where.kind)
+ {
+ case GREATER_THAN:
+ case GREATER_THAN_EQ:
+ case LESS_THAN:
+ case LESS_THAN_EQ:
+ return true;
+ }
+ }
+ }
+ else if (cond instanceof Conditional.Between)
+ {
+ Conditional.Between between = (Conditional.Between) cond;
+ if (between.ref instanceof Symbol &&
factory.clusteringColumns.contains((Symbol) between.ref))
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private List<Clustering<ByteBuffer>>
extractClusteringsFromSlices(List<Conditional> conditionals)
+ {
+ Map<Symbol, List<Conditional.Where>> rangeConditions = new HashMap<>();
+ for (Conditional cond : conditionals)
+ {
+ if (cond instanceof Conditional.Where)
+ {
+ Conditional.Where where = (Conditional.Where) cond;
+ if (factory.clusteringColumns.contains(where.lhs)
+ && (where.kind != Inequality.EQUAL)) // skip equality
+ {
+ Symbol col = (Symbol) where.lhs;
+ rangeConditions.computeIfAbsent(col, __ -> new
ArrayList<>()).add(where);
+ }
+ }
+ }
+
+ // Build slices
+ Slices.Builder builder = new
Slices.Builder(factory.clusteringComparator);
+
+ for (Map.Entry<Symbol, List<Conditional.Where>> entry :
rangeConditions.entrySet())
+ {
+ ByteBuffer lower = null;
+ ByteBuffer upper = null;
+ boolean includeLower = false;
+ boolean includeUpper = false;
+
+ for (Conditional.Where cond : entry.getValue())
+ {
+ ByteBuffer val = eval(cond.rhs);
+ switch (cond.kind)
+ {
+ case GREATER_THAN: lower = val; includeLower = false;
break;
+ case GREATER_THAN_EQ: lower = val; includeLower = true;
break;
+ case LESS_THAN: upper = val; includeUpper = false; break;
+ case LESS_THAN_EQ: upper = val; includeUpper = true; break;
+ }
+ }
+
+ ClusteringBound<ByteBuffer> start = (lower == null)
+ ? (ClusteringBound<ByteBuffer>)
ClusteringBound.BOTTOM
+ : (includeLower
+ ?
ClusteringBound.inclusiveStartOf(Clustering.make(lower))
+ :
ClusteringBound.exclusiveStartOf(Clustering.make(lower)));
+
+ ClusteringBound<ByteBuffer> end = (upper == null)
+ ? (ClusteringBound<ByteBuffer>)
ClusteringBound.TOP
+ : (includeUpper
+ ?
ClusteringBound.inclusiveEndOf(Clustering.make(upper))
+ :
ClusteringBound.exclusiveEndOf(Clustering.make(upper)));
Review Comment:
Looking at this one more time, I think the best way to make the compiler
happy is something like:
```
ClusteringBound<?> start = (lower == null)
? ClusteringBound.BOTTOM
: (includeLower
?
ClusteringBound.inclusiveStartOf(Clustering.make(lower))
:
ClusteringBound.exclusiveStartOf(Clustering.make(lower)));
ClusteringBound<?> end = (upper == null)
? ClusteringBound.TOP
: (includeUpper
?
ClusteringBound.inclusiveEndOf(Clustering.make(upper))
:
ClusteringBound.exclusiveEndOf(Clustering.make(upper)));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]