bereng commented on code in PR #3095:
URL: https://github.com/apache/cassandra/pull/3095#discussion_r1551132644
##########
src/java/org/apache/cassandra/cql3/Relation.java:
##########
@@ -17,227 +17,119 @@
*/
package org.apache.cassandra.cql3;
+import java.util.List;
+
+import org.apache.cassandra.cql3.restrictions.SimpleRestriction;
+import org.apache.cassandra.cql3.restrictions.SingleRestriction;
import org.apache.cassandra.cql3.terms.Term;
import org.apache.cassandra.cql3.terms.Terms;
+import org.apache.cassandra.db.marshal.CollectionType;
import org.apache.cassandra.schema.TableMetadata;
-import org.apache.cassandra.cql3.restrictions.Restriction;
-import org.apache.cassandra.cql3.statements.Bound;
import org.apache.cassandra.exceptions.InvalidRequestException;
import static
org.apache.cassandra.cql3.statements.RequestValidations.invalidRequest;
-public abstract class Relation
+public final class Relation
{
- protected Operator operator;
-
- public Operator operator()
- {
- return operator;
- }
-
/**
- * Returns the raw value for this relation, or null if this is an IN
relation.
+ * The raw columns'expression.
*/
- public abstract Term.Raw getValue();
+ private final ColumnsExpression.Raw rawExpressions;
/**
- * Returns the list of raw IN values for this relation, or null if this is
not an IN relation.
+ * The relation operator
*/
- public abstract Terms.Raw getInValues();
+ private final Operator operator;
/**
- * Checks if this relation is a token relation (e.g. <pre>token(a) =
token(1)</pre>).
- *
- * @return <code>true</code> if this relation is a token relation,
<code>false</code> otherwise.
+ * The raw terms.
*/
- public boolean onToken()
+ private final Terms.Raw rawTerms;
+
+ private Relation(ColumnsExpression.Raw rawExpressions, Operator operator,
Terms.Raw rawTerms)
{
- return false;
+ this.rawExpressions = rawExpressions;
+ this.operator = operator;
+ this.rawTerms = rawTerms;
}
- /**
- * Checks if the operator of this relation is a <code>CONTAINS</code>.
- * @return <code>true</code> if the operator of this relation is a
<code>CONTAINS</code>, <code>false</code>
- * otherwise.
- */
- public final boolean isContains()
+ public Operator operator()
{
- return operator == Operator.CONTAINS;
+ return operator;
}
- /**
- * Checks if the operator of this relation is a <code>CONTAINS_KEY</code>.
- * @return <code>true</code> if the operator of this relation is a
<code>CONTAINS_KEY</code>, <code>false</code>
- * otherwise.
- */
- public final boolean isContainsKey()
+ public static Relation singleColumn(ColumnIdentifier identifier, Operator
operator, Term.Raw rawTerm)
{
- return operator == Operator.CONTAINS_KEY;
+ return new Relation(ColumnsExpression.Raw.singleColumn(identifier),
operator, Terms.Raw.of(rawTerm));
}
- /**
- * Checks if the operator of this relation is a <code>IN</code>.
- * @return <code>true</code> if the operator of this relation is a
<code>IN</code>, <code>false</code>
- * otherwise.
- */
- public final boolean isIN()
+ public static Relation singleColumn(ColumnIdentifier identifier, Operator
operator, Terms.Raw rawTerms)
{
- return operator == Operator.IN;
+ return new Relation(ColumnsExpression.Raw.singleColumn(identifier),
operator, rawTerms);
}
- /**
- * Checks if the operator of this relation is a <code>EQ</code>.
- * @return <code>true</code> if the operator of this relation is a
<code>EQ</code>, <code>false</code>
- * otherwise.
- */
- public final boolean isEQ()
+ public static Relation mapElement(ColumnIdentifier identifier, Term.Raw
rawKey, Operator operator, Term.Raw rawTerm)
{
- return operator == Operator.EQ;
+ return new Relation(ColumnsExpression.Raw.mapElement(identifier,
rawKey), operator, Terms.Raw.of(rawTerm));
}
- public final boolean isLIKE()
+ public static Relation multiColumns(List<ColumnIdentifier> identifiers,
Operator operator, Term.Raw rawTerm)
{
- return operator == Operator.LIKE_PREFIX
- || operator == Operator.LIKE_SUFFIX
- || operator == Operator.LIKE_CONTAINS
- || operator == Operator.LIKE_MATCHES
- || operator == Operator.LIKE;
+ return new Relation(ColumnsExpression.Raw.multiColumns(identifiers),
operator, Terms.Raw.of(rawTerm));
}
- /**
- * Checks if the operator of this relation is a <code>Slice</code> (GT,
GTE, LTE, LT).
- *
- * @return <code>true</code> if the operator of this relation is a
<code>Slice</code>, <code>false</code> otherwise.
- */
- public final boolean isSlice()
+ public static Relation multiColumns(List<ColumnIdentifier> identifiers,
Operator operator, Terms.Raw rawTerms)
{
- return operator == Operator.GT
- || operator == Operator.GTE
- || operator == Operator.LTE
- || operator == Operator.LT;
+ return new Relation(ColumnsExpression.Raw.multiColumns(identifiers),
operator, rawTerms);
}
- /**
- * Converts this <code>Relation</code> into a <code>Restriction</code>.
- *
- * @param table the Column Family meta data
- * @param boundNames the variables specification where to collect the bind
variables
- * @return the <code>Restriction</code> corresponding to this
<code>Relation</code>
- * @throws InvalidRequestException if this <code>Relation</code> is not
valid
- */
- public final Restriction toRestriction(TableMetadata table,
VariableSpecifications boundNames)
+ public static Relation token(List<ColumnIdentifier> identifiers, Operator
operator, Term.Raw rawTerm)
{
- switch (operator)
- {
- case EQ: return newEQRestriction(table, boundNames);
- case LT: return newSliceRestriction(table, boundNames, Bound.END,
false);
- case LTE: return newSliceRestriction(table, boundNames, Bound.END,
true);
- case GTE: return newSliceRestriction(table, boundNames,
Bound.START, true);
- case GT: return newSliceRestriction(table, boundNames,
Bound.START, false);
- case IN: return newINRestriction(table, boundNames);
- case CONTAINS: return newContainsRestriction(table, boundNames,
false);
- case CONTAINS_KEY: return newContainsRestriction(table,
boundNames, true);
- case IS_NOT: return newIsNotRestriction(table, boundNames);
- case LIKE_PREFIX:
- case LIKE_SUFFIX:
- case LIKE_CONTAINS:
- case LIKE_MATCHES:
- case LIKE:
- return newLikeRestriction(table, boundNames, operator);
- case ANN:
- throw invalidRequest("ANN is only supported in ORDER BY");
- default: throw invalidRequest("Unsupported \"!=\" relation: %s",
this);
- }
+ return new Relation(ColumnsExpression.Raw.token(identifiers),
operator, Terms.Raw.of(rawTerm));
}
- /**
- * Creates a new EQ restriction instance.
- *
- * @param table the table meta data
- * @param boundNames the variables specification where to collect the bind
variables
- * @return a new EQ restriction instance.
- * @throws InvalidRequestException if the relation cannot be converted
into an EQ restriction.
- */
- protected abstract Restriction newEQRestriction(TableMetadata table,
VariableSpecifications boundNames);
- /**
- * Creates a new IN restriction instance.
- *
- * @param table the table meta data
- * @param boundNames the variables specification where to collect the bind
variables
- * @return a new IN restriction instance
- * @throws InvalidRequestException if the relation cannot be converted
into an IN restriction.
- */
- protected abstract Restriction newINRestriction(TableMetadata table,
VariableSpecifications boundNames);
/**
- * Creates a new Slice restriction instance.
+ * Checks if this relation is a token relation (e.g. <pre>token(a) =
token(1)</pre>).
*
- * @param table the table meta data
- * @param boundNames the variables specification where to collect the bind
variables
- * @param bound the slice bound
- * @param inclusive <code>true</code> if the bound is included.
- * @return a new slice restriction instance
- * @throws InvalidRequestException if the <code>Relation</code> is not
valid
+ * @return <code>true</code> if this relation is a token relation,
<code>false</code> otherwise.
*/
- protected abstract Restriction newSliceRestriction(TableMetadata table,
- VariableSpecifications
boundNames,
- Bound bound,
- boolean inclusive);
+ public boolean onToken()
+ {
+ return rawExpressions.kind() == ColumnsExpression.Kind.TOKEN;
+ }
/**
- * Creates a new Contains restriction instance.
+ * Converts this <code>Relation</code> into a <code>Restriction</code>.
*
- * @param table the table meta data
+ * @param table the Column Family meta data
Review Comment:
Wasn't CF deprecated naming and we should be using `table` instead?
--
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]