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