Search in sources :

Example 91 with ColumnMetadata

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);
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata)

Example 92 with ColumnMetadata

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;
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) ArrayList(java.util.ArrayList)

Example 93 with ColumnMetadata

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);
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) ClusteringOrder(org.apache.cassandra.schema.ColumnMetadata.ClusteringOrder)

Example 94 with ColumnMetadata

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));
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata)

Example 95 with ColumnMetadata

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");
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata)

Aggregations

ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)123 Test (org.junit.Test)35 ByteBuffer (java.nio.ByteBuffer)23 Row (org.apache.cassandra.db.rows.Row)17 TableMetadata (org.apache.cassandra.schema.TableMetadata)16 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)15 AbstractType (org.apache.cassandra.db.marshal.AbstractType)8 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)5 java.util (java.util)4 IndexTarget (org.apache.cassandra.cql3.statements.IndexTarget)4 CollectionType (org.apache.cassandra.db.marshal.CollectionType)4 IndexMetadata (org.apache.cassandra.schema.IndexMetadata)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)3 ColumnFilter (org.apache.cassandra.db.filter.ColumnFilter)3 ImmutableBTreePartition (org.apache.cassandra.db.partitions.ImmutableBTreePartition)3 Cell (org.apache.cassandra.db.rows.Cell)3 RowIterator (org.apache.cassandra.db.rows.RowIterator)3 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)3