Class ListKeyExpression
- java.lang.Object
-
- com.apple.foundationdb.record.metadata.expressions.BaseKeyExpression
-
- com.apple.foundationdb.record.metadata.expressions.ListKeyExpression
-
- All Implemented Interfaces:
KeyExpression
,KeyExpressionWithChildren
,PlanHashable
,QueryHashable
@API(MAINTAINED) public class ListKeyExpression extends BaseKeyExpression implements KeyExpressionWithChildren
Combine keys from zero or more child keys.Form a cross-product similar to
ThenKeyExpression
, but producing lists containing each child's evaluation result rather than concatenating. When converted to aTuple
, the nth child corresponds totuple.getNestedTuple(n)
, which is less compact on disk but easier to find the child boundaries in.Consider the expressions
concat(field("child_1").nest(field("field_1")), field("child_2").nest(concat(field("field_1"), field("field_2")))
andconcat(field("child_1").nest(concat(field("field_1"), field("field_2"))), field("child_2").nest(field("field_1")))
. These might produce values like[[1.1, 2.1, 2.2]]
and[[1.1, 1.2, 2.1]]
, respectively. Recovering the first child's contribution means remembering it or at least itsKeyExpression.getColumnSize()
, to know where the boundary is.Contrast
list(field("child_1").nest(field("field_1")), field("child_2").nest(concat(field("field_1"), field("field_2")))
andlist(field("child_1").nest(concat(field("field_1"), field("field_2"))), field("child_2").nest(field("field_1")))
. These would produce[[[1.1], [2.1, 2.2]]]
and[[[1.1, 1.2], [2.1]]]
, respectively.
-
-
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
-
Nested classes/interfaces inherited from interface com.apple.foundationdb.record.QueryHashable
QueryHashable.QueryHashKind
-
-
Constructor Summary
Constructors Constructor Description ListKeyExpression(RecordMetaDataProto.List list)
ListKeyExpression(List<KeyExpression> exprs)
-
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)
<M extends Message>
List<Key.Evaluated>evaluateMessage(FDBRecord<M> record, Message message)
Evaluate this expression against a record or a Protobuf message.<S extends KeyExpressionVisitor.State>
GraphExpansionexpand(ExpansionVisitor<S> visitor)
Expand this key expression into a data flow graph.List<KeyExpression>
getChildren()
int
getColumnSize()
Returns the number of items in each KeyValue that will be returned.KeyExpression
getSubKeyImpl(int start, int end)
int
hashCode()
boolean
hasRecordTypeKey()
Check whether a key expression uses record type key in some way.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.int
queryHash(QueryHashable.QueryHashKind hashKind)
Return a hash similar tohashCode
, but with the additional guarantee that is is stable across JVMs.RecordMetaDataProto.KeyExpression
toKeyExpression()
RecordMetaDataProto.List
toProto()
String
toString()
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, getSubKey, hasLosslessNormalization, hasProperInterfaces, isPrefixKey
-
Methods inherited from interface com.apple.foundationdb.record.PlanHashable
planHash
-
-
-
-
Constructor Detail
-
ListKeyExpression
public ListKeyExpression(@Nonnull List<KeyExpression> exprs)
-
ListKeyExpression
public ListKeyExpression(@Nonnull RecordMetaDataProto.List list) 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()
Returns the number of items in each KeyValue that will be returned. Note that this is exactly the number of child expressions, rather than the sum of their sizes, because each one becomes a separate nested tuple.- Specified by:
getColumnSize
in interfaceKeyExpression
- Returns:
- the number of elements that will be produced for every key
-
toProto
@Nonnull public RecordMetaDataProto.List toProto() throws KeyExpression.SerializationException
- Specified by:
toProto
in interfaceKeyExpression
- Throws:
KeyExpression.SerializationException
-
toKeyExpression
@Nonnull public RecordMetaDataProto.KeyExpression toKeyExpression()
- Specified by:
toKeyExpression
in interfaceKeyExpression
-
expand
@Nonnull public <S extends KeyExpressionVisitor.State> GraphExpansion expand(@Nonnull ExpansionVisitor<S> visitor)
Description copied from interface:KeyExpression
Expand this key expression into a data flow graph. The returned graph represents an adequate representation of the key expression as composition of relational expressions and operators (RelationalExpression
s). Note that implementors should defer to the visitation methods in the supplied visitor rather than encoding actual logic in an overriding method.- Specified by:
expand
in interfaceKeyExpression
- Type Parameters:
S
- a type that reflects the state thatvisitor
uses- Parameters:
visitor
- aExpansionVisitor
that is created by the caller from a data structure that reflects the specific semantics of the key expression. Normally this visitor is directly created based on an index.- Returns:
- a new
GraphExpansion
representing the query graph equivalent of this key expression using the supplied visitor - See Also:
QueryComponent.expand(com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier)
-
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
-
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
-
getChildren
@Nonnull public List<KeyExpression> getChildren()
- Specified by:
getChildren
in interfaceKeyExpressionWithChildren
-
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
-
queryHash
public int queryHash(@Nonnull QueryHashable.QueryHashKind hashKind)
Description copied from interface:QueryHashable
Return a hash similar tohashCode
, but with the additional guarantee that is is stable across JVMs.- Specified by:
queryHash
in interfaceQueryHashable
- 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
-
-