private Map<ColumnIdentifier, Integer> getOrderingIndex(CFMetaData cfm, Selection selection) throws InvalidRequestException { // If we order post-query (see orderResults), the sorted column needs to be in the ResultSet for sorting, // even if we don't // ultimately ship them to the client (CASSANDRA-4911). Map<ColumnIdentifier, Integer> orderingIndexes = new HashMap<>(); for (ColumnDefinition.Raw raw : parameters.orderings.keySet()) { final ColumnDefinition def = raw.prepare(cfm); int index = selection.getResultSetIndex(def); if (index < 0) index = selection.addColumnForOrdering(def); orderingIndexes.put(def.name, index); } return orderingIndexes; }
public static Selection fromSelectors(CFMetaData cfm, List<RawSelector> rawSelectors, VariableSpecifications boundNames, boolean hasGroupBy) { List<ColumnDefinition> defs = new ArrayList<>(); SelectorFactories factories = SelectorFactories.createFactoriesAndCollectColumnDefinitions(RawSelector.toSelectables(rawSelectors, cfm), null, cfm, defs, boundNames); SelectionColumnMapping mapping = collectColumnMappings(cfm, rawSelectors, factories); return (processesSelection(rawSelectors) || rawSelectors.size() != defs.size() || hasGroupBy) ? new SelectionWithProcessing(cfm, defs, mapping, factories) : new SimpleSelection(cfm, defs, mapping, false); }
/** * Prepares the restrictions. * * @param cfm the column family meta data * @param boundNames the variable specifications * @param selection the selection * @return the restrictions * @throws InvalidRequestException if a problem occurs while building the restrictions */ private StatementRestrictions prepareRestrictions(CFMetaData cfm, VariableSpecifications boundNames, Selection selection, boolean forView) throws InvalidRequestException { return new StatementRestrictions(StatementType.SELECT, cfm, whereClause, boundNames, selection.containsOnlyStaticColumns(), selection.containsAComplexColumn(), parameters.allowFiltering, forView); }
/** * Prepares the selection to use for the statement. * * @param cfm the table metadata * @param boundNames the bound names * @return the selection to use for the statement */ private Selection prepareSelection(CFMetaData cfm, VariableSpecifications boundNames) { boolean hasGroupBy = !parameters.groups.isEmpty(); if (selectClause.isEmpty()) return hasGroupBy ? Selection.wildcardWithGroupBy(cfm, boundNames) : Selection.wildcard(cfm); return Selection.fromSelectors(cfm, selectClause, boundNames, hasGroupBy); }
private Map<ColumnDefinition, Integer> getOrderingIndex(CFMetaData cfm, Selection selection, boolean isJson) throws InvalidRequestException { // If we order post-query (see orderResults), the sorted column needs to be in the ResultSet for sorting, // even if we don't // ultimately ship them to the client (CASSANDRA-4911). for (ColumnDefinition.Raw raw : parameters.orderings.keySet()) { final ColumnDefinition def = raw.prepare(cfm); selection.addColumnForOrdering(def); } return selection.getOrderingIndex(isJson); }
/** * Checks if this selection contains only static columns. * @return <code>true</code> if this selection contains only static columns, <code>false</code> otherwise; */ public boolean containsOnlyStaticColumns() { if (!containsStaticColumns()) return false; if (isWildcard()) return false; for (ColumnDefinition def : getColumns()) { if (!def.isPartitionKey() && !def.isStatic()) return false; } return true; }
if (columnsWithConditions == null) selection = Selection.wildcard(cfm); selection = Selection.forColumns(cfm, new ArrayList<>(defs)); Selection.ResultSetBuilder builder = selection.resultSetBuilder(options, false); SelectStatement.forSelection(cfm, selection).processPartition(partition, options,
/** * Checks if this selection contains a complex column. * * @return <code>true</code> if this selection contains a multicell collection or UDT, <code>false</code> otherwise. */ public boolean containsAComplexColumn() { for (ColumnDefinition def : getColumns()) if (def.isComplex()) return true; return false; }
private ColumnFilter gatherQueriedColumns() { if (selection.isWildcard()) return ColumnFilter.all(cfm); ColumnFilter.Builder builder = ColumnFilter.allColumnsBuilder(cfm); // Adds all selected columns for (ColumnDefinition def : selection.getColumns()) if (!def.isPrimaryKeyColumn()) builder.add(def); // as well as any restricted column (so we can actually apply the restriction) builder.addAll(restrictions.nonPKRestrictedColumns(true)); return builder.build(); }
? Selection.wildcard(cfm) : Selection.fromSelectors(cfm, selectClause, boundNames, !parameters.groups.isEmpty());
/** * Returns the index of the specified column within the resultset * @param c the column * @return the index of the specified column within the resultset or -1 */ public int getResultSetIndex(ColumnDefinition c) { return getColumnIndex(c); }
private void addFunctionsTo(List<Function> functions) { selection.addFunctionsTo(functions); restrictions.addFunctionsTo(functions); if (limit != null) limit.addFunctionsTo(functions); if (perPartitionLimit != null) perPartitionLimit.addFunctionsTo(functions); }
if (slices == Slices.NONE && !selection.containsStaticColumns()) return null;
public static Selection wildcardWithGroupBy(CFMetaData cfm, VariableSpecifications boundNames) { List<RawSelector> rawSelectors = new ArrayList<>(cfm.allColumns().size()); Iterator<ColumnDefinition> iter = cfm.allColumnsInSelectOrder(); while (iter.hasNext()) { ColumnDefinition.Raw raw = ColumnDefinition.Raw.forColumn(iter.next()); rawSelectors.add(new RawSelector(raw, null)); } return fromSelectors(cfm, rawSelectors, boundNames, true); }
@Override public int addColumnForOrdering(ColumnDefinition c) { int index = super.addColumnForOrdering(c); factories.addSelectorForOrdering(c, index); return factories.size() - 1; }
/** * Checks if this selection contains only static columns. * @return <code>true</code> if this selection contains only static columns, <code>false</code> otherwise; */ public boolean containsOnlyStaticColumns() { if (!containsStaticColumns()) return false; if (isWildcard()) return false; for (ColumnDefinition def : getColumns()) { if (!def.isPartitionKey() && !def.isStatic()) return false; } return true; }
if (columnsWithConditions == null) selection = Selection.wildcard(cfm); selection = Selection.forColumns(cfm, new ArrayList<>(defs)); Selection.ResultSetBuilder builder = selection.resultSetBuilder(options, false); SelectStatement.forSelection(cfm, selection).processPartition(partition, options,
/** * Prepares the selection to use for the statement. * * @param cfm the table metadata * @param boundNames the bound names * @return the selection to use for the statement */ private Selection prepareSelection(CFMetaData cfm, VariableSpecifications boundNames) { boolean hasGroupBy = !parameters.groups.isEmpty(); if (selectClause.isEmpty()) return hasGroupBy ? Selection.wildcardWithGroupBy(cfm, boundNames) : Selection.wildcard(cfm); return Selection.fromSelectors(cfm, selectClause, boundNames, hasGroupBy); }
/** * Checks if this selection contains a complex column. * * @return <code>true</code> if this selection contains a multicell collection or UDT, <code>false</code> otherwise. */ public boolean containsAComplexColumn() { for (ColumnDefinition def : getColumns()) if (def.isComplex()) return true; return false; }
private ColumnFilter gatherQueriedColumns() { if (selection.isWildcard()) return ColumnFilter.all(cfm); ColumnFilter.Builder builder = ColumnFilter.allColumnsBuilder(cfm); // Adds all selected columns for (ColumnDefinition def : selection.getColumns()) if (!def.isPrimaryKeyColumn()) builder.add(def); // as well as any restricted column (so we can actually apply the restriction) builder.addAll(restrictions.nonPKRestrictedColumns(true)); return builder.build(); }