You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sl...@apache.org on 2016/06/15 07:39:03 UTC
[2/4] cassandra git commit: Allow terms in selection clauses
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java b/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java
index 7b329ac..26b25de 100644
--- a/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/DeleteStatement.java
@@ -122,7 +122,7 @@ public class DeleteStatement extends ModificationStatement
Attributes.Raw attrs,
List<Operation.RawDeletion> deletions,
WhereClause whereClause,
- List<Pair<ColumnIdentifier.Raw, ColumnCondition.Raw>> conditions,
+ List<Pair<ColumnDefinition.Raw, ColumnCondition.Raw>> conditions,
boolean ifExists)
{
super(name, StatementType.DELETE, attrs, conditions, false, ifExists);
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/src/java/org/apache/cassandra/cql3/statements/IndexTarget.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/IndexTarget.java b/src/java/org/apache/cassandra/cql3/statements/IndexTarget.java
index 8cdf2c8..9756a4c 100644
--- a/src/java/org/apache/cassandra/cql3/statements/IndexTarget.java
+++ b/src/java/org/apache/cassandra/cql3/statements/IndexTarget.java
@@ -68,36 +68,36 @@ public class IndexTarget
public static class Raw
{
- private final ColumnIdentifier.Raw column;
+ private final ColumnDefinition.Raw column;
private final Type type;
- private Raw(ColumnIdentifier.Raw column, Type type)
+ private Raw(ColumnDefinition.Raw column, Type type)
{
this.column = column;
this.type = type;
}
- public static Raw simpleIndexOn(ColumnIdentifier.Raw c)
+ public static Raw simpleIndexOn(ColumnDefinition.Raw c)
{
return new Raw(c, Type.SIMPLE);
}
- public static Raw valuesOf(ColumnIdentifier.Raw c)
+ public static Raw valuesOf(ColumnDefinition.Raw c)
{
return new Raw(c, Type.VALUES);
}
- public static Raw keysOf(ColumnIdentifier.Raw c)
+ public static Raw keysOf(ColumnDefinition.Raw c)
{
return new Raw(c, Type.KEYS);
}
- public static Raw keysAndValuesOf(ColumnIdentifier.Raw c)
+ public static Raw keysAndValuesOf(ColumnDefinition.Raw c)
{
return new Raw(c, Type.KEYS_AND_VALUES);
}
- public static Raw fullCollection(ColumnIdentifier.Raw c)
+ public static Raw fullCollection(ColumnDefinition.Raw c)
{
return new Raw(c, Type.FULL);
}
@@ -109,13 +109,9 @@ public class IndexTarget
// same syntax as an index on a regular column (i.e. the 'values' in
// 'CREATE INDEX on table(values(collection));' is optional). So we correct the target type
// when the target column is a collection & the target type is SIMPLE.
- ColumnIdentifier colId = column.prepare(cfm);
- ColumnDefinition columnDef = cfm.getColumnDefinition(colId);
- if (columnDef == null)
- throw new InvalidRequestException("No column definition found for column " + colId);
-
+ ColumnDefinition columnDef = column.prepare(cfm);
Type actualType = (type == Type.SIMPLE && columnDef.type.isCollection()) ? Type.VALUES : type;
- return new IndexTarget(colId, actualType);
+ return new IndexTarget(columnDef.name, actualType);
}
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java b/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
index af89ba8..0a9be0c 100644
--- a/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/ModificationStatement.java
@@ -27,9 +27,9 @@ import org.slf4j.LoggerFactory;
import org.apache.cassandra.auth.Permission;
import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.config.ColumnDefinition;
+import org.apache.cassandra.config.ColumnDefinition.Raw;
import org.apache.cassandra.config.ViewDefinition;
import org.apache.cassandra.cql3.*;
-import org.apache.cassandra.cql3.ColumnIdentifier.Raw;
import org.apache.cassandra.cql3.functions.Function;
import org.apache.cassandra.cql3.restrictions.StatementRestrictions;
import org.apache.cassandra.cql3.selection.Selection;
@@ -549,10 +549,10 @@ public abstract class ModificationStatement implements CQLStatement
}
- Selection.ResultSetBuilder builder = selection.resultSetBuilder(false);
+ Selection.ResultSetBuilder builder = selection.resultSetBuilder(options, false);
SelectStatement.forSelection(cfm, selection).processPartition(partition, options, builder, FBUtilities.nowInSeconds());
- return builder.build(options.getProtocolVersion());
+ return builder.build();
}
public ResultMessage executeInternal(QueryState queryState, QueryOptions options) throws RequestValidationException, RequestExecutionException
@@ -746,21 +746,21 @@ public abstract class ModificationStatement implements CQLStatement
{
protected final StatementType type;
private final Attributes.Raw attrs;
- private final List<Pair<ColumnIdentifier.Raw, ColumnCondition.Raw>> conditions;
+ private final List<Pair<ColumnDefinition.Raw, ColumnCondition.Raw>> conditions;
private final boolean ifNotExists;
private final boolean ifExists;
protected Parsed(CFName name,
StatementType type,
Attributes.Raw attrs,
- List<Pair<ColumnIdentifier.Raw, ColumnCondition.Raw>> conditions,
+ List<Pair<ColumnDefinition.Raw, ColumnCondition.Raw>> conditions,
boolean ifNotExists,
boolean ifExists)
{
super(name);
this.type = type;
this.attrs = attrs;
- this.conditions = conditions == null ? Collections.<Pair<ColumnIdentifier.Raw, ColumnCondition.Raw>>emptyList() : conditions;
+ this.conditions = conditions == null ? Collections.<Pair<ColumnDefinition.Raw, ColumnCondition.Raw>>emptyList() : conditions;
this.ifNotExists = ifNotExists;
this.ifExists = ifExists;
}
@@ -832,16 +832,13 @@ public abstract class ModificationStatement implements CQLStatement
ColumnConditions.Builder builder = ColumnConditions.newBuilder();
- for (Pair<ColumnIdentifier.Raw, ColumnCondition.Raw> entry : conditions)
+ for (Pair<ColumnDefinition.Raw, ColumnCondition.Raw> entry : conditions)
{
- ColumnIdentifier id = entry.left.prepare(metadata);
- ColumnDefinition def = metadata.getColumnDefinition(id);
- checkNotNull(metadata.getColumnDefinition(id), "Unknown identifier %s in IF conditions", id);
-
+ ColumnDefinition def = entry.left.prepare(metadata);
ColumnCondition condition = entry.right.prepare(keyspace(), def, metadata);
condition.collectMarkerSpecification(boundNames);
- checkFalse(def.isPrimaryKeyColumn(), "PRIMARY KEY column '%s' cannot have IF conditions", id);
+ checkFalse(def.isPrimaryKeyColumn(), "PRIMARY KEY column '%s' cannot have IF conditions", def.name);
builder.add(condition);
}
return builder.build();
@@ -884,8 +881,7 @@ public abstract class ModificationStatement implements CQLStatement
*/
protected static ColumnDefinition getColumnDefinition(CFMetaData cfm, Raw rawId)
{
- ColumnIdentifier id = rawId.prepare(cfm);
- return checkNotNull(cfm.getColumnDefinition(id), "Unknown identifier %s", id);
+ return rawId.prepare(cfm);
}
}
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index a4bacda..5f37e5e 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -100,7 +100,7 @@ public class SelectStatement implements CQLStatement
private final ColumnFilter queriedColumns;
// Used by forSelection below
- private static final Parameters defaultParameters = new Parameters(Collections.<ColumnIdentifier.Raw, Boolean>emptyMap(), false, false, false);
+ private static final Parameters defaultParameters = new Parameters(Collections.<ColumnDefinition.Raw, Boolean>emptyMap(), false, false, false);
public SelectStatement(CFMetaData cfm,
int boundTerms,
@@ -386,7 +386,7 @@ public class SelectStatement implements CQLStatement
ClientWarn.instance.warn("Aggregation query used on multiple partition keys (IN restriction)");
}
- Selection.ResultSetBuilder result = selection.resultSetBuilder(parameters.isJson);
+ Selection.ResultSetBuilder result = selection.resultSetBuilder(options, parameters.isJson);
while (!pager.isExhausted())
{
try (PartitionIterator iter = pager.fetchPage(pageSize))
@@ -400,7 +400,7 @@ public class SelectStatement implements CQLStatement
}
}
}
- return new ResultMessage.Rows(result.build(options.getProtocolVersion()));
+ return new ResultMessage.Rows(result.build());
}
private ResultMessage.Rows processResults(PartitionIterator partitions,
@@ -732,7 +732,7 @@ public class SelectStatement implements CQLStatement
int nowInSec,
int userLimit) throws InvalidRequestException
{
- Selection.ResultSetBuilder result = selection.resultSetBuilder(parameters.isJson);
+ Selection.ResultSetBuilder result = selection.resultSetBuilder(options, parameters.isJson);
while (partitions.hasNext())
{
try (RowIterator partition = partitions.next())
@@ -741,7 +741,7 @@ public class SelectStatement implements CQLStatement
}
}
- ResultSet cqlRows = result.build(options.getProtocolVersion());
+ ResultSet cqlRows = result.build();
orderResults(cqlRows);
@@ -779,7 +779,7 @@ public class SelectStatement implements CQLStatement
{
if (!staticRow.isEmpty() && (!restrictions.hasClusteringColumnsRestriction() || cfm.isStaticCompactTable()))
{
- result.newRow(protocolVersion);
+ result.newRow();
for (ColumnDefinition def : selection.getColumns())
{
switch (def.kind)
@@ -801,7 +801,7 @@ public class SelectStatement implements CQLStatement
while (partition.hasNext())
{
Row row = partition.next();
- result.newRow(protocolVersion);
+ result.newRow();
// Respect selection order
for (ColumnDefinition def : selection.getColumns())
{
@@ -894,7 +894,7 @@ public class SelectStatement implements CQLStatement
Selection selection = selectClause.isEmpty()
? Selection.wildcard(cfm)
- : Selection.fromSelectors(cfm, selectClause);
+ : Selection.fromSelectors(cfm, selectClause, boundNames);
StatementRestrictions restrictions = prepareRestrictions(cfm, boundNames, selection, forView);
@@ -949,23 +949,14 @@ public class SelectStatement implements CQLStatement
Selection selection,
boolean forView) throws InvalidRequestException
{
- try
- {
- return new StatementRestrictions(StatementType.SELECT,
- cfm,
- whereClause,
- boundNames,
- selection.containsOnlyStaticColumns(),
- selection.containsAComplexColumn(),
- parameters.allowFiltering,
- forView);
- }
- catch (UnrecognizedEntityException e)
- {
- if (containsAlias(e.entity))
- throw invalidRequest("Aliases aren't allowed in the where clause ('%s')", e.relation);
- throw e;
- }
+ return new StatementRestrictions(StatementType.SELECT,
+ cfm,
+ whereClause,
+ boundNames,
+ selection.containsOnlyStaticColumns(),
+ selection.containsAComplexColumn(),
+ parameters.allowFiltering,
+ forView);
}
/** Returns a Term for the limit or null if no limit is set */
@@ -1011,12 +1002,6 @@ public class SelectStatement implements CQLStatement
"SELECT DISTINCT queries must request all the partition key columns (missing %s)", def.name);
}
- private void handleUnrecognizedOrderingColumn(ColumnIdentifier column) throws InvalidRequestException
- {
- checkFalse(containsAlias(column), "Aliases are not allowed in order by clause ('%s')", column);
- checkFalse(true, "Order by on unknown column %s", column);
- }
-
private Comparator<List<ByteBuffer>> getOrderingComparator(CFMetaData cfm,
Selection selection,
StatementRestrictions restrictions)
@@ -1030,10 +1015,9 @@ public class SelectStatement implements CQLStatement
List<Integer> idToSort = new ArrayList<Integer>();
List<Comparator<ByteBuffer>> sorters = new ArrayList<Comparator<ByteBuffer>>();
- for (ColumnIdentifier.Raw raw : parameters.orderings.keySet())
+ for (ColumnDefinition.Raw raw : parameters.orderings.keySet())
{
- ColumnIdentifier identifier = raw.prepare(cfm);
- ColumnDefinition orderingColumn = cfm.getColumnDefinition(identifier);
+ ColumnDefinition orderingColumn = raw.prepare(cfm);
idToSort.add(orderingIndexes.get(orderingColumn.name));
sorters.add(orderingColumn.type);
}
@@ -1048,12 +1032,9 @@ public class SelectStatement implements CQLStatement
// even if we don't
// ultimately ship them to the client (CASSANDRA-4911).
Map<ColumnIdentifier, Integer> orderingIndexes = new HashMap<>();
- for (ColumnIdentifier.Raw raw : parameters.orderings.keySet())
+ for (ColumnDefinition.Raw raw : parameters.orderings.keySet())
{
- ColumnIdentifier column = raw.prepare(cfm);
- final ColumnDefinition def = cfm.getColumnDefinition(column);
- if (def == null)
- handleUnrecognizedOrderingColumn(column);
+ final ColumnDefinition def = raw.prepare(cfm);
int index = selection.getResultSetIndex(def);
if (index < 0)
index = selection.addColumnForOrdering(def);
@@ -1066,17 +1047,13 @@ public class SelectStatement implements CQLStatement
{
Boolean[] reversedMap = new Boolean[cfm.clusteringColumns().size()];
int i = 0;
- for (Map.Entry<ColumnIdentifier.Raw, Boolean> entry : parameters.orderings.entrySet())
+ for (Map.Entry<ColumnDefinition.Raw, Boolean> entry : parameters.orderings.entrySet())
{
- ColumnIdentifier column = entry.getKey().prepare(cfm);
+ ColumnDefinition def = entry.getKey().prepare(cfm);
boolean reversed = entry.getValue();
- ColumnDefinition def = cfm.getColumnDefinition(column);
- if (def == null)
- handleUnrecognizedOrderingColumn(column);
-
checkTrue(def.isClusteringColumn(),
- "Order by is currently only supported on the clustered columns of the PRIMARY KEY, got %s", column);
+ "Order by is currently only supported on the clustered columns of the PRIMARY KEY, got %s", def.name);
checkTrue(i++ == def.position(),
"Order by currently only support the ordering of columns following their declared order in the PRIMARY KEY");
@@ -1116,17 +1093,6 @@ public class SelectStatement implements CQLStatement
}
}
- private boolean containsAlias(final ColumnIdentifier name)
- {
- return Iterables.any(selectClause, new Predicate<RawSelector>()
- {
- public boolean apply(RawSelector raw)
- {
- return name.equals(raw.alias);
- }
- });
- }
-
private ColumnSpecification limitReceiver()
{
return new ColumnSpecification(keyspace(), columnFamily(), new ColumnIdentifier("[limit]", true), Int32Type.instance);
@@ -1152,12 +1118,12 @@ public class SelectStatement implements CQLStatement
public static class Parameters
{
// Public because CASSANDRA-9858
- public final Map<ColumnIdentifier.Raw, Boolean> orderings;
+ public final Map<ColumnDefinition.Raw, Boolean> orderings;
public final boolean isDistinct;
public final boolean allowFiltering;
public final boolean isJson;
- public Parameters(Map<ColumnIdentifier.Raw, Boolean> orderings,
+ public Parameters(Map<ColumnDefinition.Raw, Boolean> orderings,
boolean isDistinct,
boolean allowFiltering,
boolean isJson)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java b/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java
index 4675731..3657f94 100644
--- a/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/UpdateStatement.java
@@ -113,7 +113,7 @@ public class UpdateStatement extends ModificationStatement
public static class ParsedInsert extends ModificationStatement.Parsed
{
- private final List<ColumnIdentifier.Raw> columnNames;
+ private final List<ColumnDefinition.Raw> columnNames;
private final List<Term.Raw> columnValues;
/**
@@ -127,7 +127,7 @@ public class UpdateStatement extends ModificationStatement
*/
public ParsedInsert(CFName name,
Attributes.Raw attrs,
- List<ColumnIdentifier.Raw> columnNames,
+ List<ColumnDefinition.Raw> columnNames,
List<Term.Raw> columnValues,
boolean ifNotExists)
{
@@ -233,9 +233,7 @@ public class UpdateStatement extends ModificationStatement
Term.Raw raw = prepared.getRawTermForColumn(def);
if (def.isPrimaryKeyColumn())
{
- whereClause.add(new SingleColumnRelation(new ColumnIdentifier.ColumnIdentifierValue(def.name),
- Operator.EQ,
- raw));
+ whereClause.add(new SingleColumnRelation(ColumnDefinition.Raw.forColumn(def), Operator.EQ, raw));
}
else
{
@@ -269,7 +267,7 @@ public class UpdateStatement extends ModificationStatement
public static class ParsedUpdate extends ModificationStatement.Parsed
{
// Provided for an UPDATE
- private final List<Pair<ColumnIdentifier.Raw, Operation.RawUpdate>> updates;
+ private final List<Pair<ColumnDefinition.Raw, Operation.RawUpdate>> updates;
private final WhereClause whereClause;
/**
@@ -284,9 +282,9 @@ public class UpdateStatement extends ModificationStatement
* */
public ParsedUpdate(CFName name,
Attributes.Raw attrs,
- List<Pair<ColumnIdentifier.Raw, Operation.RawUpdate>> updates,
+ List<Pair<ColumnDefinition.Raw, Operation.RawUpdate>> updates,
WhereClause whereClause,
- List<Pair<ColumnIdentifier.Raw, ColumnCondition.Raw>> conditions,
+ List<Pair<ColumnDefinition.Raw, ColumnCondition.Raw>> conditions,
boolean ifExists)
{
super(name, StatementType.UPDATE, attrs, conditions, false, ifExists);
@@ -302,7 +300,7 @@ public class UpdateStatement extends ModificationStatement
{
Operations operations = new Operations(type);
- for (Pair<ColumnIdentifier.Raw, Operation.RawUpdate> entry : updates)
+ for (Pair<ColumnDefinition.Raw, Operation.RawUpdate> entry : updates)
{
ColumnDefinition def = getColumnDefinition(cfm, entry.left);
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/src/java/org/apache/cassandra/db/marshal/AbstractType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/AbstractType.java b/src/java/org/apache/cassandra/db/marshal/AbstractType.java
index 67717bb..2b5503b 100644
--- a/src/java/org/apache/cassandra/db/marshal/AbstractType.java
+++ b/src/java/org/apache/cassandra/db/marshal/AbstractType.java
@@ -30,7 +30,9 @@ import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.apache.cassandra.cql3.AssignmentTestable;
import org.apache.cassandra.cql3.CQL3Type;
+import org.apache.cassandra.cql3.ColumnSpecification;
import org.apache.cassandra.cql3.Term;
import org.apache.cassandra.db.TypeSizes;
import org.apache.cassandra.exceptions.SyntaxException;
@@ -54,7 +56,7 @@ import static org.apache.cassandra.db.marshal.AbstractType.ComparisonType.CUSTOM
* represent a valid ByteBuffer for the type being compared.
*/
@Unmetered
-public abstract class AbstractType<T> implements Comparator<ByteBuffer>
+public abstract class AbstractType<T> implements Comparator<ByteBuffer>, AssignmentTestable
{
private static final Logger logger = LoggerFactory.getLogger(AbstractType.class);
@@ -476,4 +478,24 @@ public abstract class AbstractType<T> implements Comparator<ByteBuffer>
throw new IllegalArgumentException(this + " cannot be used in comparisons, so cannot be used as a clustering column");
}
}
+
+ public final AssignmentTestable.TestResult testAssignment(String keyspace, ColumnSpecification receiver)
+ {
+ // We should ignore the fact that the output type is frozen in our comparison as functions do not support
+ // frozen types for arguments
+ AbstractType<?> receiverType = receiver.type;
+ if (isFreezable() && !isMultiCell())
+ receiverType = receiverType.freeze();
+
+ if (isReversed())
+ receiverType = ReversedType.getInstance(receiverType);
+
+ if (equals(receiverType))
+ return AssignmentTestable.TestResult.EXACT_MATCH;
+
+ if (receiverType.isValueCompatibleWith(this))
+ return AssignmentTestable.TestResult.WEAKLY_ASSIGNABLE;
+
+ return AssignmentTestable.TestResult.NOT_ASSIGNABLE;
+ }
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/src/java/org/apache/cassandra/db/marshal/TypeParser.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/TypeParser.java b/src/java/org/apache/cassandra/db/marshal/TypeParser.java
index ba8ad13..78af800 100644
--- a/src/java/org/apache/cassandra/db/marshal/TypeParser.java
+++ b/src/java/org/apache/cassandra/db/marshal/TypeParser.java
@@ -23,6 +23,7 @@ import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.util.*;
+import org.apache.cassandra.cql3.FieldIdentifier;
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;
@@ -538,16 +539,16 @@ public class TypeParser
return sb.toString();
}
- public static String stringifyUserTypeParameters(String keysace, ByteBuffer typeName, List<ByteBuffer> columnNames,
+ public static String stringifyUserTypeParameters(String keysace, ByteBuffer typeName, List<FieldIdentifier> fields,
List<AbstractType<?>> columnTypes, boolean ignoreFreezing)
{
StringBuilder sb = new StringBuilder();
sb.append('(').append(keysace).append(",").append(ByteBufferUtil.bytesToHex(typeName));
- for (int i = 0; i < columnNames.size(); i++)
+ for (int i = 0; i < fields.size(); i++)
{
sb.append(',');
- sb.append(ByteBufferUtil.bytesToHex(columnNames.get(i))).append(":");
+ sb.append(ByteBufferUtil.bytesToHex(fields.get(i).bytes)).append(":");
sb.append(columnTypes.get(i).toString(ignoreFreezing));
}
sb.append(')');
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/src/java/org/apache/cassandra/db/marshal/UserType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/UserType.java b/src/java/org/apache/cassandra/db/marshal/UserType.java
index d2cf94b..7803ee2 100644
--- a/src/java/org/apache/cassandra/db/marshal/UserType.java
+++ b/src/java/org/apache/cassandra/db/marshal/UserType.java
@@ -47,11 +47,11 @@ public class UserType extends TupleType
public final String keyspace;
public final ByteBuffer name;
- private final List<ByteBuffer> fieldNames;
+ private final List<FieldIdentifier> fieldNames;
private final List<String> stringFieldNames;
private final boolean isMultiCell;
- public UserType(String keyspace, ByteBuffer name, List<ByteBuffer> fieldNames, List<AbstractType<?>> fieldTypes, boolean isMultiCell)
+ public UserType(String keyspace, ByteBuffer name, List<FieldIdentifier> fieldNames, List<AbstractType<?>> fieldTypes, boolean isMultiCell)
{
super(fieldTypes, false);
assert fieldNames.size() == fieldTypes.size();
@@ -61,17 +61,8 @@ public class UserType extends TupleType
this.stringFieldNames = new ArrayList<>(fieldNames.size());
this.isMultiCell = isMultiCell;
- for (ByteBuffer fieldName : fieldNames)
- {
- try
- {
- stringFieldNames.add(ByteBufferUtil.string(fieldName, StandardCharsets.UTF_8));
- }
- catch (CharacterCodingException ex)
- {
- throw new AssertionError("Got non-UTF8 field name for user-defined type: " + ByteBufferUtil.bytesToHex(fieldName), ex);
- }
- }
+ for (FieldIdentifier fieldName : fieldNames)
+ stringFieldNames.add(fieldName.toString());
}
public static UserType getInstance(TypeParser parser) throws ConfigurationException, SyntaxException
@@ -79,11 +70,11 @@ public class UserType extends TupleType
Pair<Pair<String, ByteBuffer>, List<Pair<ByteBuffer, AbstractType>>> params = parser.getUserTypeParameters();
String keyspace = params.left.left;
ByteBuffer name = params.left.right;
- List<ByteBuffer> columnNames = new ArrayList<>(params.right.size());
+ List<FieldIdentifier> columnNames = new ArrayList<>(params.right.size());
List<AbstractType<?>> columnTypes = new ArrayList<>(params.right.size());
for (Pair<ByteBuffer, AbstractType> p : params.right)
{
- columnNames.add(p.left);
+ columnNames.add(new FieldIdentifier(p.left));
columnTypes.add(p.right);
}
@@ -118,7 +109,7 @@ public class UserType extends TupleType
return types;
}
- public ByteBuffer fieldName(int i)
+ public FieldIdentifier fieldName(int i)
{
return fieldNames.get(i);
}
@@ -128,7 +119,7 @@ public class UserType extends TupleType
return stringFieldNames.get(i);
}
- public List<ByteBuffer> fieldNames()
+ public List<FieldIdentifier> fieldNames()
{
return fieldNames;
}
@@ -138,23 +129,15 @@ public class UserType extends TupleType
return UTF8Type.instance.compose(name);
}
- public short fieldPosition(ColumnIdentifier field)
- {
- return fieldPosition(field.bytes);
- }
-
- public short fieldPosition(ByteBuffer fieldName)
+ public int fieldPosition(FieldIdentifier fieldName)
{
- for (short i = 0; i < fieldNames.size(); i++)
- if (fieldName.equals(fieldNames.get(i)))
- return i;
- return -1;
+ return fieldNames.indexOf(fieldName);
}
- public CellPath cellPathForField(ByteBuffer fieldName)
+ public CellPath cellPathForField(FieldIdentifier fieldName)
{
// we use the field position instead of the field name to allow for field renaming in ALTER TYPE statements
- return CellPath.create(ByteBufferUtil.bytes(fieldPosition(fieldName)));
+ return CellPath.create(ByteBufferUtil.bytes((short)fieldPosition(fieldName)));
}
public ShortType nameComparator()
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/src/java/org/apache/cassandra/db/view/View.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/view/View.java b/src/java/org/apache/cassandra/db/view/View.java
index 845a6ab..771c242 100644
--- a/src/java/org/apache/cassandra/db/view/View.java
+++ b/src/java/org/apache/cassandra/db/view/View.java
@@ -262,12 +262,12 @@ public class View
if (rel.isMultiColumn())
{
sb.append(((MultiColumnRelation) rel).getEntities().stream()
- .map(ColumnIdentifier.Raw::toCQLString)
+ .map(ColumnDefinition.Raw::toString)
.collect(Collectors.joining(", ", "(", ")")));
}
else
{
- sb.append(((SingleColumnRelation) rel).getEntity().toCQLString());
+ sb.append(((SingleColumnRelation) rel).getEntity());
}
sb.append(" ").append(rel.operator()).append(" ");
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/src/java/org/apache/cassandra/exceptions/UnrecognizedEntityException.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/exceptions/UnrecognizedEntityException.java b/src/java/org/apache/cassandra/exceptions/UnrecognizedEntityException.java
deleted file mode 100644
index e8392e9..0000000
--- a/src/java/org/apache/cassandra/exceptions/UnrecognizedEntityException.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.cassandra.exceptions;
-
-import org.apache.cassandra.cql3.ColumnIdentifier;
-import org.apache.cassandra.cql3.Relation;
-
-/**
- * Exception thrown when an entity is not recognized within a relation.
- */
-public final class UnrecognizedEntityException extends InvalidRequestException
-{
- /**
- * The unrecognized entity.
- */
- public final ColumnIdentifier entity;
-
- /**
- * The entity relation.
- */
- public final Relation relation;
-
- /**
- * Creates a new <code>UnrecognizedEntityException</code>.
- * @param entity the unrecognized entity
- * @param relation the entity relation
- */
- public UnrecognizedEntityException(ColumnIdentifier entity, Relation relation)
- {
- super(String.format("Undefined name %s in where clause ('%s')", entity, relation));
- this.entity = entity;
- this.relation = relation;
- }
-}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java b/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java
index 0503080..68f907e 100644
--- a/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java
+++ b/src/java/org/apache/cassandra/schema/LegacySchemaMigrator.java
@@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory;
import org.apache.cassandra.config.*;
import org.apache.cassandra.cql3.ColumnIdentifier;
+import org.apache.cassandra.cql3.FieldIdentifier;
import org.apache.cassandra.cql3.QueryProcessor;
import org.apache.cassandra.cql3.UntypedResultSet;
import org.apache.cassandra.cql3.functions.FunctionName;
@@ -823,10 +824,10 @@ public final class LegacySchemaMigrator
SystemKeyspace.LEGACY_USERTYPES);
UntypedResultSet.Row row = query(query, keyspaceName, typeName).one();
- List<ByteBuffer> names =
+ List<FieldIdentifier> names =
row.getList("field_names", UTF8Type.instance)
.stream()
- .map(ByteBufferUtil::bytes)
+ .map(t -> FieldIdentifier.forInternalString(t))
.collect(Collectors.toList());
List<AbstractType<?>> types =
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/schema/SchemaKeyspace.java b/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
index ed6e76f..4dc273a 100644
--- a/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
+++ b/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
@@ -433,7 +433,7 @@ public final class SchemaKeyspace
{
RowUpdateBuilder adder = new RowUpdateBuilder(Types, timestamp, mutation)
.clustering(type.getNameAsString())
- .frozenList("field_names", type.fieldNames().stream().map(SchemaKeyspace::bbToString).collect(toList()))
+ .frozenList("field_names", type.fieldNames().stream().map(FieldIdentifier::toString).collect(toList()))
.frozenList("field_types", type.fieldTypes().stream().map(AbstractType::asCQL3Type).map(CQL3Type::toString).collect(toList()));
adder.build();
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/src/java/org/apache/cassandra/schema/Types.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/schema/Types.java b/src/java/org/apache/cassandra/schema/Types.java
index 00801b5..25efd70 100644
--- a/src/java/org/apache/cassandra/schema/Types.java
+++ b/src/java/org/apache/cassandra/schema/Types.java
@@ -24,6 +24,7 @@ import javax.annotation.Nullable;
import com.google.common.collect.*;
+import org.apache.cassandra.cql3.FieldIdentifier;
import org.apache.cassandra.cql3.CQL3Type;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.UserType;
@@ -303,9 +304,9 @@ public final class Types implements Iterable<UserType>
UserType prepare(String keyspace, Types types)
{
- List<ByteBuffer> preparedFieldNames =
+ List<FieldIdentifier> preparedFieldNames =
fieldNames.stream()
- .map(ByteBufferUtil::bytes)
+ .map(t -> FieldIdentifier.forInternalString(t))
.collect(toList());
List<AbstractType<?>> preparedFieldTypes =
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/src/java/org/apache/cassandra/transport/DataType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/transport/DataType.java b/src/java/org/apache/cassandra/transport/DataType.java
index 7abcba7..eb1f1f4 100644
--- a/src/java/org/apache/cassandra/transport/DataType.java
+++ b/src/java/org/apache/cassandra/transport/DataType.java
@@ -28,8 +28,9 @@ import com.google.common.annotations.VisibleForTesting;
import io.netty.buffer.ByteBuf;
-import org.apache.cassandra.exceptions.RequestValidationException;
+import org.apache.cassandra.cql3.FieldIdentifier;
import org.apache.cassandra.db.marshal.*;
+import org.apache.cassandra.exceptions.RequestValidationException;
import org.apache.cassandra.utils.Pair;
public enum DataType implements OptionCodec.Codecable<DataType>
@@ -111,11 +112,11 @@ public enum DataType implements OptionCodec.Codecable<DataType>
String ks = CBUtil.readString(cb);
ByteBuffer name = UTF8Type.instance.decompose(CBUtil.readString(cb));
int n = cb.readUnsignedShort();
- List<ByteBuffer> fieldNames = new ArrayList<>(n);
+ List<FieldIdentifier> fieldNames = new ArrayList<>(n);
List<AbstractType<?>> fieldTypes = new ArrayList<>(n);
for (int i = 0; i < n; i++)
{
- fieldNames.add(UTF8Type.instance.decompose(CBUtil.readString(cb)));
+ fieldNames.add(FieldIdentifier.forInternalString(CBUtil.readString(cb)));
fieldTypes.add(DataType.toType(codec.decodeOne(cb, version)));
}
return new UserType(ks, name, fieldNames, fieldTypes, true);
@@ -163,7 +164,7 @@ public enum DataType implements OptionCodec.Codecable<DataType>
cb.writeShort(udt.size());
for (int i = 0; i < udt.size(); i++)
{
- CBUtil.writeString(UTF8Type.instance.compose(udt.fieldName(i)), cb);
+ CBUtil.writeString(udt.fieldName(i).toString(), cb);
codec.writeOne(DataType.fromType(udt.fieldType(i), version), cb, version);
}
break;
@@ -203,7 +204,7 @@ public enum DataType implements OptionCodec.Codecable<DataType>
size += 2;
for (int i = 0; i < udt.size(); i++)
{
- size += CBUtil.sizeOfString(UTF8Type.instance.compose(udt.fieldName(i)));
+ size += CBUtil.sizeOfString(udt.fieldName(i).toString());
size += codec.oneSerializedSize(DataType.fromType(udt.fieldType(i), version), version);
}
return size;
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/test/unit/org/apache/cassandra/cql3/CQL3TypeLiteralTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/CQL3TypeLiteralTest.java b/test/unit/org/apache/cassandra/cql3/CQL3TypeLiteralTest.java
index 73e0fca..43dc267 100644
--- a/test/unit/org/apache/cassandra/cql3/CQL3TypeLiteralTest.java
+++ b/test/unit/org/apache/cassandra/cql3/CQL3TypeLiteralTest.java
@@ -629,11 +629,11 @@ public class CQL3TypeLiteralTest
static UserType randomUserType(int level)
{
int typeCount = 2 + randInt(5);
- List<ByteBuffer> names = new ArrayList<>();
+ List<FieldIdentifier> names = new ArrayList<>();
List<AbstractType<?>> types = new ArrayList<>();
for (int i = 0; i < typeCount; i++)
{
- names.add(UTF8Type.instance.fromString('f' + randLetters(i)));
+ names.add(FieldIdentifier.forQuoted('f' + randLetters(i)));
types.add(randomNestedType(level));
}
return new UserType("ks", UTF8Type.instance.fromString("u" + randInt(1000000)), names, types, true);
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/test/unit/org/apache/cassandra/cql3/CQLTester.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/CQLTester.java b/test/unit/org/apache/cassandra/cql3/CQLTester.java
index 1e7d05f..bca9e7b 100644
--- a/test/unit/org/apache/cassandra/cql3/CQLTester.java
+++ b/test/unit/org/apache/cassandra/cql3/CQLTester.java
@@ -676,6 +676,11 @@ public abstract class CQLTester
return currentTable == null ? query : String.format(query, KEYSPACE + "." + currentTable);
}
+ protected ResultMessage.Prepared prepare(String query) throws Throwable
+ {
+ return QueryProcessor.prepare(formatQuery(query), ClientState.forInternalCalls(), false);
+ }
+
protected UntypedResultSet execute(String query, Object... values) throws Throwable
{
query = formatQuery(query);
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/test/unit/org/apache/cassandra/cql3/selection/TermSelectionTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/selection/TermSelectionTest.java b/test/unit/org/apache/cassandra/cql3/selection/TermSelectionTest.java
new file mode 100644
index 0000000..065fdbd
--- /dev/null
+++ b/test/unit/org/apache/cassandra/cql3/selection/TermSelectionTest.java
@@ -0,0 +1,338 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.cql3.selection;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.*;
+
+import org.junit.Test;
+
+import org.apache.cassandra.cql3.*;
+import org.apache.cassandra.db.marshal.*;
+import org.apache.cassandra.transport.messages.ResultMessage;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class TermSelectionTest extends CQLTester
+{
+ // Helper method for testSelectLiteral()
+ private void assertConstantResult(UntypedResultSet result, Object constant)
+ {
+ assertRows(result,
+ row(1, "one", constant),
+ row(2, "two", constant),
+ row(3, "three", constant));
+ }
+
+ @Test
+ public void testSelectLiteral() throws Throwable
+ {
+ createTable("CREATE TABLE %s (pk int, ck int, t text, PRIMARY KEY (pk, ck) )");
+ execute("INSERT INTO %s (pk, ck, t) VALUES (1, 1, 'one')");
+ execute("INSERT INTO %s (pk, ck, t) VALUES (1, 2, 'two')");
+ execute("INSERT INTO %s (pk, ck, t) VALUES (1, 3, 'three')");
+
+ assertInvalidMessage("Cannot infer type for term", "SELECT ck, t, 'a const' FROM %s");
+ assertConstantResult(execute("SELECT ck, t, (text)'a const' FROM %s"), "a const");
+
+ assertInvalidMessage("Cannot infer type for term", "SELECT ck, t, 42 FROM %s");
+ assertConstantResult(execute("SELECT ck, t, (int)42 FROM %s"), 42);
+
+ assertInvalidMessage("Cannot infer type for term", "SELECT ck, t, (1, 'foo') FROM %s");
+ assertConstantResult(execute("SELECT ck, t, (tuple<int, text>)(1, 'foo') FROM %s"), tuple(1, "foo"));
+
+ assertInvalidMessage("Cannot infer type for term", "SELECT ck, t, [1, 2, 3] FROM %s");
+ assertConstantResult(execute("SELECT ck, t, (list<int>)[1, 2, 3] FROM %s"), list(1, 2, 3));
+
+ assertInvalidMessage("Cannot infer type for term", "SELECT ck, t, {1, 2, 3} FROM %s");
+ assertConstantResult(execute("SELECT ck, t, (set<int>){1, 2, 3} FROM %s"), set(1, 2, 3));
+
+ assertInvalidMessage("Cannot infer type for term", "SELECT ck, t, {1: 'foo', 2: 'bar', 3: 'baz'} FROM %s");
+ assertConstantResult(execute("SELECT ck, t, (map<int, text>){1: 'foo', 2: 'bar', 3: 'baz'} FROM %s"), map(1, "foo", 2, "bar", 3, "baz"));
+
+ assertColumnNames(execute("SELECT ck, t, (int)42, (int)43 FROM %s"), "ck", "t", "(int)42", "(int)43");
+ assertRows(execute("SELECT ck, t, (int) 42, (int) 43 FROM %s"),
+ row(1, "one", 42, 43),
+ row(2, "two", 42, 43),
+ row(3, "three", 42, 43));
+ }
+
+ @Test
+ public void testSelectUDTLiteral() throws Throwable
+ {
+ String type = createType("CREATE TYPE %s(a int, b text)");
+ createTable("CREATE TABLE %s (k int PRIMARY KEY, v " + type + ")");
+
+ execute("INSERT INTO %s(k, v) VALUES (?, ?)", 0, userType("a", 3, "b", "foo"));
+
+ assertInvalidMessage("Cannot infer type for term", "SELECT k, v, { a: 4, b: 'bar'} FROM %s");
+
+ assertRows(execute("SELECT k, v, (" + type + "){ a: 4, b: 'bar'} FROM %s"),
+ row(0, userType("a", 3, "b", "foo"), userType("a", 4, "b", "bar"))
+ );
+ }
+
+ @Test
+ public void testInvalidSelect() throws Throwable
+ {
+ // Creates a table just so we can reference it in the (invalid) SELECT below
+ createTable("CREATE TABLE %s (k int PRIMARY KEY)");
+
+ assertInvalidMessage("Cannot infer type for term", "SELECT ? FROM %s");
+ assertInvalidMessage("Cannot infer type for term", "SELECT k, ? FROM %s");
+
+ assertInvalidMessage("Cannot infer type for term", "SELECT k, null FROM %s");
+ }
+
+ private void assertColumnSpec(ColumnSpecification spec, String expectedName, AbstractType<?> expectedType)
+ {
+ assertEquals(expectedName, spec.name.toString());
+ assertEquals(expectedType, spec.type);
+ }
+
+ @Test
+ public void testSelectPrepared() throws Throwable
+ {
+ createTable("CREATE TABLE %s (pk int, ck int, t text, PRIMARY KEY (pk, ck) )");
+ execute("INSERT INTO %s (pk, ck, t) VALUES (1, 1, 'one')");
+ execute("INSERT INTO %s (pk, ck, t) VALUES (1, 2, 'two')");
+ execute("INSERT INTO %s (pk, ck, t) VALUES (1, 3, 'three')");
+
+ String query = "SELECT (int)?, (decimal):adecimal, (text)?, (tuple<int,text>):atuple, pk, ck, t FROM %s WHERE pk = ?";
+ ResultMessage.Prepared prepared = prepare(query);
+
+ List<ColumnSpecification> boundNames = prepared.metadata.names;
+
+ // 5 bound variables
+ assertEquals(5, boundNames.size());
+ assertColumnSpec(boundNames.get(0), "[selection]", Int32Type.instance);
+ assertColumnSpec(boundNames.get(1), "adecimal", DecimalType.instance);
+ assertColumnSpec(boundNames.get(2), "[selection]", UTF8Type.instance);
+ assertColumnSpec(boundNames.get(3), "atuple", TypeParser.parse("TupleType(Int32Type,UTF8Type)"));
+ assertColumnSpec(boundNames.get(4), "pk", Int32Type.instance);
+
+
+ List<ColumnSpecification> resultNames = prepared.resultMetadata.names;
+
+ // 7 result "columns"
+ assertEquals(7, resultNames.size());
+ assertColumnSpec(resultNames.get(0), "(int)?", Int32Type.instance);
+ assertColumnSpec(resultNames.get(1), "(decimal)?", DecimalType.instance);
+ assertColumnSpec(resultNames.get(2), "(text)?", UTF8Type.instance);
+ assertColumnSpec(resultNames.get(3), "(tuple<int, text>)?", TypeParser.parse("TupleType(Int32Type,UTF8Type)"));
+ assertColumnSpec(resultNames.get(4), "pk", Int32Type.instance);
+ assertColumnSpec(resultNames.get(5), "ck", Int32Type.instance);
+ assertColumnSpec(resultNames.get(6), "t", UTF8Type.instance);
+
+ assertRows(execute(query, 88, BigDecimal.TEN, "foo bar baz", tuple(42, "ursus"), 1),
+ row(88, BigDecimal.TEN, "foo bar baz", tuple(42, "ursus"),
+ 1, 1, "one"),
+ row(88, BigDecimal.TEN, "foo bar baz", tuple(42, "ursus"),
+ 1, 2, "two"),
+ row(88, BigDecimal.TEN, "foo bar baz", tuple(42, "ursus"),
+ 1, 3, "three"));
+ }
+
+ @Test
+ public void testConstantFunctionArgs() throws Throwable
+ {
+ String fInt = createFunction(KEYSPACE,
+ "int,int",
+ "CREATE FUNCTION %s (val1 int, val2 int) " +
+ "CALLED ON NULL INPUT " +
+ "RETURNS int " +
+ "LANGUAGE java\n" +
+ "AS 'return Math.max(val1, val2);';");
+ String fFloat = createFunction(KEYSPACE,
+ "float,float",
+ "CREATE FUNCTION %s (val1 float, val2 float) " +
+ "CALLED ON NULL INPUT " +
+ "RETURNS float " +
+ "LANGUAGE java\n" +
+ "AS 'return Math.max(val1, val2);';");
+ String fText = createFunction(KEYSPACE,
+ "text,text",
+ "CREATE FUNCTION %s (val1 text, val2 text) " +
+ "CALLED ON NULL INPUT " +
+ "RETURNS text " +
+ "LANGUAGE java\n" +
+ "AS 'return val2;';");
+ String fAscii = createFunction(KEYSPACE,
+ "ascii,ascii",
+ "CREATE FUNCTION %s (val1 ascii, val2 ascii) " +
+ "CALLED ON NULL INPUT " +
+ "RETURNS ascii " +
+ "LANGUAGE java\n" +
+ "AS 'return val2;';");
+ String fTimeuuid = createFunction(KEYSPACE,
+ "timeuuid,timeuuid",
+ "CREATE FUNCTION %s (val1 timeuuid, val2 timeuuid) " +
+ "CALLED ON NULL INPUT " +
+ "RETURNS timeuuid " +
+ "LANGUAGE java\n" +
+ "AS 'return val2;';");
+
+ createTable("CREATE TABLE %s (pk int PRIMARY KEY, valInt int, valFloat float, valText text, valAscii ascii, valTimeuuid timeuuid)");
+ execute("INSERT INTO %s (pk, valInt, valFloat, valText, valAscii, valTimeuuid) " +
+ "VALUES (1, 10, 10.0, '100', '100', 2deb23e0-96b5-11e5-b26d-a939dd1405a3)");
+
+ assertRows(execute("SELECT pk, " + fInt + "(valInt, 100) FROM %s"),
+ row(1, 100));
+ assertRows(execute("SELECT pk, " + fInt + "(valInt, (int)100) FROM %s"),
+ row(1, 100));
+ assertInvalidMessage("Type error: (bigint)100 cannot be passed as argument 1 of function",
+ "SELECT pk, " + fInt + "(valInt, (bigint)100) FROM %s");
+ assertRows(execute("SELECT pk, " + fFloat + "(valFloat, (float)100.00) FROM %s"),
+ row(1, 100f));
+ assertRows(execute("SELECT pk, " + fText + "(valText, 'foo') FROM %s"),
+ row(1, "foo"));
+ assertRows(execute("SELECT pk, " + fAscii + "(valAscii, (ascii)'foo') FROM %s"),
+ row(1, "foo"));
+ assertRows(execute("SELECT pk, " + fTimeuuid + "(valTimeuuid, (timeuuid)34617f80-96b5-11e5-b26d-a939dd1405a3) FROM %s"),
+ row(1, UUID.fromString("34617f80-96b5-11e5-b26d-a939dd1405a3")));
+
+ // ambiguous
+
+ String fAmbiguousFunc1 = createFunction(KEYSPACE,
+ "int,bigint",
+ "CREATE FUNCTION %s (val1 int, val2 bigint) " +
+ "CALLED ON NULL INPUT " +
+ "RETURNS bigint " +
+ "LANGUAGE java\n" +
+ "AS 'return Math.max((long)val1, val2);';");
+ assertRows(execute("SELECT pk, " + fAmbiguousFunc1 + "(valInt, 100) FROM %s"),
+ row(1, 100L));
+ createFunctionOverload(fAmbiguousFunc1, "int,int",
+ "CREATE FUNCTION %s (val1 int, val2 int) " +
+ "CALLED ON NULL INPUT " +
+ "RETURNS bigint " +
+ "LANGUAGE java\n" +
+ "AS 'return (long)Math.max(val1, val2);';");
+ assertInvalidMessage("Ambiguous call to function cql_test_keyspace.function_",
+ "SELECT pk, " + fAmbiguousFunc1 + "(valInt, 100) FROM %s");
+ }
+
+ @Test
+ public void testPreparedFunctionArgs() throws Throwable
+ {
+ createTable("CREATE TABLE %s (pk int, ck int, t text, i int, PRIMARY KEY (pk, ck) )");
+ execute("INSERT INTO %s (pk, ck, t, i) VALUES (1, 1, 'one', 50)");
+ execute("INSERT INTO %s (pk, ck, t, i) VALUES (1, 2, 'two', 100)");
+ execute("INSERT INTO %s (pk, ck, t, i) VALUES (1, 3, 'three', 150)");
+
+ String fIntMax = createFunction(KEYSPACE,
+ "int,int",
+ "CREATE FUNCTION %s (val1 int, val2 int) " +
+ "CALLED ON NULL INPUT " +
+ "RETURNS int " +
+ "LANGUAGE java\n" +
+ "AS 'return Math.max(val1, val2);';");
+
+ // weak typing
+
+ assertRows(execute("SELECT pk, ck, " + fIntMax + "(i, ?) FROM %s", 0),
+ row(1, 1, 50),
+ row(1, 2, 100),
+ row(1, 3, 150));
+ assertRows(execute("SELECT pk, ck, " + fIntMax + "(i, ?) FROM %s", 100),
+ row(1, 1, 100),
+ row(1, 2, 100),
+ row(1, 3, 150));
+ assertRows(execute("SELECT pk, ck, " + fIntMax + "(i, ?) FROM %s", 200),
+ row(1, 1, 200),
+ row(1, 2, 200),
+ row(1, 3, 200));
+
+ // explicit typing
+
+ assertRows(execute("SELECT pk, ck, " + fIntMax + "(i, (int)?) FROM %s", 0),
+ row(1, 1, 50),
+ row(1, 2, 100),
+ row(1, 3, 150));
+ assertRows(execute("SELECT pk, ck, " + fIntMax + "(i, (int)?) FROM %s", 100),
+ row(1, 1, 100),
+ row(1, 2, 100),
+ row(1, 3, 150));
+ assertRows(execute("SELECT pk, ck, " + fIntMax + "(i, (int)?) FROM %s", 200),
+ row(1, 1, 200),
+ row(1, 2, 200),
+ row(1, 3, 200));
+
+ // weak typing
+
+ assertRows(execute("SELECT pk, ck, " + fIntMax + "(i, ?) FROM %s WHERE pk = " + fIntMax + "(1,1)", 0),
+ row(1, 1, 50),
+ row(1, 2, 100),
+ row(1, 3, 150));
+ assertRows(execute("SELECT pk, ck, " + fIntMax + "(i, ?) FROM %s WHERE pk = " + fIntMax + "(2,1)", 0));
+
+ assertRows(execute("SELECT pk, ck, " + fIntMax + "(i, ?) FROM %s WHERE pk = " + fIntMax + "(?,1)", 0, 1),
+ row(1, 1, 50),
+ row(1, 2, 100),
+ row(1, 3, 150));
+ assertRows(execute("SELECT pk, ck, " + fIntMax + "(i, ?) FROM %s WHERE pk = " + fIntMax + "(?,1)", 0, 2));
+
+ // explicit typing
+
+ assertRows(execute("SELECT pk, ck, " + fIntMax + "(i, (int)?) FROM %s WHERE pk = " + fIntMax + "((int)1,(int)1)", 0),
+ row(1, 1, 50),
+ row(1, 2, 100),
+ row(1, 3, 150));
+ assertRows(execute("SELECT pk, ck, " + fIntMax + "(i, (int)?) FROM %s WHERE pk = " + fIntMax + "((int)2,(int)1)", 0));
+
+ assertRows(execute("SELECT pk, ck, " + fIntMax + "(i, (int)?) FROM %s WHERE pk = " + fIntMax + "((int)?,(int)1)", 0, 1),
+ row(1, 1, 50),
+ row(1, 2, 100),
+ row(1, 3, 150));
+ assertRows(execute("SELECT pk, ck, " + fIntMax + "(i, (int)?) FROM %s WHERE pk = " + fIntMax + "((int)?,(int)1)", 0, 2));
+
+ assertInvalidMessage("Invalid unset value for argument", "SELECT pk, ck, " + fIntMax + "(i, (int)?) FROM %s WHERE pk = " + fIntMax + "((int)1,(int)1)", unset());
+ }
+
+ @Test
+ public void testInsertUpdateDelete() throws Throwable
+ {
+ String fIntMax = createFunction(KEYSPACE,
+ "int,int",
+ "CREATE FUNCTION %s (val1 int, val2 int) " +
+ "CALLED ON NULL INPUT " +
+ "RETURNS int " +
+ "LANGUAGE java\n" +
+ "AS 'return Math.max(val1, val2);';");
+
+ createTable("CREATE TABLE %s (pk int, ck int, t text, i int, PRIMARY KEY (pk, ck) )");
+
+ execute("UPDATE %s SET i = " + fIntMax + "(100, 200) WHERE pk = 1 AND ck = 1");
+ assertRows(execute("SELECT i FROM %s WHERE pk = 1 AND ck = 1"),
+ row(200));
+
+ execute("UPDATE %s SET i = " + fIntMax + "(100, 300) WHERE pk = 1 AND ck = " + fIntMax + "(1,2)");
+ assertRows(execute("SELECT i FROM %s WHERE pk = 1 AND ck = 2"),
+ row(300));
+
+ execute("DELETE FROM %s WHERE pk = 1 AND ck = " + fIntMax + "(1,2)");
+ assertRows(execute("SELECT i FROM %s WHERE pk = 1 AND ck = 2"));
+
+ execute("INSERT INTO %s (pk, ck, i) VALUES (1, " + fIntMax + "(1,2), " + fIntMax + "(100, 300))");
+ assertRows(execute("SELECT i FROM %s WHERE pk = 1 AND ck = 2"),
+ row(300));
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java
index fd09bc4..24a9528 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java
@@ -148,9 +148,6 @@ public class AggregationTest extends CQLTester
assertColumnNames(execute("SELECT COUNT(1) as myCount FROM %s"), "mycount");
assertRows(execute("SELECT COUNT(1) as myCount FROM %s"), row(0L));
- // Test invalid call
- assertInvalidSyntaxMessage("Only COUNT(1) is supported, got COUNT(2)", "SELECT COUNT(2) FROM %s");
-
// Test with other aggregates
assertColumnNames(execute("SELECT COUNT(*), max(b), b FROM %s"), "count", "system.max(b)", "b");
assertRows(execute("SELECT COUNT(*), max(b), b FROM %s"), row(0L, null, null));
@@ -250,7 +247,7 @@ public class AggregationTest extends CQLTester
assertRows(execute("SELECT count(b.x), max(b.x) as max, b.x, c.x as first FROM %s"),
row(3L, 8, 2, null));
- assertInvalidMessage("Invalid field selection: max(b) of type blob is not a user type",
+ assertInvalidMessage("Invalid field selection: system.max(b) of type blob is not a user type",
"SELECT max(b).x as max FROM %s");
}
@@ -353,7 +350,6 @@ public class AggregationTest extends CQLTester
assertInvalidSyntax("SELECT max(b), max(c) FROM %s WHERE max(a) = 1");
assertInvalidMessage("aggregate functions cannot be used as arguments of aggregate functions", "SELECT max(sum(c)) FROM %s");
- assertInvalidSyntax("SELECT COUNT(2) FROM %s");
}
@Test
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/test/unit/org/apache/cassandra/cql3/validation/operations/DeleteTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/DeleteTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/DeleteTest.java
index 89b90a6..9ead942 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/DeleteTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/DeleteTest.java
@@ -397,10 +397,10 @@ public class DeleteTest extends CQLTester
"DELETE FROM %s WHERE partitionKey = ? AND partitionKey = ?", 0, 1);
// unknown identifiers
- assertInvalidMessage("Unknown identifier unknown",
+ assertInvalidMessage("Undefined column name unknown",
"DELETE unknown FROM %s WHERE partitionKey = ?", 0);
- assertInvalidMessage("Undefined name partitionkey1 in where clause ('partitionkey1 = ?')",
+ assertInvalidMessage("Undefined column name partitionkey1",
"DELETE FROM %s WHERE partitionKey1 = ?", 0);
// Invalid operator in the where clause
@@ -486,13 +486,13 @@ public class DeleteTest extends CQLTester
"DELETE FROM %s WHERE partitionKey = ? AND clustering = ? AND clustering = ?", 0, 1, 1);
// unknown identifiers
- assertInvalidMessage("Unknown identifier value1",
+ assertInvalidMessage("Undefined column name value1",
"DELETE value1 FROM %s WHERE partitionKey = ? AND clustering = ?", 0, 1);
- assertInvalidMessage("Undefined name partitionkey1 in where clause ('partitionkey1 = ?')",
+ assertInvalidMessage("Undefined column name partitionkey1",
"DELETE FROM %s WHERE partitionKey1 = ? AND clustering = ?", 0, 1);
- assertInvalidMessage("Undefined name clustering_3 in where clause ('clustering_3 = ?')",
+ assertInvalidMessage("Undefined column name clustering_3",
"DELETE FROM %s WHERE partitionKey = ? AND clustering_3 = ?", 0, 1);
// Invalid operator in the where clause
@@ -616,13 +616,13 @@ public class DeleteTest extends CQLTester
"DELETE FROM %s WHERE partitionKey = ? AND clustering_1 = ? AND clustering_2 = ? AND clustering_1 = ?", 0, 1, 1, 1);
// unknown identifiers
- assertInvalidMessage("Unknown identifier value1",
+ assertInvalidMessage("Undefined column name value1",
"DELETE value1 FROM %s WHERE partitionKey = ? AND clustering_1 = ? AND clustering_2 = ?", 0, 1, 1);
- assertInvalidMessage("Undefined name partitionkey1 in where clause ('partitionkey1 = ?')",
+ assertInvalidMessage("Undefined column name partitionkey1",
"DELETE FROM %s WHERE partitionKey1 = ? AND clustering_1 = ? AND clustering_2 = ?", 0, 1, 1);
- assertInvalidMessage("Undefined name clustering_3 in where clause ('clustering_3 = ?')",
+ assertInvalidMessage("Undefined column name clustering_3",
"DELETE FROM %s WHERE partitionKey = ? AND clustering_1 = ? AND clustering_3 = ?", 0, 1, 1);
// Invalid operator in the where clause
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/test/unit/org/apache/cassandra/cql3/validation/operations/InsertTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/InsertTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/InsertTest.java
index aa738bb..5314d6a 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/InsertTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/InsertTest.java
@@ -97,10 +97,10 @@ public class InsertTest extends CQLTester
"INSERT INTO %s (partitionKey, clustering, clustering, value) VALUES (0, 0, 0, 2)");
// unknown identifiers
- assertInvalidMessage("Unknown identifier clusteringx",
+ assertInvalidMessage("Undefined column name clusteringx",
"INSERT INTO %s (partitionKey, clusteringx, value) VALUES (0, 0, 2)");
- assertInvalidMessage("Unknown identifier valuex",
+ assertInvalidMessage("Undefined column name valuex",
"INSERT INTO %s (partitionKey, clustering, valuex) VALUES (0, 0, 2)");
}
@@ -145,10 +145,10 @@ public class InsertTest extends CQLTester
"INSERT INTO %s (partitionKey, clustering, clustering, value) VALUES (0, 0, 0, 2)");
// unknown identifiers
- assertInvalidMessage("Unknown identifier clusteringx",
+ assertInvalidMessage("Undefined column name clusteringx",
"INSERT INTO %s (partitionKey, clusteringx, value) VALUES (0, 0, 2)");
- assertInvalidMessage("Unknown identifier valuex",
+ assertInvalidMessage("Undefined column name valuex",
"INSERT INTO %s (partitionKey, clustering, valuex) VALUES (0, 0, 2)");
}
@@ -190,10 +190,10 @@ public class InsertTest extends CQLTester
"INSERT INTO %s (partitionKey, clustering_1, clustering_1, clustering_2, value) VALUES (0, 0, 0, 0, 2)");
// unknown identifiers
- assertInvalidMessage("Unknown identifier clustering_1x",
+ assertInvalidMessage("Undefined column name clustering_1x",
"INSERT INTO %s (partitionKey, clustering_1x, clustering_2, value) VALUES (0, 0, 0, 2)");
- assertInvalidMessage("Unknown identifier valuex",
+ assertInvalidMessage("Undefined column name valuex",
"INSERT INTO %s (partitionKey, clustering_1, clustering_2, valuex) VALUES (0, 0, 0, 2)");
}
@@ -243,10 +243,10 @@ public class InsertTest extends CQLTester
"INSERT INTO %s (partitionKey, clustering_1, clustering_1, clustering_2, value) VALUES (0, 0, 0, 0, 2)");
// unknown identifiers
- assertInvalidMessage("Unknown identifier clustering_1x",
+ assertInvalidMessage("Undefined column name clustering_1x",
"INSERT INTO %s (partitionKey, clustering_1x, clustering_2, value) VALUES (0, 0, 0, 2)");
- assertInvalidMessage("Unknown identifier valuex",
+ assertInvalidMessage("Undefined column name valuex",
"INSERT INTO %s (partitionKey, clustering_1, clustering_2, valuex) VALUES (0, 0, 0, 2)");
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
index 0db0039..1239b7a 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
@@ -1909,11 +1909,11 @@ public class SelectMultiColumnRelationTest extends CQLTester
public void testInvalidColumnNames() throws Throwable
{
createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c))");
- assertInvalidMessage("Undefined name e in where clause ('(b, e) = (0, 0)')", "SELECT * FROM %s WHERE (b, e) = (0, 0)");
- assertInvalidMessage("Undefined name e in where clause ('(b, e) IN ((0, 1), (2, 4))')", "SELECT * FROM %s WHERE (b, e) IN ((0, 1), (2, 4))");
- assertInvalidMessage("Undefined name e in where clause ('(b, e) > (0, 1)')", "SELECT * FROM %s WHERE (b, e) > (0, 1) and b <= 2");
- assertInvalidMessage("Aliases aren't allowed in the where clause ('(b, e) = (0, 0)')", "SELECT c AS e FROM %s WHERE (b, e) = (0, 0)");
- assertInvalidMessage("Aliases aren't allowed in the where clause ('(b, e) IN ((0, 1), (2, 4))')", "SELECT c AS e FROM %s WHERE (b, e) IN ((0, 1), (2, 4))");
- assertInvalidMessage("Aliases aren't allowed in the where clause ('(b, e) > (0, 1)')", "SELECT c AS e FROM %s WHERE (b, e) > (0, 1) and b <= 2");
+ assertInvalidMessage("Undefined column name e", "SELECT * FROM %s WHERE (b, e) = (0, 0)");
+ assertInvalidMessage("Undefined column name e", "SELECT * FROM %s WHERE (b, e) IN ((0, 1), (2, 4))");
+ assertInvalidMessage("Undefined column name e", "SELECT * FROM %s WHERE (b, e) > (0, 1) and b <= 2");
+ assertInvalidMessage("Undefined column name e", "SELECT c AS e FROM %s WHERE (b, e) = (0, 0)");
+ assertInvalidMessage("Undefined column name e", "SELECT c AS e FROM %s WHERE (b, e) IN ((0, 1), (2, 4))");
+ assertInvalidMessage("Undefined column name e", "SELECT c AS e FROM %s WHERE (b, e) > (0, 1) and b <= 2");
}
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderedPartitionerTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderedPartitionerTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderedPartitionerTest.java
index 0b2ed9f..89f3e65 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderedPartitionerTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectOrderedPartitionerTest.java
@@ -483,9 +483,9 @@ public class SelectOrderedPartitionerTest extends CQLTester
public void testTokenFunctionWithInvalidColumnNames() throws Throwable
{
createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY ((a, b), c))");
- assertInvalidMessage("Undefined name e in where clause ('token(a, e) = token(0, 0)')", "SELECT * FROM %s WHERE token(a, e) = token(0, 0)");
- assertInvalidMessage("Undefined name e in where clause ('token(a, e) > token(0, 1)')", "SELECT * FROM %s WHERE token(a, e) > token(0, 1)");
- assertInvalidMessage("Aliases aren't allowed in the where clause ('token(a, e) = token(0, 0)')", "SELECT b AS e FROM %s WHERE token(a, e) = token(0, 0)");
- assertInvalidMessage("Aliases aren't allowed in the where clause ('token(a, e) > token(0, 1)')", "SELECT b AS e FROM %s WHERE token(a, e) > token(0, 1)");
+ assertInvalidMessage("Undefined column name e", "SELECT * FROM %s WHERE token(a, e) = token(0, 0)");
+ assertInvalidMessage("Undefined column name e", "SELECT * FROM %s WHERE token(a, e) > token(0, 1)");
+ assertInvalidMessage("Undefined column name e", "SELECT b AS e FROM %s WHERE token(a, e) = token(0, 0)");
+ assertInvalidMessage("Undefined column name e", "SELECT b AS e FROM %s WHERE token(a, e) > token(0, 1)");
}
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/test/unit/org/apache/cassandra/cql3/validation/operations/SelectSingleColumnRelationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectSingleColumnRelationTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectSingleColumnRelationTest.java
index 4beb1fb..0e2517b 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectSingleColumnRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectSingleColumnRelationTest.java
@@ -620,16 +620,16 @@ public class SelectSingleColumnRelationTest extends CQLTester
public void testInvalidColumnNames() throws Throwable
{
createTable("CREATE TABLE %s (a int, b int, c map<int, int>, PRIMARY KEY (a, b))");
- assertInvalidMessage("Undefined name d in where clause ('d = 0')", "SELECT * FROM %s WHERE d = 0");
- assertInvalidMessage("Undefined name d in where clause ('d IN [0, 1]')", "SELECT * FROM %s WHERE d IN (0, 1)");
- assertInvalidMessage("Undefined name d in where clause ('d > 0')", "SELECT * FROM %s WHERE d > 0 and d <= 2");
- assertInvalidMessage("Undefined name d in where clause ('d CONTAINS 0')", "SELECT * FROM %s WHERE d CONTAINS 0");
- assertInvalidMessage("Undefined name d in where clause ('d CONTAINS KEY 0')", "SELECT * FROM %s WHERE d CONTAINS KEY 0");
- assertInvalidMessage("Aliases aren't allowed in the where clause ('d = 0')", "SELECT a AS d FROM %s WHERE d = 0");
- assertInvalidMessage("Aliases aren't allowed in the where clause ('d IN [0, 1]')", "SELECT b AS d FROM %s WHERE d IN (0, 1)");
- assertInvalidMessage("Aliases aren't allowed in the where clause ('d > 0')", "SELECT b AS d FROM %s WHERE d > 0 and d <= 2");
- assertInvalidMessage("Aliases aren't allowed in the where clause ('d CONTAINS 0')", "SELECT c AS d FROM %s WHERE d CONTAINS 0");
- assertInvalidMessage("Aliases aren't allowed in the where clause ('d CONTAINS KEY 0')", "SELECT c AS d FROM %s WHERE d CONTAINS KEY 0");
- assertInvalidMessage("Undefined name d in selection clause", "SELECT d FROM %s WHERE a = 0");
+ assertInvalidMessage("Undefined column name d", "SELECT * FROM %s WHERE d = 0");
+ assertInvalidMessage("Undefined column name d", "SELECT * FROM %s WHERE d IN (0, 1)");
+ assertInvalidMessage("Undefined column name d", "SELECT * FROM %s WHERE d > 0 and d <= 2");
+ assertInvalidMessage("Undefined column name d", "SELECT * FROM %s WHERE d CONTAINS 0");
+ assertInvalidMessage("Undefined column name d", "SELECT * FROM %s WHERE d CONTAINS KEY 0");
+ assertInvalidMessage("Undefined column name d", "SELECT a AS d FROM %s WHERE d = 0");
+ assertInvalidMessage("Undefined column name d", "SELECT b AS d FROM %s WHERE d IN (0, 1)");
+ assertInvalidMessage("Undefined column name d", "SELECT b AS d FROM %s WHERE d > 0 and d <= 2");
+ assertInvalidMessage("Undefined column name d", "SELECT c AS d FROM %s WHERE d CONTAINS 0");
+ assertInvalidMessage("Undefined column name d", "SELECT c AS d FROM %s WHERE d CONTAINS KEY 0");
+ assertInvalidMessage("Undefined column name d", "SELECT d FROM %s WHERE a = 0");
}
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java
index f91ec5a..7c0ca7c 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectTest.java
@@ -1159,11 +1159,11 @@ public class SelectTest extends CQLTester
assertEquals(ByteBuffer.wrap(new byte[4]), rs.one().getBlob(rs.metadata().get(0).name.toString()));
// test that select throws a meaningful exception for aliases in where clause
- assertInvalidMessage("Aliases aren't allowed in the where clause",
+ assertInvalidMessage("Undefined column name user_id",
"SELECT id AS user_id, name AS user_name FROM %s WHERE user_id = 0");
// test that select throws a meaningful exception for aliases in order by clause
- assertInvalidMessage("Aliases are not allowed in order by clause",
+ assertInvalidMessage("Undefined column name user_name",
"SELECT id AS user_id, name AS user_name FROM %s WHERE id IN (0) ORDER BY user_name");
}
@@ -1401,11 +1401,11 @@ public class SelectTest extends CQLTester
for (int i = 0; i < 5; i++)
execute("INSERT INTO %s (id, name) VALUES (?, ?) USING TTL 10 AND TIMESTAMP 0", i, Integer.toString(i));
- assertInvalidMessage("Aliases aren't allowed in the where clause",
+ assertInvalidMessage("Undefined column name user_id",
"SELECT id AS user_id, name AS user_name FROM %s WHERE user_id = 0");
// test that select throws a meaningful exception for aliases in order by clause
- assertInvalidMessage("Aliases are not allowed in order by clause",
+ assertInvalidMessage("Undefined column name user_name",
"SELECT id AS user_id, name AS user_name FROM %s WHERE id IN (0) ORDER BY user_name");
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/test/unit/org/apache/cassandra/cql3/validation/operations/UpdateTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/UpdateTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/UpdateTest.java
index b2e59a3..9c42fc2 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/UpdateTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/UpdateTest.java
@@ -196,13 +196,13 @@ public class UpdateTest extends CQLTester
"UPDATE %s SET value = ? WHERE partitionKey = ? AND clustering_1 = ? AND clustering_1 = ?", 7, 0, 1, 1);
// unknown identifiers
- assertInvalidMessage("Unknown identifier value1",
+ assertInvalidMessage("Undefined column name value1",
"UPDATE %s SET value1 = ? WHERE partitionKey = ? AND clustering_1 = ?", 7, 0, 1);
- assertInvalidMessage("Undefined name partitionkey1 in where clause ('partitionkey1 = ?')",
+ assertInvalidMessage("Undefined column name partitionkey1",
"UPDATE %s SET value = ? WHERE partitionKey1 = ? AND clustering_1 = ?", 7, 0, 1);
- assertInvalidMessage("Undefined name clustering_3 in where clause ('clustering_3 = ?')",
+ assertInvalidMessage("Undefined column name clustering_3",
"UPDATE %s SET value = ? WHERE partitionKey = ? AND clustering_3 = ?", 7, 0, 1);
// Invalid operator in the where clause
@@ -383,13 +383,13 @@ public class UpdateTest extends CQLTester
"UPDATE %s SET value = ? WHERE partitionKey = ? AND clustering_1 = ? AND clustering_2 = ? AND clustering_1 = ?", 7, 0, 1, 1, 1);
// unknown identifiers
- assertInvalidMessage("Unknown identifier value1",
+ assertInvalidMessage("Undefined column name value1",
"UPDATE %s SET value1 = ? WHERE partitionKey = ? AND clustering_1 = ? AND clustering_2 = ?", 7, 0, 1, 1);
- assertInvalidMessage("Undefined name partitionkey1 in where clause ('partitionkey1 = ?')",
+ assertInvalidMessage("Undefined column name partitionkey1",
"UPDATE %s SET value = ? WHERE partitionKey1 = ? AND clustering_1 = ? AND clustering_2 = ?", 7, 0, 1, 1);
- assertInvalidMessage("Undefined name clustering_3 in where clause ('clustering_3 = ?')",
+ assertInvalidMessage("Undefined column name clustering_3",
"UPDATE %s SET value = ? WHERE partitionKey = ? AND clustering_1 = ? AND clustering_3 = ?", 7, 0, 1, 1);
// Invalid operator in the where clause
http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed00607/test/unit/org/apache/cassandra/schema/LegacySchemaMigratorTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/schema/LegacySchemaMigratorTest.java b/test/unit/org/apache/cassandra/schema/LegacySchemaMigratorTest.java
index 9432c90..2de671c 100644
--- a/test/unit/org/apache/cassandra/schema/LegacySchemaMigratorTest.java
+++ b/test/unit/org/apache/cassandra/schema/LegacySchemaMigratorTest.java
@@ -31,6 +31,7 @@ import org.apache.cassandra.config.ColumnDefinition;
import org.apache.cassandra.config.Schema;
import org.apache.cassandra.cql3.CQLTester;
import org.apache.cassandra.cql3.ColumnIdentifier;
+import org.apache.cassandra.cql3.FieldIdentifier;
import org.apache.cassandra.cql3.functions.*;
import org.apache.cassandra.db.*;
import org.apache.cassandra.db.marshal.*;
@@ -95,6 +96,11 @@ public class LegacySchemaMigratorTest
expected.forEach(LegacySchemaMigratorTest::verifyIndexBuildStatus);
}
+ private static FieldIdentifier field(String field)
+ {
+ return FieldIdentifier.forQuoted(field);
+ }
+
private static void loadLegacySchemaTables()
{
KeyspaceMetadata systemKeyspace = Schema.instance.getKSMetaData(SystemKeyspace.NAME);
@@ -310,19 +316,19 @@ public class LegacySchemaMigratorTest
UserType udt1 = new UserType(keyspace,
bytes("udt1"),
- new ArrayList<ByteBuffer>() {{ add(bytes("col1")); add(bytes("col2")); }},
+ new ArrayList<FieldIdentifier>() {{ add(field("col1")); add(field("col2")); }},
new ArrayList<AbstractType<?>>() {{ add(UTF8Type.instance); add(Int32Type.instance); }},
true);
UserType udt2 = new UserType(keyspace,
bytes("udt2"),
- new ArrayList<ByteBuffer>() {{ add(bytes("col3")); add(bytes("col4")); }},
+ new ArrayList<FieldIdentifier>() {{ add(field("col3")); add(field("col4")); }},
new ArrayList<AbstractType<?>>() {{ add(BytesType.instance); add(BooleanType.instance); }},
true);
UserType udt3 = new UserType(keyspace,
bytes("udt3"),
- new ArrayList<ByteBuffer>() {{ add(bytes("col5")); }},
+ new ArrayList<FieldIdentifier>() {{ add(field("col5")); }},
new ArrayList<AbstractType<?>>() {{ add(AsciiType.instance); }},
true);
@@ -433,13 +439,13 @@ public class LegacySchemaMigratorTest
UserType udt1 = new UserType(keyspace,
bytes("udt1"),
- new ArrayList<ByteBuffer>() {{ add(bytes("col1")); add(bytes("col2")); }},
+ new ArrayList<FieldIdentifier>() {{ add(field("col1")); add(field("col2")); }},
new ArrayList<AbstractType<?>>() {{ add(UTF8Type.instance); add(Int32Type.instance); }},
true);
UserType udt2 = new UserType(keyspace,
bytes("udt2"),
- new ArrayList<ByteBuffer>() {{ add(bytes("col1")); add(bytes("col2")); }},
+ new ArrayList<FieldIdentifier>() {{ add(field("col1")); add(field("col2")); }},
new ArrayList<AbstractType<?>>() {{ add(ListType.getInstance(udt1, false)); add(Int32Type.instance); }},
true);
@@ -482,13 +488,13 @@ public class LegacySchemaMigratorTest
UserType udt1 = new UserType(keyspace,
bytes("udt1"),
- new ArrayList<ByteBuffer>() {{ add(bytes("col1")); add(bytes("col2")); }},
+ new ArrayList<FieldIdentifier>() {{ add(field("col1")); add(field("col2")); }},
new ArrayList<AbstractType<?>>() {{ add(UTF8Type.instance); add(Int32Type.instance); }},
true);
UserType udt2 = new UserType(keyspace,
bytes("udt2"),
- new ArrayList<ByteBuffer>() {{ add(bytes("col1")); add(bytes("col2")); }},
+ new ArrayList<FieldIdentifier>() {{ add(field("col1")); add(field("col2")); }},
new ArrayList<AbstractType<?>>() {{ add(ListType.getInstance(udt1, false)); add(Int32Type.instance); }},
true);
@@ -728,7 +734,7 @@ public class LegacySchemaMigratorTest
for (int i = 0; i < type.size(); i++)
{
- adder.addListEntry("field_names", type.fieldName(i))
+ adder.addListEntry("field_names", type.fieldName(i).toString())
.addListEntry("field_types", type.fieldType(i).toString());
}