Search in sources :

Example 86 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class StatementRestrictions method addRestriction.

private void addRestriction(Restriction restriction) {
    ColumnMetadata def = restriction.getFirstColumn();
    if (def.isPartitionKey())
        partitionKeyRestrictions = partitionKeyRestrictions.mergeWith(restriction);
    else if (def.isClusteringColumn())
        clusteringColumnsRestrictions = clusteringColumnsRestrictions.mergeWith(restriction);
    else
        nonPrimaryKeyRestrictions = nonPrimaryKeyRestrictions.addRestriction((SingleRestriction) restriction);
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata)

Example 87 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class AbstractFunctionSelector method newFactory.

public static Factory newFactory(final Function fun, final SelectorFactories factories) throws InvalidRequestException {
    if (fun.isAggregate()) {
        if (factories.doesAggregation())
            throw new InvalidRequestException("aggregate functions cannot be used as arguments of aggregate functions");
    }
    return new Factory() {

        protected String getColumnName() {
            return fun.columnName(factories.getColumnNames());
        }

        protected AbstractType<?> getReturnType() {
            return fun.returnType();
        }

        protected void addColumnMapping(SelectionColumnMapping mapping, ColumnSpecification resultsColumn) {
            SelectionColumnMapping tmpMapping = SelectionColumnMapping.newMapping();
            for (Factory factory : factories) factory.addColumnMapping(tmpMapping, resultsColumn);
            if (tmpMapping.getMappings().get(resultsColumn).isEmpty())
                // add a null mapping for cases where there are no
                // further selectors, such as no-arg functions and count
                mapping.addMapping(resultsColumn, (ColumnMetadata) null);
            else
                // collate the mapped columns from the child factories & add those
                mapping.addMapping(resultsColumn, tmpMapping.getMappings().values());
        }

        public void addFunctionsTo(List<Function> functions) {
            fun.addFunctionsTo(functions);
            factories.addFunctionsTo(functions);
        }

        public Selector newInstance(QueryOptions options) throws InvalidRequestException {
            return fun.isAggregate() ? new AggregateFunctionSelector(fun, factories.newInstances(options)) : new ScalarFunctionSelector(fun, factories.newInstances(options));
        }

        public boolean isWritetimeSelectorFactory() {
            return factories.containsWritetimeSelectorFactory();
        }

        public boolean isTTLSelectorFactory() {
            return factories.containsTTLSelectorFactory();
        }

        public boolean isAggregateSelectorFactory() {
            return fun.isAggregate() || factories.doesAggregation();
        }
    };
}
Also used : ColumnSpecification(org.apache.cassandra.cql3.ColumnSpecification) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) List(java.util.List) QueryOptions(org.apache.cassandra.cql3.QueryOptions)

Example 88 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class BatchStatement method executeWithConditions.

private ResultMessage executeWithConditions(BatchQueryOptions options, QueryState state, long queryStartNanoTime) throws RequestExecutionException, RequestValidationException {
    Pair<CQL3CasRequest, Set<ColumnMetadata>> p = makeCasRequest(options, state);
    CQL3CasRequest casRequest = p.left;
    Set<ColumnMetadata> columnsWithConditions = p.right;
    String ksName = casRequest.metadata.keyspace;
    String tableName = casRequest.metadata.name;
    try (RowIterator result = StorageProxy.cas(ksName, tableName, casRequest.key, casRequest, options.getSerialConsistency(), options.getConsistency(), state.getClientState(), queryStartNanoTime)) {
        return new ResultMessage.Rows(ModificationStatement.buildCasResultSet(ksName, tableName, result, columnsWithConditions, true, options.forStatement(0)));
    }
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) RowIterator(org.apache.cassandra.db.rows.RowIterator)

Example 89 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class SingleColumnRelation method newEQRestriction.

@Override
protected Restriction newEQRestriction(TableMetadata table, VariableSpecifications boundNames) {
    ColumnMetadata columnDef = entity.prepare(table);
    if (mapKey == null) {
        Term term = toTerm(toReceivers(columnDef), value, table.keyspace, boundNames);
        return new SingleColumnRestriction.EQRestriction(columnDef, term);
    }
    List<? extends ColumnSpecification> receivers = toReceivers(columnDef);
    Term entryKey = toTerm(Collections.singletonList(receivers.get(0)), mapKey, table.keyspace, boundNames);
    Term entryValue = toTerm(Collections.singletonList(receivers.get(1)), value, table.keyspace, boundNames);
    return new SingleColumnRestriction.ContainsRestriction(columnDef, entryKey, entryValue);
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata)

Example 90 with ColumnMetadata

use of org.apache.cassandra.schema.ColumnMetadata in project cassandra by apache.

the class SingleColumnRelation method newINRestriction.

@Override
protected Restriction newINRestriction(TableMetadata table, VariableSpecifications boundNames) {
    ColumnMetadata columnDef = entity.prepare(table);
    List<? extends ColumnSpecification> receivers = toReceivers(columnDef);
    List<Term> terms = toTerms(receivers, inValues, table.keyspace, boundNames);
    if (terms == null) {
        Term term = toTerm(receivers, value, table.keyspace, boundNames);
        return new SingleColumnRestriction.InRestrictionWithMarker(columnDef, (Lists.Marker) term);
    }
    // An IN restrictions with only one element is the same than an EQ restriction
    if (terms.size() == 1)
        return new SingleColumnRestriction.EQRestriction(columnDef, terms.get(0));
    return new SingleColumnRestriction.InRestrictionWithValues(columnDef, terms);
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) SingleColumnRestriction(org.apache.cassandra.cql3.restrictions.SingleColumnRestriction)

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