Class FieldKeyExpression
- java.lang.Object
-
- com.apple.foundationdb.record.metadata.expressions.BaseKeyExpression
-
- com.apple.foundationdb.record.metadata.expressions.FieldKeyExpression
-
- All Implemented Interfaces:
AtomKeyExpression
,KeyExpression
,KeyExpressionWithoutChildren
,PlanHashable
,QueryHashable
@API(MAINTAINED) public class FieldKeyExpression extends BaseKeyExpression implements AtomKeyExpression, KeyExpressionWithoutChildren
Take keys from a record field. IffieldName
is arepeated
field, thenFanType.Concatenate
turns all the field values into a singleKey.Evaluated
. IfFanType.FanOut
, there is one (singleton)Key.Evaluated
for each repeated value. If this is evaluated on thenull
record, then it will the same value as if it were evaluated on a record where the field is either unset (in the case of scalar fields) or empty (in the case of repeated fields). In particular, ifFanType.None
, then this returns a singleKey.Evaluated
containingnull
; ifFanType.FanOut
, then this returns noKey.Evaluated
s; and ifFanType.Concatenate
, then this returns a singleKey.Evaluated
containing the empty list.
-
-
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 FieldKeyExpression(RecordMetaDataProto.Field field)
FieldKeyExpression(String fieldName, KeyExpression.FanType fanType, Key.Evaluated.NullStandin nullStandin)
-
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.<S extends KeyExpressionVisitor.State>
GraphExpansionexpand(ExpansionVisitor<S> visitor)
Expand this key expression into a data flow graph.Quantifier
explodeField(CorrelationIdentifier baseAlias, List<String> fieldNamePrefix)
int
getColumnSize()
Returns the number of items in each KeyValue that will be returned.Descriptors.Descriptor
getDescriptor(Descriptors.Descriptor parentDescriptor)
KeyExpression.FanType
getFanType()
String
getFieldName()
Key.Evaluated.NullStandin
getNullStandin()
GroupingKeyExpression
groupBy(KeyExpression groupByFirst, KeyExpression... groupByRest)
int
hashCode()
NestingKeyExpression
nest(KeyExpression child)
Nest another expression inside this one.NestingKeyExpression
nest(KeyExpression first, KeyExpression second, KeyExpression... rest)
Shorthand fornest(concat(first, second, rest))
.NestingKeyExpression
nest(String fieldName)
Nest a single scalar field inside of this one.NestingKeyExpression
nest(String fieldName, KeyExpression.FanType fanType)
Nest a single field inside of this one, optionally setting the handling for a repeated 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.SplitKeyExpression
split(int splitSize)
RecordMetaDataProto.KeyExpression
toKeyExpression()
RecordMetaDataProto.Field
toProto()
String
toString()
GroupingKeyExpression
ungrouped()
Get this field as a group without any grouping keys.List<Descriptors.FieldDescriptor>
validate(Descriptors.Descriptor parentDescriptor)
Validate this expression against a given record type descriptor.List<Descriptors.FieldDescriptor>
validate(Descriptors.Descriptor parentDescriptor, boolean allowMessageType)
void
validate(Descriptors.Descriptor parentDescriptor, Descriptors.FieldDescriptor fieldDescriptor, boolean allowMessageType)
-
Methods inherited from class com.apple.foundationdb.record.metadata.expressions.BaseKeyExpression
getSubKey, getSubKeyImpl, 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, hasProperInterfaces, hasRecordTypeKey, isPrefixKey, normalizeKeyForPositions, versionColumns
-
Methods inherited from interface com.apple.foundationdb.record.PlanHashable
planHash
-
-
-
-
Constructor Detail
-
FieldKeyExpression
public FieldKeyExpression(@Nonnull String fieldName, @Nonnull KeyExpression.FanType fanType, @Nonnull Key.Evaluated.NullStandin nullStandin)
-
FieldKeyExpression
public FieldKeyExpression(@Nonnull RecordMetaDataProto.Field field) throws KeyExpression.DeserializationException
-
-
Method Detail
-
validate
public List<Descriptors.FieldDescriptor> validate(@Nonnull Descriptors.Descriptor parentDescriptor)
Description copied from interface:KeyExpression
Validate this expression against a given record type descriptor.- Specified by:
validate
in interfaceKeyExpression
- Parameters:
parentDescriptor
- the descriptor for the record type or submessage- Returns:
- a list of fields that this key applies to
-
validate
public List<Descriptors.FieldDescriptor> validate(@Nonnull Descriptors.Descriptor parentDescriptor, boolean allowMessageType)
-
validate
public void validate(@Nonnull Descriptors.Descriptor parentDescriptor, Descriptors.FieldDescriptor fieldDescriptor, boolean allowMessageType)
-
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
-
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.Field 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)
-
explodeField
@Nonnull public Quantifier explodeField(@Nonnull CorrelationIdentifier baseAlias, @Nonnull List<String> fieldNamePrefix)
-
nest
@Nonnull public NestingKeyExpression nest(@Nonnull String fieldName)
Nest a single scalar field inside of this one. Shorthand tonest(field(fieldName))
- Parameters:
fieldName
- the name of the nested field. This is contextual, there is no need to use the full path.- Returns:
- a new expression that will get the value from the value of the given field for each value of this field.
-
nest
@Nonnull public NestingKeyExpression nest(@Nonnull String fieldName, @Nonnull KeyExpression.FanType fanType)
Nest a single field inside of this one, optionally setting the handling for a repeated field. Shorthand tonest(field(fieldName, fanType))
- Parameters:
fieldName
- the name of the nested fieldfanType
- how to handle the nested field repeated state- Returns:
- a new key that will get all of the values from the value of the given field within this field
-
nest
@Nonnull public NestingKeyExpression nest(@Nonnull KeyExpression first, @Nonnull KeyExpression second, @Nonnull KeyExpression... rest)
Shorthand fornest(concat(first, second, rest))
.- Parameters:
first
- the first child expression to usesecond
- the second child expression to userest
- this supports any number children (at least 2), this is the rest of them- Returns:
- a new key that will get all of the values from the value of the given field within this field
-
nest
@Nonnull public NestingKeyExpression nest(@Nonnull KeyExpression child)
Nest another expression inside this one. That one will be evaluated for each value of this field in the context of this field. This field must be pointed to a Message. The child also has no access to the parts of the record outside of this field value. If this field is repeated with FanOut, there will be one index entry for each value of this field.- Parameters:
child
- a child expression to be evaluated on the message that this field has- Returns:
- a new expression for evaluating this complicated nesting
- Throws:
KeyExpression.InvalidExpressionException
- if this field is of concatenate type At least for now.
-
ungrouped
@Nonnull public GroupingKeyExpression ungrouped()
Get this field as a group without any grouping keys.- Returns:
- this field without any grouping keys
-
groupBy
@Nonnull public GroupingKeyExpression groupBy(@Nonnull KeyExpression groupByFirst, @Nonnull KeyExpression... groupByRest)
-
split
@Nonnull public SplitKeyExpression split(int splitSize)
-
getDescriptor
@Nonnull public Descriptors.Descriptor getDescriptor(@Nonnull Descriptors.Descriptor parentDescriptor)
-
getFanType
@Nonnull public KeyExpression.FanType getFanType()
-
getNullStandin
@Nonnull public Key.Evaluated.NullStandin getNullStandin()
-
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
-
equalsAtomic
public boolean equalsAtomic(AtomKeyExpression other)
- Specified by:
equalsAtomic
in interfaceAtomKeyExpression
-
-