/** * Returns the bounds (start or end) of the clustering columns. * * @param b the bound type * @param options the query options * @return the bounds (start or end) of the clustering columns */ public NavigableSet<ClusteringBound> getClusteringColumnsBounds(Bound b, QueryOptions options) { return clusteringColumnsRestrictions.boundsAsClustering(b, options); }
/** * Returns the clustering columns that are not restricted. * @return the clustering columns that are not restricted. */ private Collection<ColumnIdentifier> getUnrestrictedClusteringColumns() { List<ColumnDefinition> missingClusteringColumns = new ArrayList<>(cfm.clusteringColumns()); missingClusteringColumns.removeAll(new LinkedList<>(clusteringColumnsRestrictions.getColumnDefs())); return ColumnDefinition.toIdentifiers(missingClusteringColumns); }
/** * Checks if restrictions on the clustering key have IN restrictions. * * @return <code>true</code> if the restrictions on the clustering key have IN restrictions, * <code>false</code> otherwise. */ public boolean clusteringKeyRestrictionsHasIN() { return clusteringColumnsRestrictions.hasIN(); }
/** * Checks if the query returns a range of columns. * * @return <code>true</code> if the query returns a range of columns, <code>false</code> otherwise. */ public boolean isColumnRange() { // For static compact tables we want to ignore the fake clustering column (note that if we weren't special casing, // this would mean a 'SELECT *' on a static compact table would query whole partitions, even though we'll only return // the static part as far as CQL is concerned. This is thus mostly an optimization to use the query-by-name path). int numberOfClusteringColumns = cfm.isStaticCompactTable() ? 0 : cfm.clusteringColumns().size(); // it is a range query if it has at least one the column alias for which no relation is defined or is not EQ or IN. return clusteringColumnsRestrictions.size() < numberOfClusteringColumns || !clusteringColumnsRestrictions.hasOnlyEqualityRestrictions(); }
boolean allowFiltering) checkFalse(!type.allowClusteringColumnSlices() && clusteringColumnsRestrictions.hasSlice(), "Slice restrictions are not supported on the clustering columns in %s statements", type); checkFalse(clusteringColumnsRestrictions.hasIN() && selectsComplexColumn, "Cannot restrict clustering columns by IN relations when a collection is selected by the query"); checkFalse(clusteringColumnsRestrictions.hasContains() && !hasQueriableIndex && !allowFiltering, "Clustering columns can only be restricted with CONTAINS with a secondary index or filtering"); if (hasClusteringColumnsRestrictions() && clusteringColumnsRestrictions.needFiltering()) List<ColumnDefinition> restrictedColumns = new LinkedList<>(clusteringColumnsRestrictions.getColumnDefs());
public NavigableSet<ClusteringBound> boundsAsClustering(Bound bound, QueryOptions options) throws InvalidRequestException { MultiCBuilder builder = MultiCBuilder.create(comparator, hasIN() || hasMultiColumnSlice()); int keyPosition = 0; for (SingleRestriction r : restrictions) { if (handleInFilter(r, keyPosition)) break; if (r.isSlice()) { r.appendBoundTo(builder, bound, options); return builder.buildBoundForSlice(bound.isStart(), r.isInclusive(bound), r.isInclusive(bound.reverse()), r.getColumnDefs()); } r.appendBoundTo(builder, bound, options); if (builder.hasMissingElements()) return BTreeSet.empty(comparator); keyPosition = r.getLastColumn().position() + 1; } // Everything was an equal (or there was nothing) return builder.buildBound(bound.isStart(), true); }
/** * Checks if underlying restrictions would require filtering * * @return <code>true</code> if any underlying restrictions require filtering, <code>false</code> * otherwise */ public final boolean needFiltering() { int position = 0; for (SingleRestriction restriction : restrictions) { if (handleInFilter(restriction, position)) return true; if (!restriction.isSlice()) position = restriction.getLastColumn().position() + 1; } return hasContains(); }
public ClusteringColumnRestrictions mergeWith(Restriction restriction) throws InvalidRequestException { SingleRestriction newRestriction = (SingleRestriction) restriction; RestrictionSet newRestrictionSet = restrictions.addRestriction(newRestriction); if (!isEmpty() && !allowFiltering) { SingleRestriction lastRestriction = restrictions.lastRestriction(); ColumnDefinition lastRestrictionStart = lastRestriction.getFirstColumn(); ColumnDefinition newRestrictionStart = restriction.getFirstColumn(); checkFalse(lastRestriction.isSlice() && newRestrictionStart.position() > lastRestrictionStart.position(), "Clustering column \"%s\" cannot be restricted (preceding column \"%s\" is restricted by a non-EQ relation)", newRestrictionStart.name, lastRestrictionStart.name); if (newRestrictionStart.position() < lastRestrictionStart.position() && newRestriction.isSlice()) throw invalidRequest("PRIMARY KEY column \"%s\" cannot be restricted (preceding column \"%s\" is restricted by a non-EQ relation)", restrictions.nextColumn(newRestrictionStart).name, newRestrictionStart.name); } return new ClusteringColumnRestrictions(this.comparator, newRestrictionSet, allowFiltering); }
public void addFunctionsTo(List<Function> functions) { partitionKeyRestrictions.addFunctionsTo(functions); clusteringColumnsRestrictions.addFunctionsTo(functions); nonPrimaryKeyRestrictions.addFunctionsTo(functions); }
private StatementRestrictions(StatementType type, CFMetaData cfm, boolean allowFiltering) { this.type = type; this.cfm = cfm; this.partitionKeyRestrictions = new PartitionKeySingleRestrictionSet(cfm.getKeyValidatorAsClusteringComparator()); this.clusteringColumnsRestrictions = new ClusteringColumnRestrictions(cfm, allowFiltering); this.nonPrimaryKeyRestrictions = new RestrictionSet(); this.notNullColumns = new HashSet<>(); }
/** * Checks that all the primary key columns (partition key and clustering columns) are restricted by an equality * relation ('=' or 'IN'). * * @return <code>true</code> if all the primary key columns are restricted by an equality relation. */ public boolean hasAllPKColumnsRestrictedByEqualities() { return !isPartitionKeyRestrictionsOnToken() && !partitionKeyRestrictions.hasUnrestrictedPartitionKeyComponents(cfm) && (partitionKeyRestrictions.hasOnlyEqualityRestrictions()) && !hasUnrestrictedClusteringColumns() && (clusteringColumnsRestrictions.hasOnlyEqualityRestrictions()); }
@Override public void addRowFilterTo(RowFilter filter, SecondaryIndexManager indexManager, QueryOptions options) throws InvalidRequestException { int position = 0; for (SingleRestriction restriction : restrictions) { // We ignore all the clustering columns that can be handled by slices. if (handleInFilter(restriction, position) || restriction.hasSupportingIndex(indexManager)) { restriction.addRowFilterTo(filter, indexManager, options); continue; } if (!restriction.isSlice()) position = restriction.getLastColumn().position() + 1; } }
boolean allowFiltering) checkFalse(!type.allowClusteringColumnSlices() && clusteringColumnsRestrictions.hasSlice(), "Slice restrictions are not supported on the clustering columns in %s statements", type); checkFalse(clusteringColumnsRestrictions.hasIN() && selectsComplexColumn, "Cannot restrict clustering columns by IN relations when a collection is selected by the query"); checkFalse(clusteringColumnsRestrictions.hasContains() && !hasQueriableIndex && !allowFiltering, "Clustering columns can only be restricted with CONTAINS with a secondary index or filtering"); if (hasClusteringColumnsRestrictions() && clusteringColumnsRestrictions.needFiltering()) List<ColumnDefinition> restrictedColumns = new LinkedList<>(clusteringColumnsRestrictions.getColumnDefs());
public NavigableSet<ClusteringBound> boundsAsClustering(Bound bound, QueryOptions options) throws InvalidRequestException { MultiCBuilder builder = MultiCBuilder.create(comparator, hasIN() || hasMultiColumnSlice()); int keyPosition = 0; for (SingleRestriction r : restrictions) { if (handleInFilter(r, keyPosition)) break; if (r.isSlice()) { r.appendBoundTo(builder, bound, options); return builder.buildBoundForSlice(bound.isStart(), r.isInclusive(bound), r.isInclusive(bound.reverse()), r.getColumnDefs()); } r.appendBoundTo(builder, bound, options); if (builder.hasMissingElements()) return BTreeSet.empty(comparator); keyPosition = r.getLastColumn().position() + 1; } // Everything was an equal (or there was nothing) return builder.buildBound(bound.isStart(), true); }
/** * Checks if the query returns a range of columns. * * @return <code>true</code> if the query returns a range of columns, <code>false</code> otherwise. */ public boolean isColumnRange() { // For static compact tables we want to ignore the fake clustering column (note that if we weren't special casing, // this would mean a 'SELECT *' on a static compact table would query whole partitions, even though we'll only return // the static part as far as CQL is concerned. This is thus mostly an optimization to use the query-by-name path). int numberOfClusteringColumns = cfm.isStaticCompactTable() ? 0 : cfm.clusteringColumns().size(); // it is a range query if it has at least one the column alias for which no relation is defined or is not EQ or IN. return clusteringColumnsRestrictions.size() < numberOfClusteringColumns || !clusteringColumnsRestrictions.hasOnlyEqualityRestrictions(); }
/** * Checks if underlying restrictions would require filtering * * @return <code>true</code> if any underlying restrictions require filtering, <code>false</code> * otherwise */ public final boolean needFiltering() { int position = 0; for (SingleRestriction restriction : restrictions) { if (handleInFilter(restriction, position)) return true; if (!restriction.isSlice()) position = restriction.getLastColumn().position() + 1; } return hasContains(); }
public ClusteringColumnRestrictions mergeWith(Restriction restriction) throws InvalidRequestException { SingleRestriction newRestriction = (SingleRestriction) restriction; RestrictionSet newRestrictionSet = restrictions.addRestriction(newRestriction); if (!isEmpty() && !allowFiltering) { SingleRestriction lastRestriction = restrictions.lastRestriction(); ColumnDefinition lastRestrictionStart = lastRestriction.getFirstColumn(); ColumnDefinition newRestrictionStart = restriction.getFirstColumn(); checkFalse(lastRestriction.isSlice() && newRestrictionStart.position() > lastRestrictionStart.position(), "Clustering column \"%s\" cannot be restricted (preceding column \"%s\" is restricted by a non-EQ relation)", newRestrictionStart.name, lastRestrictionStart.name); if (newRestrictionStart.position() < lastRestrictionStart.position() && newRestriction.isSlice()) throw invalidRequest("PRIMARY KEY column \"%s\" cannot be restricted (preceding column \"%s\" is restricted by a non-EQ relation)", restrictions.nextColumn(newRestrictionStart).name, newRestrictionStart.name); } return new ClusteringColumnRestrictions(this.comparator, newRestrictionSet, allowFiltering); }
public void addFunctionsTo(List<Function> functions) { partitionKeyRestrictions.addFunctionsTo(functions); clusteringColumnsRestrictions.addFunctionsTo(functions); nonPrimaryKeyRestrictions.addFunctionsTo(functions); }
private StatementRestrictions(StatementType type, CFMetaData cfm, boolean allowFiltering) { this.type = type; this.cfm = cfm; this.partitionKeyRestrictions = new PartitionKeySingleRestrictionSet(cfm.getKeyValidatorAsClusteringComparator()); this.clusteringColumnsRestrictions = new ClusteringColumnRestrictions(cfm, allowFiltering); this.nonPrimaryKeyRestrictions = new RestrictionSet(); this.notNullColumns = new HashSet<>(); }
/** * Checks that all the primary key columns (partition key and clustering columns) are restricted by an equality * relation ('=' or 'IN'). * * @return <code>true</code> if all the primary key columns are restricted by an equality relation. */ public boolean hasAllPKColumnsRestrictedByEqualities() { return !isPartitionKeyRestrictionsOnToken() && !partitionKeyRestrictions.hasUnrestrictedPartitionKeyComponents(cfm) && (partitionKeyRestrictions.hasOnlyEqualityRestrictions()) && !hasUnrestrictedClusteringColumns() && (clusteringColumnsRestrictions.hasOnlyEqualityRestrictions()); }