Search in sources :

Example 6 with QueryOptions

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

the class StressCQLSSTableWriter method rawAddRow.

/**
     * Adds a new row to the writer given already serialized values.
     * <p>
     * This is a shortcut for {@code rawAddRow(Arrays.asList(values))}.
     *
     * @param values the row values (corresponding to the bind variables of the
     * insertion statement used when creating by this writer) as binary.
     * @return this writer.
     */
public StressCQLSSTableWriter rawAddRow(List<ByteBuffer> values) throws InvalidRequestException, IOException {
    if (values.size() != boundNames.size())
        throw new InvalidRequestException(String.format("Invalid number of arguments, expecting %d values but got %d", boundNames.size(), values.size()));
    QueryOptions options = QueryOptions.forInternalCalls(null, values);
    List<ByteBuffer> keys = insert.buildPartitionKeyNames(options);
    SortedSet<Clustering> clusterings = insert.createClustering(options);
    long now = System.currentTimeMillis() * 1000;
    // Note that we asks indexes to not validate values (the last 'false' arg below) because that triggers a 'Keyspace.open'
    // and that forces a lot of initialization that we don't want.
    UpdateParameters params = new UpdateParameters(insert.metadata(), insert.updatedColumns(), options, insert.getTimestamp(now, options), insert.getTimeToLive(options), Collections.<DecoratedKey, Partition>emptyMap());
    try {
        for (ByteBuffer key : keys) {
            for (Clustering clustering : clusterings) insert.addUpdateForKey(writer.getUpdateFor(key), clustering, params);
        }
        return this;
    } catch (SSTableSimpleUnsortedWriter.SyncException e) {
        // wrapped in a SyncException (see BufferedWriter below). We want to extract that IOE.
        throw (IOException) e.getCause();
    }
}
Also used : InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) UpdateParameters(org.apache.cassandra.cql3.UpdateParameters) QueryOptions(org.apache.cassandra.cql3.QueryOptions) ByteBuffer(java.nio.ByteBuffer)

Example 7 with QueryOptions

use of org.apache.cassandra.cql3.QueryOptions 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 8 with QueryOptions

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

the class CQLSSTableWriter method rawAddRow.

/**
     * Adds a new row to the writer given already serialized values.
     * <p>
     * This is a shortcut for {@code rawAddRow(Arrays.asList(values))}.
     *
     * @param values the row values (corresponding to the bind variables of the
     * insertion statement used when creating by this writer) as binary.
     * @return this writer.
     */
public CQLSSTableWriter rawAddRow(List<ByteBuffer> values) throws InvalidRequestException, IOException {
    if (values.size() != boundNames.size())
        throw new InvalidRequestException(String.format("Invalid number of arguments, expecting %d values but got %d", boundNames.size(), values.size()));
    QueryOptions options = QueryOptions.forInternalCalls(null, values);
    List<ByteBuffer> keys = insert.buildPartitionKeyNames(options);
    SortedSet<Clustering> clusterings = insert.createClustering(options);
    long now = System.currentTimeMillis() * 1000;
    // Note that we asks indexes to not validate values (the last 'false' arg below) because that triggers a 'Keyspace.open'
    // and that forces a lot of initialization that we don't want.
    UpdateParameters params = new UpdateParameters(insert.metadata, insert.updatedColumns(), options, insert.getTimestamp(now, options), insert.getTimeToLive(options), Collections.<DecoratedKey, Partition>emptyMap());
    try {
        for (ByteBuffer key : keys) {
            for (Clustering clustering : clusterings) insert.addUpdateForKey(writer.getUpdateFor(key), clustering, params);
        }
        return this;
    } catch (SSTableSimpleUnsortedWriter.SyncException e) {
        // wrapped in a SyncException (see BufferedWriter below). We want to extract that IOE.
        throw (IOException) e.getCause();
    }
}
Also used : InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) UpdateParameters(org.apache.cassandra.cql3.UpdateParameters) Clustering(org.apache.cassandra.db.Clustering) QueryOptions(org.apache.cassandra.cql3.QueryOptions) ByteBuffer(java.nio.ByteBuffer)

Example 9 with QueryOptions

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

the class CQLTester method schemaChange.

protected static void schemaChange(String query) {
    try {
        ClientState state = ClientState.forInternalCalls();
        state.setKeyspace(SchemaConstants.SYSTEM_KEYSPACE_NAME);
        QueryState queryState = new QueryState(state);
        ParsedStatement.Prepared prepared = QueryProcessor.parseStatement(query, queryState);
        prepared.statement.validate(state);
        QueryOptions options = QueryOptions.forInternalCalls(Collections.<ByteBuffer>emptyList());
        lastSchemaChangeResult = prepared.statement.executeInternal(queryState, options);
    } catch (Exception e) {
        logger.info("Error performing schema change", e);
        throw new RuntimeException("Error setting schema for test (query was: " + query + ")", e);
    }
}
Also used : ClientState(org.apache.cassandra.service.ClientState) ParsedStatement(org.apache.cassandra.cql3.statements.ParsedStatement) QueryState(org.apache.cassandra.service.QueryState) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) SyntaxException(org.apache.cassandra.exceptions.SyntaxException)

Aggregations

QueryOptions (org.apache.cassandra.cql3.QueryOptions)5 ByteBuffer (java.nio.ByteBuffer)3 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)3 ColumnSpecification (org.apache.cassandra.cql3.ColumnSpecification)2 UpdateParameters (org.apache.cassandra.cql3.UpdateParameters)2 Selection (org.apache.cassandra.cql3.selection.Selection)2 ParsedStatement (org.apache.cassandra.cql3.statements.ParsedStatement)2 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 java.util (java.util)1 List (java.util.List)1 UUID (java.util.UUID)1 ExecutionException (java.util.concurrent.ExecutionException)1 CQLStatement (org.apache.cassandra.cql3.CQLStatement)1 QueryHandler (org.apache.cassandra.cql3.QueryHandler)1 MultiItemTerminal (org.apache.cassandra.cql3.Term.MultiItemTerminal)1 Terminal (org.apache.cassandra.cql3.Term.Terminal)1 UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)1 Function (org.apache.cassandra.cql3.functions.Function)1