maedhroz commented on code in PR #3095:
URL: https://github.com/apache/cassandra/pull/3095#discussion_r1586824098
##########
src/java/org/apache/cassandra/cql3/Relation.java:
##########
@@ -17,227 +17,171 @@
*/
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
+/**
+ * The parsed version of a {@code SimpleRestriction} as outputed by the CQL
parser.
+ * {@code Relation.prepare} will be called upon schema binding to create a
{@code SimpleRestriction}.
+ */
+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()
- {
- return false;
- }
+ private final Terms.Raw 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()
+ private Relation(ColumnsExpression.Raw rawExpressions, Operator operator,
Terms.Raw rawTerms)
{
- return operator == Operator.CONTAINS;
+ this.rawExpressions = rawExpressions;
+ this.operator = operator;
+ this.rawTerms = rawTerms;
}
- /**
- * 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 Operator operator()
{
- return operator == Operator.CONTAINS_KEY;
+ return operator;
}
/**
- * 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.
+ * Creates a relation for a single column (e.g. {@code columnA = ?} ).
+ *
+ * @param identifier the column identifier to which the relation applies
+ * @param operator the relation operator
+ * @param rawTerm the term to which the column values must be compared
+ * @return a relation for a single column.
*/
- public final boolean isIN()
+ public static Relation singleColumn(ColumnIdentifier identifier, Operator
operator, Term.Raw rawTerm)
{
- return operator == Operator.IN;
+ assert operator != Operator.IN;
+ return new Relation(ColumnsExpression.Raw.singleColumn(identifier),
operator, Terms.Raw.of(rawTerm));
}
/**
- * 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.
+ * Creates a relation for a single column (e.g. {@code columnA IN ?} ).
+ *
+ * @param identifier the column identifier to which the relation applies
+ * @param operator the relation operator
+ * @param rawTerms the terms to which the column values must be compared
+ * @return a relation for a single column.
*/
- public final boolean isEQ()
- {
- return operator == Operator.EQ;
- }
-
- public final boolean isLIKE()
+ public static Relation singleColumn(ColumnIdentifier identifier, Operator
operator, Terms.Raw rawTerms)
{
- 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.singleColumn(identifier),
operator, rawTerms);
}
/**
- * Checks if the operator of this relation is a <code>Slice</code> (GT,
GTE, LTE, LT).
+ * Creates a relation for a map element (e.g. {@code columnA[?] = ?}).
*
- * @return <code>true</code> if the operator of this relation is a
<code>Slice</code>, <code>false</code> otherwise.
+ * @param identifier the map column identifier
+ * @param rawKey the map element key
+ * @param operator the relation operator
+ * @param rawTerm the term to which the map element must be compared
+ * @return a relation for a map element.
*/
- public final boolean isSlice()
+ public static Relation mapElement(ColumnIdentifier identifier, Term.Raw
rawKey, Operator operator, Term.Raw rawTerm)
{
- return operator == Operator.GT
- || operator == Operator.GTE
- || operator == Operator.LTE
- || operator == Operator.LT;
+ return new Relation(ColumnsExpression.Raw.mapElement(identifier,
rawKey), operator, Terms.Raw.of(rawTerm));
}
/**
- * Converts this <code>Relation</code> into a <code>Restriction</code>.
+ * Creates a relation for multiple columns (e.g. {@code (columnA, columnB)
= (?, ?)}).
*
- * @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
+ * @param identifiers the columns identifiers
+ * @param operator the relation operator
+ * @param rawTerm the term (tuple) to which the multiple columns must be
compared
+ * @return a relation for multiple columns.
*/
- public final Restriction toRestriction(TableMetadata table,
VariableSpecifications boundNames)
+ public static Relation multiColumns(List<ColumnIdentifier> identifiers,
Operator operator, Term.Raw rawTerm)
Review Comment:
```suggestion
public static Relation multiColumn(List<ColumnIdentifier> identifiers,
Operator operator, Term.Raw rawTerm)
```
...just to be consistent w/ `singleColumn` I guess
--
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]