Search in sources :

Example 16 with ColumnSpecification

use of org.apache.cassandra.cql3.ColumnSpecification 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();
        }

        @Override
        public boolean areAllFetchedColumnsKnown() {
            return Iterables.all(factories, f -> f.areAllFetchedColumnsKnown());
        }

        @Override
        public void addFetchedColumns(ColumnFilter.Builder builder) {
            for (Selector.Factory factory : factories) factory.addFetchedColumns(builder);
        }
    };
}
Also used : ColumnSpecification(org.apache.cassandra.cql3.ColumnSpecification) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) StrBuilder(org.apache.commons.lang3.text.StrBuilder) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) List(java.util.List) QueryOptions(org.apache.cassandra.cql3.QueryOptions)

Example 17 with ColumnSpecification

use of org.apache.cassandra.cql3.ColumnSpecification in project cassandra by apache.

the class AliasedSelectable method newSelectorFactory.

@Override
public Factory newSelectorFactory(TableMetadata table, AbstractType<?> expectedType, List<ColumnMetadata> defs, VariableSpecifications boundNames) {
    final Factory delegate = selectable.newSelectorFactory(table, expectedType, defs, boundNames);
    final ColumnSpecification columnSpec = delegate.getColumnSpecification(table).withAlias(alias);
    return new ForwardingFactory() {

        @Override
        protected Factory delegate() {
            return delegate;
        }

        @Override
        public ColumnSpecification getColumnSpecification(TableMetadata table) {
            return columnSpec;
        }
    };
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ColumnSpecification(org.apache.cassandra.cql3.ColumnSpecification) Factory(org.apache.cassandra.cql3.selection.Selector.Factory)

Example 18 with ColumnSpecification

use of org.apache.cassandra.cql3.ColumnSpecification in project stargate by stargate.

the class DefaultQueryInterceptor method replaceNativeTransportPort.

private static void replaceNativeTransportPort(ResultSet rs, int port) {
    List<ColumnSpecification> columns = rs.metadata.names;
    int columnCount = rs.metadata.getColumnCount();
    int index = -1;
    for (int i = 0; i < columnCount; ++i) {
        if (columns.get(i).name.equals(NATIVE_TRANSPORT_PORT_ID)) {
            index = i;
        }
    }
    if (index == -1) {
        return;
    }
    ByteBuffer portBytes = Int32Type.instance.decompose(port);
    for (List<ByteBuffer> row : rs.rows) {
        row.set(index, portBytes);
    }
}
Also used : ColumnSpecification(org.apache.cassandra.cql3.ColumnSpecification) ByteBuffer(java.nio.ByteBuffer)

Example 19 with ColumnSpecification

use of org.apache.cassandra.cql3.ColumnSpecification in project ecaudit by Ericsson.

the class PreparedAuditOperation method preparedWithValues.

private String preparedWithValues() {
    StringBuilder fullStatement = new StringBuilder(preparedStatement);
    fullStatement.append('[');
    Queue<ByteBuffer> values = new LinkedList<>(options.getValues());
    for (ColumnSpecification column : options.getColumnSpecifications()) {
        ByteBuffer value = values.remove();
        String valueString = boundValueSuppressor.suppress(column, value).orElseGet(() -> CqlLiteralFlavorAdapter.toCQLLiteral(value, column));
        fullStatement.append(valueString).append(", ");
    }
    fullStatement.setLength(fullStatement.length() - 1);
    fullStatement.setCharAt(fullStatement.length() - 1, ']');
    return fullStatement.toString();
}
Also used : ColumnSpecification(org.apache.cassandra.cql3.ColumnSpecification) ByteBuffer(java.nio.ByteBuffer) LinkedList(java.util.LinkedList)

Example 20 with ColumnSpecification

use of org.apache.cassandra.cql3.ColumnSpecification in project ecaudit by Ericsson.

the class TestAuditAdapter method createTextColumns.

private ImmutableList<ColumnSpecification> createTextColumns(String... columns) {
    ImmutableList.Builder<ColumnSpecification> builder = ImmutableList.builder();
    for (String column : columns) {
        ColumnIdentifier id = new ColumnIdentifier(ByteBuffer.wrap(column.getBytes()), UTF8Type.instance);
        ColumnSpecification columnSpecification = new ColumnSpecification("ks", "cf", id, UTF8Type.instance);
        builder.add(columnSpecification);
    }
    return builder.build();
}
Also used : ColumnSpecification(org.apache.cassandra.cql3.ColumnSpecification) ImmutableList(com.google.common.collect.ImmutableList) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier)

Aggregations

ColumnSpecification (org.apache.cassandra.cql3.ColumnSpecification)21 ByteBuffer (java.nio.ByteBuffer)11 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 List (java.util.List)3 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)3 AuditEntry (com.ericsson.bss.cassandra.ecaudit.entry.AuditEntry)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 AssignmentTestable (org.apache.cassandra.cql3.AssignmentTestable)2 QueryOptions (org.apache.cassandra.cql3.QueryOptions)2 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)2 ColumnDefinitions (com.datastax.driver.core.ColumnDefinitions)1 ResultSet (com.datastax.driver.core.ResultSet)1 Session (com.datastax.driver.core.Session)1 LinkedList (java.util.LinkedList)1 Random (java.util.Random)1 UUID (java.util.UUID)1 Parameters (junitparams.Parameters)1 CQLStatement (org.apache.cassandra.cql3.CQLStatement)1