bereng commented on code in PR #3095:
URL: https://github.com/apache/cassandra/pull/3095#discussion_r1553256645
##########
src/java/org/apache/cassandra/cql3/restrictions/RestrictionSet.java:
##########
@@ -171,179 +166,125 @@ public boolean hasRestrictionFor(ColumnMetadata.Kind
kind)
*/
public RestrictionSet addRestriction(SingleRestriction restriction)
{
- // RestrictionSet is immutable so we need to clone the restrictions
map.
- TreeMap<ColumnMetadata, SingleRestriction> newRestrictions = new
TreeMap<>(this.restrictions);
+ // RestrictionSet is immutable. Therefore, we need to clone the
restrictions map.
+ NavigableMap<ColumnMetadata, SingleRestriction> newRestricitons = new
TreeMap<>(this.restrictions);
- boolean newHasIn = hasIn || restriction.isIN();
- boolean newHasContains = hasContains || restriction.isContains();
+ boolean newHasIN = hasIn || restriction.isIN();
boolean newHasSlice = hasSlice || restriction.isSlice();
- boolean newHasAnn = hasAnn || restriction.isANN();
- boolean newHasOnlyEqualityRestrictions = hasOnlyEqualityRestrictions
&& (restriction.isEQ() || restriction.isIN());
+ boolean newHasANN = hasAnn || restriction.isANN();
+ boolean newNeedsFilteringOrIndexing = needsFilteringOrIndexing ||
restriction.needsFilteringOrIndexing();
- return new RestrictionSet(mergeRestrictions(newRestrictions,
restriction),
- hasMultiColumnRestrictions ||
restriction.isMultiColumn(),
- newHasIn,
- newHasContains,
+ return new RestrictionSet(mergeRestrictions(newRestricitons,
restriction),
+ newHasIN,
newHasSlice,
- newHasAnn,
- newHasOnlyEqualityRestrictions);
+ newHasANN,
+ newNeedsFilteringOrIndexing);
}
- private TreeMap<ColumnMetadata, SingleRestriction>
mergeRestrictions(TreeMap<ColumnMetadata, SingleRestriction> restrictions,
-
SingleRestriction restriction)
+ private NavigableMap<ColumnMetadata, SingleRestriction>
mergeRestrictions(NavigableMap<ColumnMetadata, SingleRestriction> restrictions,
+
SingleRestriction restriction)
{
- Collection<ColumnMetadata> columnDefs = restriction.getColumnDefs();
- Set<SingleRestriction> existingRestrictions =
getRestrictions(columnDefs);
+ Collection<ColumnMetadata> columns = restriction.columns();
+ Set<SingleRestriction> existings = getRestrictions(columns);
- if (existingRestrictions.isEmpty())
+ if (existings.isEmpty())
{
- for (ColumnMetadata columnDef : columnDefs)
+ for (ColumnMetadata columnDef : columns)
restrictions.put(columnDef, restriction);
}
else
{
- for (SingleRestriction existing : existingRestrictions)
+ for (SingleRestriction existing : existings)
{
SingleRestriction newRestriction = mergeRestrictions(existing,
restriction);
- for (ColumnMetadata columnDef : columnDefs)
+ for (ColumnMetadata columnDef : columns)
restrictions.put(columnDef, newRestriction);
}
}
return restrictions;
}
- @Override
- public Set<Restriction> getRestrictions(ColumnMetadata columnDef)
+ /**
+ * Merges the two specified restrictions.
+ *
+ * @param restriction the first restriction
+ * @param otherRestriction the second restriction
+ * @return the merged restriction
+ * @throws InvalidRequestException if the two restrictions cannot be merged
+ */
+ private static SingleRestriction mergeRestrictions(SingleRestriction
restriction,
+ SingleRestriction
otherRestriction)
{
- Restriction existing = restrictions.get(columnDef);
- return existing == null ? Collections.emptySet() :
Collections.singleton(existing);
+ return restriction == null ? otherRestriction
Review Comment:
Could `restriction` be null?
--
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]