mike-tr-adamson commented on code in PR #2916:
URL: https://github.com/apache/cassandra/pull/2916#discussion_r1402592562
##########
src/java/org/apache/cassandra/index/sai/plan/Expression.java:
##########
@@ -106,244 +110,344 @@ public Expression(IndexContext indexContext)
* @param value the expression value
* @return the current expression with the added operation
*/
- public Expression add(Operator op, ByteBuffer value)
+ Expression add(Operator op, ByteBuffer value);
+
+ /**
+ * Used in post-filtering to determine is an indexed value matches the
expression
+ */
+ boolean isSatisfiedBy(ByteBuffer columnValue);
+
+ Bound lower();
+
+ Bound upper();
+
+ class IndexedExpression extends AbstractExpression
{
- boolean lowerInclusive, upperInclusive;
- // If the type supports rounding then we need to make sure that index
- // range search is always inclusive, otherwise we run the risk of
- // missing values that are within the exclusive range but are rejected
- // because their rounded value is the same as the value being queried.
- lowerInclusive = upperInclusive = TypeUtil.supportsRounding(validator);
- switch (op)
- {
- case EQ:
- case CONTAINS:
- case CONTAINS_KEY:
- lower = new Bound(value, validator, true);
- upper = lower;
- operator = IndexOperator.valueOf(op);
- break;
-
- case LTE:
- if (context.getDefinition().isReversedType())
- {
- this.lowerInclusive = true;
- lowerInclusive = true;
- }
- else
- {
- this.upperInclusive = true;
- upperInclusive = true;
- }
- case LT:
- operator = IndexOperator.RANGE;
- if (context.getDefinition().isReversedType())
- lower = new Bound(value, validator, lowerInclusive);
- else
- upper = new Bound(value, validator, upperInclusive);
- break;
+ private final StorageAttachedIndex index;
- case GTE:
- if (context.getDefinition().isReversedType())
- {
- this.upperInclusive = true;
- upperInclusive = true;
- }
- else
- {
- this.lowerInclusive = true;
- lowerInclusive = true;
- }
- case GT:
- operator = IndexOperator.RANGE;
- if (context.getDefinition().isReversedType())
- upper = new Bound(value, validator, upperInclusive);
- else
- lower = new Bound(value, validator, lowerInclusive);
- break;
- case ANN:
- operator = IndexOperator.ANN;
- lower = new Bound(value, validator, true);
- upper = lower;
- break;
+ public IndexedExpression(StorageAttachedIndex index)
+ {
+ super(index.termType());
+ this.index = index;
+ }
+
+ @Override
+ public boolean isNotIndexed()
+ {
+ return false;
}
- assert operator != null;
+ @Override
+ public StorageAttachedIndex getIndex()
+ {
+ return index;
+ }
- return this;
+ @Override
+ public AbstractAnalyzer getAnalyzer()
+ {
+ return index.analyzer();
+ }
}
- /**
- * Used in post-filtering to determine is an indexed value matches the
expression
- */
- public boolean isSatisfiedBy(ByteBuffer columnValue)
+ class UnindexedExpression extends AbstractExpression
{
- // If the expression represents an ANN ordering then we return true
because the actual result
- // is approximate and will rarely / never match the expression value
- if (validator.isVector())
+ private UnindexedExpression(IndexTermType indexTermType)
+ {
+ super(indexTermType);
+ }
+
+ @Override
+ public boolean isNotIndexed()
+ {
return true;
+ }
- if (!TypeUtil.isValid(columnValue, validator))
+ @Override
+ public StorageAttachedIndex getIndex()
{
- logger.error(context.logMessage("Value is not valid for indexed
column {} with {}"), context.getColumnName(), validator);
- return false;
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public AbstractAnalyzer getAnalyzer()
+ {
+ return new NoOpAnalyzer();
}
+ }
+
+ abstract class AbstractExpression implements Expression
Review Comment:
Agreed, I have made `Expression` an `abstract class`.
--
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]