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();
}
}
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();
}
};
}
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();
}
}
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);
}
}
Aggregations