use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class SingleColumnRelation method newLikeRestriction.
@Override
protected Restriction newLikeRestriction(TableMetadata table, VariableSpecifications boundNames, Operator operator) {
if (mapKey != null)
throw invalidRequest("%s can't be used with collections.", operator());
ColumnMetadata columnDef = entity.prepare(table);
Term term = toTerm(toReceivers(columnDef), value, table.keyspace, boundNames);
return new SingleColumnRestriction.LikeRestriction(columnDef, operator, term);
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class MultiColumnRelation method receivers.
protected List<ColumnMetadata> receivers(TableMetadata table) throws InvalidRequestException {
List<ColumnMetadata> names = new ArrayList<>(getEntities().size());
int previousPosition = -1;
for (ColumnMetadata.Raw raw : getEntities()) {
ColumnMetadata def = raw.prepare(table);
checkTrue(def.isClusteringColumn(), "Multi-column relations can only be applied to clustering columns but was applied to: %s", def.name);
checkFalse(names.contains(def), "Column \"%s\" appeared twice in a relation: %s", def.name, this);
// check that no clustering columns were skipped
checkFalse(previousPosition != -1 && def.position() != previousPosition + 1, "Clustering columns must appear in the PRIMARY KEY order in multi-column relations: %s", this);
names.add(def);
previousPosition = def.position();
}
return names;
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class NativeSSTableLoaderClient method createDefinitionFromRow.
private static ColumnMetadata createDefinitionFromRow(Row row, String keyspace, String table, Types types) {
ClusteringOrder order = ClusteringOrder.valueOf(row.getString("clustering_order").toUpperCase());
AbstractType<?> type = CQLTypeParser.parse(keyspace, row.getString("type"), types);
if (order == ClusteringOrder.DESC)
type = ReversedType.getInstance(type);
ColumnIdentifier name = ColumnIdentifier.getInterned(type, row.getBytes("column_name_bytes"), row.getString("column_name"));
int position = row.getInt("position");
org.apache.cassandra.schema.ColumnMetadata.Kind kind = ColumnMetadata.Kind.valueOf(row.getString("kind").toUpperCase());
return new ColumnMetadata(keyspace, table, name, type, position, kind);
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class SelectionColumnMappingTest method testUserDefinedAggregate.
private void testUserDefinedAggregate() throws Throwable {
String sFunc = parseFunctionName(createFunction(KEYSPACE, "int", " CREATE FUNCTION %s (a int, b int)" + " RETURNS NULL ON NULL INPUT" + " RETURNS int" + " LANGUAGE javascript" + " AS 'a + b'")).name;
String aFunc = createAggregate(KEYSPACE, "int, int", " CREATE AGGREGATE %s (int)" + " SFUNC " + sFunc + " STYPE int" + " INITCOND 0");
String plusOne = createFunction(KEYSPACE, "int", " CREATE FUNCTION %s (a int)" + " RETURNS NULL ON NULL INPUT" + " RETURNS int" + " LANGUAGE javascript" + " AS 'a+1'");
String sqFunc = createFunction(KEYSPACE, "int", " CREATE FUNCTION %s (a int)" + " RETURNS NULL ON NULL INPUT" + " RETURNS int" + " LANGUAGE javascript" + " AS 'a*a'");
ColumnMetadata v1 = columnDefinition("v1");
SelectionColumns expected = SelectionColumnMapping.newMapping().addMapping(columnSpecification(aFunc + "(v1)", Int32Type.instance), v1);
verify(expected, String.format("SELECT %s(v1) FROM %%s", aFunc));
// aggregate with nested udfs as input
String specName = String.format("%s(%s(%s(v1)))", aFunc, sqFunc, plusOne);
expected = SelectionColumnMapping.newMapping().addMapping(columnSpecification(specName, Int32Type.instance), v1);
verify(expected, String.format("SELECT %s FROM %%s", specName));
}
use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.
the class SelectionColumnMappingTest method testWildcard.
private void testWildcard() throws Throwable {
// Wildcard select represents each column in the table with a ColumnMetadata
// in the ResultSet metadata
ColumnMetadata kSpec = columnDefinition("k");
ColumnMetadata v1Spec = columnDefinition("v1");
ColumnMetadata v2Spec = columnDefinition("v2");
ColumnMetadata v3Spec = columnDefinition("v3");
SelectionColumnMapping expected = SelectionColumnMapping.newMapping().addMapping(kSpec, columnDefinition("k")).addMapping(v1Spec, columnDefinition("v1")).addMapping(v2Spec, columnDefinition("v2")).addMapping(v3Spec, columnDefinition("v3"));
verify(expected, "SELECT * FROM %s");
}
Aggregations