use of org.apache.cassandra.cql3.selection.Selector.Factory in project cassandra by apache.
the class SystemKeyspace method getViewBuildStatus.
public static Map<Range<Token>, Pair<Token, Long>> getViewBuildStatus(String ksname, String viewName) {
String req = "SELECT start_token, end_token, last_token, keys_built FROM system.%s WHERE keyspace_name = ? AND view_name = ?";
Token.TokenFactory factory = ViewBuildsInProgress.partitioner.getTokenFactory();
UntypedResultSet rs = executeInternal(format(req, VIEW_BUILDS_IN_PROGRESS), ksname, viewName);
if (rs == null || rs.isEmpty())
return Collections.emptyMap();
Map<Range<Token>, Pair<Token, Long>> status = new HashMap<>();
for (UntypedResultSet.Row row : rs) {
Token start = factory.fromString(row.getString("start_token"));
Token end = factory.fromString(row.getString("end_token"));
Range<Token> range = new Range<>(start, end);
Token lastToken = row.has("last_token") ? factory.fromString(row.getString("last_token")) : null;
long keysBuilt = row.has("keys_built") ? row.getLong("keys_built") : 0;
status.put(range, Pair.create(lastToken, keysBuilt));
}
return status;
}
use of org.apache.cassandra.cql3.selection.Selector.Factory in project cassandra by apache.
the class ElementsSelector method newSliceFactory.
/**
* Creates a {@code Selector.Factory} for the selection of a slice of a collection.
*
* @param name a string representing the selection the factory is for. Something like "c[x..y]".
* @param factory the {@code Selector.Factory} corresponding to the collection on which a slice
* is selected.
* @param type the type of the collection.
* @param from the starting bound of the selected slice. This cannot be {@code null} but can be
* {@code Constants.UNSET_VALUE} if the slice doesn't have a start.
* @param to the ending bound of the selected slice. This cannot be {@code null} but can be
* {@code Constants.UNSET_VALUE} if the slice doesn't have an end.
* @return the created factory.
*/
public static Factory newSliceFactory(String name, Selector.Factory factory, CollectionType<?> type, final Term from, final Term to) {
return new AbstractFactory(name, factory, type) {
protected AbstractType<?> getReturnType() {
return type;
}
public Selector newInstance(QueryOptions options) throws InvalidRequestException {
ByteBuffer fromValue = from.bindAndGet(options);
ByteBuffer toValue = to.bindAndGet(options);
// Note that we use UNSET values to represent no bound, so null is truly invalid
if (fromValue == null || toValue == null)
throw new InvalidRequestException("Invalid null value for slice selection on " + factory.getColumnName());
return new SliceSelector(factory.newInstance(options), from.bindAndGet(options), to.bindAndGet(options));
}
public boolean areAllFetchedColumnsKnown() {
// 3) the bound of the selected slice are terminal.
return factory.areAllFetchedColumnsKnown() && (!type.isMultiCell() || !factory.isSimpleSelectorFactory() || (from.isTerminal() && to.isTerminal()));
}
public void addFetchedColumns(ColumnFilter.Builder builder) {
if (!type.isMultiCell() || !factory.isSimpleSelectorFactory()) {
factory.addFetchedColumns(builder);
return;
}
ColumnMetadata column = ((SimpleSelectorFactory) factory).getColumn();
ByteBuffer fromBB = ((Term.Terminal) from).get(ProtocolVersion.V3);
ByteBuffer toBB = ((Term.Terminal) to).get(ProtocolVersion.V3);
builder.slice(column, isUnset(fromBB) ? CellPath.BOTTOM : CellPath.create(fromBB), isUnset(toBB) ? CellPath.TOP : CellPath.create(toBB));
}
};
}
use of org.apache.cassandra.cql3.selection.Selector.Factory 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.selection.Selector.Factory 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.selection.Selector.Factory in project cassandra by apache.
the class ElementsSelector method newElementFactory.
/**
* Creates a {@code Selector.Factory} for the selection of an element of a collection.
*
* @param name a string representing the selection the factory is for. Something like "c[x]".
* @param factory the {@code Selector.Factory} corresponding to the collection on which an element
* is selected.
* @param type the type of the collection.
* @param key the element within the value represented by {@code factory} that is selected.
* @return the created factory.
*/
public static Factory newElementFactory(String name, Selector.Factory factory, CollectionType<?> type, final Term key) {
return new AbstractFactory(name, factory, type) {
protected AbstractType<?> getReturnType() {
return valueType(type);
}
public Selector newInstance(QueryOptions options) throws InvalidRequestException {
ByteBuffer keyValue = key.bindAndGet(options);
if (keyValue == null)
throw new InvalidRequestException("Invalid null value for element selection on " + factory.getColumnName());
if (keyValue == ByteBufferUtil.UNSET_BYTE_BUFFER)
throw new InvalidRequestException("Invalid unset value for element selection on " + factory.getColumnName());
return new ElementSelector(factory.newInstance(options), keyValue);
}
public boolean areAllFetchedColumnsKnown() {
// 3) the element selected is terminal.
return factory.areAllFetchedColumnsKnown() && (!type.isMultiCell() || !factory.isSimpleSelectorFactory() || key.isTerminal());
}
public void addFetchedColumns(ColumnFilter.Builder builder) {
if (!type.isMultiCell() || !factory.isSimpleSelectorFactory()) {
factory.addFetchedColumns(builder);
return;
}
ColumnMetadata column = ((SimpleSelectorFactory) factory).getColumn();
builder.select(column, CellPath.create(((Term.Terminal) key).get(ProtocolVersion.V3)));
}
};
}
Aggregations