Class NestingKeyExpression
- java.lang.Object
-
- com.apple.foundationdb.record.metadata.expressions.BaseKeyExpression
-
- com.apple.foundationdb.record.metadata.expressions.NestingKeyExpression
-
- All Implemented Interfaces:
AtomKeyExpression
,KeyExpression
,KeyExpressionWithChild
,KeyExpressionWithChildren
,PlanHashable
@API(MAINTAINED) public class NestingKeyExpression extends BaseKeyExpression implements KeyExpressionWithChild, AtomKeyExpression
A key expression within a nested subrecord. If the parent field is repeated, then the parent field must have fan typeFanType.FanOut
. In that case, this will return the nested expression evaluated against every subrecord (possibly returning noKey.Evaluated
s if the parent field is empty). If the parent field is not repeated and not set, then this will evaluate the nested expression on thenull
record. This should return the same result as if the field were set to the empty message. If this expression is evaluated on thenull
record, then it will evaluate the same as if the parent field is unset or empty (depending on the fan type).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.apple.foundationdb.record.metadata.expressions.BaseKeyExpression
BaseKeyExpression.IllegalSubKeyException, BaseKeyExpression.UnsplittableKeyExpressionException
-
Nested classes/interfaces inherited from interface com.apple.foundationdb.record.metadata.expressions.KeyExpression
KeyExpression.DeserializationException, KeyExpression.FanType, KeyExpression.InvalidExpressionException, KeyExpression.InvalidResultException, KeyExpression.NoSuchArgumentException, KeyExpression.SerializationException
-
Nested classes/interfaces inherited from interface com.apple.foundationdb.record.PlanHashable
PlanHashable.PlanHashKind
-
-
Constructor Summary
Constructors Constructor Description NestingKeyExpression(FieldKeyExpression parent, KeyExpression child)
NestingKeyExpression(RecordMetaDataProto.Nesting nesting)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
createsDuplicates()
This states whether the given expression type is capable of evaluating more to more than one value when applied to a single record.boolean
equals(Object o)
boolean
equalsAtomic(AtomKeyExpression other)
<M extends Message>
List<Key.Evaluated>evaluateMessage(FDBRecord<M> record, Message message)
Evaluate this expression against a record or a Protobuf message.KeyExpression
getChild()
int
getColumnSize()
Returns the number of items in each KeyValue that will be returned.FieldKeyExpression
getParent()
KeyExpression
getSubKeyImpl(int start, int end)
GroupingKeyExpression
groupBy(KeyExpression groupByFirst, KeyExpression... groupByRest)
int
hashCode()
boolean
hasRecordTypeKey()
Check whether a key expression uses record type key in some way.KeyExpression
normalizeForPlanner(Source source, List<String> fieldNamePrefix)
Normalize this key expression into another key expression that pushes all nesting and fan-out toElementKeyExpression
s at the leaves.List<KeyExpression>
normalizeKeyForPositions()
Get key in normalized form for comparing field-by-field.int
planHash(PlanHashable.PlanHashKind hashKind)
Return a hash similar tohashCode
, but with the additional guarantee that is is stable across JVMs.RecordMetaDataProto.KeyExpression
toKeyExpression()
RecordMetaDataProto.Nesting
toProto()
String
toString()
GroupingKeyExpression
ungrouped()
Get this nesting as a group without any grouping keys.List<Descriptors.FieldDescriptor>
validate(Descriptors.Descriptor descriptor)
Validate this expression against a given record type descriptor.int
versionColumns()
Returns the number of version columns produced by this key expression.-
Methods inherited from class com.apple.foundationdb.record.metadata.expressions.BaseKeyExpression
getSubKey, isPrefixKey
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.apple.foundationdb.record.metadata.expressions.KeyExpression
evaluate, evaluateSingleton, flattenForPlanner, getSubKey, hasProperInterfaces, isPrefixKey
-
Methods inherited from interface com.apple.foundationdb.record.metadata.expressions.KeyExpressionWithChild
getChildren
-
Methods inherited from interface com.apple.foundationdb.record.PlanHashable
planHash
-
-
-
-
Constructor Detail
-
NestingKeyExpression
public NestingKeyExpression(@Nonnull FieldKeyExpression parent, @Nonnull KeyExpression child)
-
NestingKeyExpression
public NestingKeyExpression(@Nonnull RecordMetaDataProto.Nesting nesting) throws KeyExpression.DeserializationException
-
-
Method Detail
-
evaluateMessage
@Nonnull public <M extends Message> List<Key.Evaluated> evaluateMessage(@Nullable FDBRecord<M> record, @Nullable Message message)
Description copied from interface:KeyExpression
Evaluate this expression against a record or a Protobuf message. The message might be the Protobuf form of a record or a piece of that record. If the key expression is meaningful against a subrecord, it should evaluate against the message. Otherwise, it should evaluate against the record and ignore what part of that record is being considered. There should not be any reason to call this method outside of the implementation of anotherevaluateMessage
. Under ordinary circumstances, ifrecord
isnull
, thenmessage
will benull
. Otherwise,message
will berecord.getRecord()
or some submessage of that, possiblynull
if the corresponding field is missing.- Specified by:
evaluateMessage
in interfaceKeyExpression
- Type Parameters:
M
- the type of record- Parameters:
record
- the recordmessage
- the Protobuf message to evaluate against- Returns:
- the evaluated keys for the given record
- See Also:
KeyExpression.evaluate(com.apple.foundationdb.record.provider.foundationdb.FDBRecord<M>)
-
createsDuplicates
public boolean createsDuplicates()
Description copied from interface:KeyExpression
This states whether the given expression type is capable of evaluating more to more than one value when applied to a single record. In practice, this can happen if this expression is evaluated on a repeated field withFanType.FanOut
set (either directly or indirectly).- Specified by:
createsDuplicates
in interfaceKeyExpression
- Returns:
true
if this expression can evaluate to multiple values andfalse
otherwise
-
validate
public List<Descriptors.FieldDescriptor> validate(@Nonnull Descriptors.Descriptor descriptor)
Description copied from interface:KeyExpression
Validate this expression against a given record type descriptor.- Specified by:
validate
in interfaceKeyExpression
- Parameters:
descriptor
- the descriptor for the record type or submessage- Returns:
- a list of fields that this key applies to
-
getColumnSize
public int getColumnSize()
Description copied from interface:KeyExpression
Returns the number of items in each KeyValue that will be returned. For key expressions that supportKeyExpression.FanType.Concatenate
, this will the count of non-nested lists, i.e. this will be value of evaluate(r).get(i).toList().size() for any i or r.- Specified by:
getColumnSize
in interfaceKeyExpression
- Returns:
- the number of elements that will be produced for every key
-
toProto
@Nonnull public RecordMetaDataProto.Nesting toProto() throws KeyExpression.SerializationException
- Specified by:
toProto
in interfaceKeyExpression
- Throws:
KeyExpression.SerializationException
-
toKeyExpression
@Nonnull public RecordMetaDataProto.KeyExpression toKeyExpression()
- Specified by:
toKeyExpression
in interfaceKeyExpression
-
normalizeKeyForPositions
@Nonnull public List<KeyExpression> normalizeKeyForPositions()
Description copied from interface:KeyExpression
Get key in normalized form for comparing field-by-field. Does not take account of fan-type, so only valid when this has already been taken care of, such as individual index entries.- Specified by:
normalizeKeyForPositions
in interfaceKeyExpression
- Returns:
- a list of key expressions in order
-
normalizeForPlanner
@Nonnull public KeyExpression normalizeForPlanner(@Nonnull Source source, @Nonnull List<String> fieldNamePrefix)
Description copied from interface:KeyExpression
Normalize this key expression into another key expression that pushes all nesting and fan-out toElementKeyExpression
s at the leaves.By default, a key expression is a complicated nested structure that can be difficult to work with. This method pushes much of the complexity, including nested structures and fan-out of repeated fields, to special key expressions that track these relationship using the
Source
abstraction. This pre-processing makes planning nested and repeated structures much simpler.This normalization process requires tracking some state since the name of a nested field is available only at the relevant
FieldKeyExpression
, but that information is necessary to construct theElementKeyExpression
at the leaves of the sub-tree rooted at theNestingKeyExpression
. This extra information is tracked in thefieldNamePrefix
.- Specified by:
normalizeForPlanner
in interfaceKeyExpression
- Parameters:
source
- the source representing the input stream of the key expressionfieldNamePrefix
- the (non-repeated) field names on the path from the most recent source to this part of the key expression- Returns:
- a new key expression that has only
ElementKeyExpression
s at its leaves
-
versionColumns
public int versionColumns()
Description copied from interface:KeyExpression
Returns the number of version columns produced by this key expression.- Specified by:
versionColumns
in interfaceKeyExpression
- Returns:
- the number of version columns
-
hasRecordTypeKey
public boolean hasRecordTypeKey()
Description copied from interface:KeyExpression
Check whether a key expression uses record type key in some way.- Specified by:
hasRecordTypeKey
in interfaceKeyExpression
- Returns:
true
if record type key is used
-
getSubKeyImpl
public KeyExpression getSubKeyImpl(int start, int end)
- Overrides:
getSubKeyImpl
in classBaseKeyExpression
-
getParent
@Nonnull public FieldKeyExpression getParent()
-
getChild
@Nonnull public KeyExpression getChild()
- Specified by:
getChild
in interfaceKeyExpressionWithChild
-
ungrouped
@Nonnull public GroupingKeyExpression ungrouped()
Get this nesting as a group without any grouping keys.- Returns:
- this nesting without any grouping keys
-
groupBy
@Nonnull public GroupingKeyExpression groupBy(@Nonnull KeyExpression groupByFirst, @Nonnull KeyExpression... groupByRest)
-
planHash
public int planHash(@Nonnull PlanHashable.PlanHashKind hashKind)
Description copied from interface:PlanHashable
Return a hash similar tohashCode
, but with the additional guarantee that is is stable across JVMs.- Specified by:
planHash
in interfacePlanHashable
- Parameters:
hashKind
- the "kind" of hash to calculate. Each kind of hash has a particular logic with regards to included and excluded items.- Returns:
- a stable hash code
-
equalsAtomic
public boolean equalsAtomic(AtomKeyExpression other)
- Specified by:
equalsAtomic
in interfaceAtomKeyExpression
-
-