Search in sources :

Example 6 with Selectors

use of org.apache.cassandra.cql3.selection.Selection.Selectors 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);
        }
    };
}
Also used : ColumnSpecification(org.apache.cassandra.cql3.ColumnSpecification) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) StrBuilder(org.apache.commons.lang3.text.StrBuilder) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) List(java.util.List) QueryOptions(org.apache.cassandra.cql3.QueryOptions)

Aggregations

Selectors (org.apache.cassandra.cql3.selection.Selection.Selectors)4 ResultSetBuilder (org.apache.cassandra.cql3.selection.ResultSetBuilder)2 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)2 AggregationQueryPager (org.apache.cassandra.service.pager.AggregationQueryPager)2 QueryPager (org.apache.cassandra.service.pager.QueryPager)2 List (java.util.List)1 ColumnSpecification (org.apache.cassandra.cql3.ColumnSpecification)1 QueryOptions (org.apache.cassandra.cql3.QueryOptions)1 Selection (org.apache.cassandra.cql3.selection.Selection)1 GroupMaker (org.apache.cassandra.db.aggregation.GroupMaker)1 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)1 RowIterator (org.apache.cassandra.db.rows.RowIterator)1 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)1 TableMetadata (org.apache.cassandra.schema.TableMetadata)1 StrBuilder (org.apache.commons.lang3.text.StrBuilder)1