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