@Override protected Restriction newEQRestriction(CFMetaData cfm, VariableSpecifications boundNames) throws InvalidRequestException { ColumnDefinition columnDef = entity.prepare(cfm); if (mapKey == null) { Term term = toTerm(toReceivers(columnDef), value, cfm.ksName, boundNames); return new SingleColumnRestriction.EQRestriction(columnDef, term); } List<? extends ColumnSpecification> receivers = toReceivers(columnDef); Term entryKey = toTerm(Collections.singletonList(receivers.get(0)), mapKey, cfm.ksName, boundNames); Term entryValue = toTerm(Collections.singletonList(receivers.get(1)), value, cfm.ksName, boundNames); return new SingleColumnRestriction.ContainsRestriction(columnDef, entryKey, entryValue); }
@Override public void addRowFilterTo(RowFilter filter, SecondaryIndexManager indexManager, QueryOptions options) { for (ByteBuffer value : bindAndGet(values, options)) filter.add(columnDef, Operator.CONTAINS, value); for (ByteBuffer key : bindAndGet(keys, options)) filter.add(columnDef, Operator.CONTAINS_KEY, key); List<ByteBuffer> eks = bindAndGet(entryKeys, options); List<ByteBuffer> evs = bindAndGet(entryValues, options); assert eks.size() == evs.size(); for (int i = 0; i < eks.size(); i++) filter.addMapEquality(columnDef, eks.get(i), Operator.EQ, evs.get(i)); }
/** * Checks if the restrictions contains multiple contains, contains key, or map[key] = value. * * @return <code>true</code> if the restrictions contains multiple contains, contains key, or , * map[key] = value; <code>false</code> otherwise */ public final boolean hasMultipleContains() { int numberOfContains = 0; for (SingleRestriction restriction : restrictions.values()) { if (restriction.isContains()) { ContainsRestriction contains = (ContainsRestriction) restriction; numberOfContains += (contains.numberOfValues() + contains.numberOfKeys() + contains.numberOfEntries()); } } return numberOfContains > 1; }
/** * Checks if the restrictions contains multiple contains, contains key, or map[key] = value. * * @return <code>true</code> if the restrictions contains multiple contains, contains key, or , * map[key] = value; <code>false</code> otherwise */ public final boolean hasMultipleContains() { int numberOfContains = 0; for (SingleRestriction restriction : restrictions.values()) { if (restriction.isContains()) { ContainsRestriction contains = (ContainsRestriction) restriction; numberOfContains += (contains.numberOfValues() + contains.numberOfKeys() + contains.numberOfEntries()); } } return numberOfContains > 1; }
/** * Checks if the restrictions contains multiple contains, contains key, or map[key] = value. * * @return <code>true</code> if the restrictions contains multiple contains, contains key, or , * map[key] = value; <code>false</code> otherwise */ public final boolean hasMultipleContains() { int numberOfContains = 0; for (SingleRestriction restriction : restrictions.values()) { if (restriction.isContains()) { ContainsRestriction contains = (ContainsRestriction) restriction; numberOfContains += (contains.numberOfValues() + contains.numberOfKeys() + contains.numberOfEntries()); } } return numberOfContains > 1; }
@Override protected Restriction newEQRestriction(CFMetaData cfm, VariableSpecifications boundNames) throws InvalidRequestException { ColumnDefinition columnDef = entity.prepare(cfm); if (mapKey == null) { Term term = toTerm(toReceivers(columnDef), value, cfm.ksName, boundNames); return new SingleColumnRestriction.EQRestriction(columnDef, term); } List<? extends ColumnSpecification> receivers = toReceivers(columnDef); Term entryKey = toTerm(Collections.singletonList(receivers.get(0)), mapKey, cfm.ksName, boundNames); Term entryValue = toTerm(Collections.singletonList(receivers.get(1)), value, cfm.ksName, boundNames); return new SingleColumnRestriction.ContainsRestriction(columnDef, entryKey, entryValue); }
@Override protected Restriction newEQRestriction(CFMetaData cfm, VariableSpecifications boundNames) throws InvalidRequestException { ColumnDefinition columnDef = entity.prepare(cfm); if (mapKey == null) { Term term = toTerm(toReceivers(columnDef), value, cfm.ksName, boundNames); return new SingleColumnRestriction.EQRestriction(columnDef, term); } List<? extends ColumnSpecification> receivers = toReceivers(columnDef); Term entryKey = toTerm(Collections.singletonList(receivers.get(0)), mapKey, cfm.ksName, boundNames); Term entryValue = toTerm(Collections.singletonList(receivers.get(1)), value, cfm.ksName, boundNames); return new SingleColumnRestriction.ContainsRestriction(columnDef, entryKey, entryValue); }
@Override public void addRowFilterTo(RowFilter filter, SecondaryIndexManager indexManager, QueryOptions options) { for (ByteBuffer value : bindAndGet(values, options)) filter.add(columnDef, Operator.CONTAINS, value); for (ByteBuffer key : bindAndGet(keys, options)) filter.add(columnDef, Operator.CONTAINS_KEY, key); List<ByteBuffer> eks = bindAndGet(entryKeys, options); List<ByteBuffer> evs = bindAndGet(entryValues, options); assert eks.size() == evs.size(); for (int i = 0; i < eks.size(); i++) filter.addMapEquality(columnDef, eks.get(i), Operator.EQ, evs.get(i)); }
@Override protected Restriction newContainsRestriction(CFMetaData cfm, VariableSpecifications boundNames, boolean isKey) throws InvalidRequestException { ColumnDefinition columnDef = entity.prepare(cfm); Term term = toTerm(toReceivers(columnDef), value, cfm.ksName, boundNames); return new SingleColumnRestriction.ContainsRestriction(columnDef, term, isKey); }
@Override public SingleRestriction doMergeWith(SingleRestriction otherRestriction) { checkTrue(otherRestriction.isContains(), "Collection column %s can only be restricted by CONTAINS, CONTAINS KEY, or map-entry equality", columnDef.name); SingleColumnRestriction.ContainsRestriction newContains = new ContainsRestriction(columnDef); copyKeysAndValues(this, newContains); copyKeysAndValues((ContainsRestriction) otherRestriction, newContains); return newContains; }
@Override protected Restriction newContainsRestriction(CFMetaData cfm, VariableSpecifications boundNames, boolean isKey) throws InvalidRequestException { ColumnDefinition columnDef = entity.prepare(cfm); Term term = toTerm(toReceivers(columnDef), value, cfm.ksName, boundNames); return new SingleColumnRestriction.ContainsRestriction(columnDef, term, isKey); }
@Override protected Restriction newContainsRestriction(CFMetaData cfm, VariableSpecifications boundNames, boolean isKey) throws InvalidRequestException { ColumnDefinition columnDef = entity.prepare(cfm); Term term = toTerm(toReceivers(columnDef), value, cfm.ksName, boundNames); return new SingleColumnRestriction.ContainsRestriction(columnDef, term, isKey); }
@Override protected boolean isSupportedBy(Index index) { boolean supported = false; if (numberOfValues() > 0) supported |= index.supportsExpression(columnDef, Operator.CONTAINS); if (numberOfKeys() > 0) supported |= index.supportsExpression(columnDef, Operator.CONTAINS_KEY); if (numberOfEntries() > 0) supported |= index.supportsExpression(columnDef, Operator.EQ); return supported; }
@Override public void addRowFilterTo(RowFilter filter, SecondaryIndexManager indexManager, QueryOptions options) { for (ByteBuffer value : bindAndGet(values, options)) filter.add(columnDef, Operator.CONTAINS, value); for (ByteBuffer key : bindAndGet(keys, options)) filter.add(columnDef, Operator.CONTAINS_KEY, key); List<ByteBuffer> eks = bindAndGet(entryKeys, options); List<ByteBuffer> evs = bindAndGet(entryValues, options); assert eks.size() == evs.size(); for (int i = 0; i < eks.size(); i++) filter.addMapEquality(columnDef, eks.get(i), Operator.EQ, evs.get(i)); }
@Override public SingleRestriction doMergeWith(SingleRestriction otherRestriction) { checkTrue(otherRestriction.isContains(), "Collection column %s can only be restricted by CONTAINS, CONTAINS KEY, or map-entry equality", columnDef.name); SingleColumnRestriction.ContainsRestriction newContains = new ContainsRestriction(columnDef); copyKeysAndValues(this, newContains); copyKeysAndValues((ContainsRestriction) otherRestriction, newContains); return newContains; }
@Override public SingleRestriction doMergeWith(SingleRestriction otherRestriction) { checkTrue(otherRestriction.isContains(), "Collection column %s can only be restricted by CONTAINS, CONTAINS KEY, or map-entry equality", columnDef.name); SingleColumnRestriction.ContainsRestriction newContains = new ContainsRestriction(columnDef); copyKeysAndValues(this, newContains); copyKeysAndValues((ContainsRestriction) otherRestriction, newContains); return newContains; }
@Override protected boolean isSupportedBy(Index index) { boolean supported = false; if (numberOfValues() > 0) supported |= index.supportsExpression(columnDef, Operator.CONTAINS); if (numberOfKeys() > 0) supported |= index.supportsExpression(columnDef, Operator.CONTAINS_KEY); if (numberOfEntries() > 0) supported |= index.supportsExpression(columnDef, Operator.EQ); return supported; }
@Override protected boolean isSupportedBy(Index index) { boolean supported = false; if (numberOfValues() > 0) supported |= index.supportsExpression(columnDef, Operator.CONTAINS); if (numberOfKeys() > 0) supported |= index.supportsExpression(columnDef, Operator.CONTAINS_KEY); if (numberOfEntries() > 0) supported |= index.supportsExpression(columnDef, Operator.EQ); return supported; }