@API(value=MAINTAINED) public class FieldKeyExpression extends BaseKeyExpression implements AtomKeyExpression, KeyExpressionWithoutChildren
fieldName
is a repeated
field, then FanType.Concatenate
turns all the
field values into a single Key.Evaluated
. If FanType.FanOut
, there is one (singleton)
Key.Evaluated
for each repeated value. If this is evaluated on the null
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, if FanType.None
, then this returns
a single Key.Evaluated
containing null
; if FanType.FanOut
, then
this returns no Key.Evaluated
s; and if FanType.Concatenate
, then this returns a single
Key.Evaluated
containing the empty list.BaseKeyExpression.IllegalSubKeyException, BaseKeyExpression.UnsplittableKeyExpressionException
KeyExpression.DeserializationException, KeyExpression.FanType, KeyExpression.InvalidExpressionException, KeyExpression.InvalidResultException, KeyExpression.NoSuchArgumentException, KeyExpression.SerializationException
Constructor and Description |
---|
FieldKeyExpression(RecordMetaDataProto.Field field) |
FieldKeyExpression(String fieldName,
KeyExpression.FanType fanType,
Key.Evaluated.NullStandin nullStandin) |
Modifier and Type | Method and 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> |
evaluateMessage(FDBRecord<M> record,
Message message)
Evaluate this expression against a record or a Protobuf message.
|
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 for
nest(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.
|
KeyExpression |
normalizeForPlanner(Source source,
List<String> fieldNamePrefix)
Normalize this key expression into another key expression that pushes all nesting and fan-out to
ElementKeyExpression s at the leaves. |
int |
planHash()
Return a hash similar to
hashCode , 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) |
getSubKey, getSubKeyImpl, isPrefixKey
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
evaluate, evaluateSingleton, flattenForPlanner, fromProto, getSubKey, hasProperInterfaces, hasRecordTypeKey, isPrefixKey, normalizeKeyForPositions, versionColumns
combineHashes, iterablePlanHash, objectPlanHash, objectsPlanHash, planHash, planHash, planHashUnordered, stringHashUnordered
public FieldKeyExpression(@Nonnull String fieldName, @Nonnull KeyExpression.FanType fanType, @Nonnull Key.Evaluated.NullStandin nullStandin)
public FieldKeyExpression(@Nonnull RecordMetaDataProto.Field field) throws KeyExpression.DeserializationException
public List<Descriptors.FieldDescriptor> validate(@Nonnull Descriptors.Descriptor parentDescriptor)
KeyExpression
validate
in interface KeyExpression
parentDescriptor
- the descriptor for the record type or submessagepublic List<Descriptors.FieldDescriptor> validate(@Nonnull Descriptors.Descriptor parentDescriptor, boolean allowMessageType)
public void validate(@Nonnull Descriptors.Descriptor parentDescriptor, Descriptors.FieldDescriptor fieldDescriptor, boolean allowMessageType)
@Nonnull public <M extends Message> List<Key.Evaluated> evaluateMessage(@Nullable FDBRecord<M> record, @Nullable Message message)
KeyExpression
evaluateMessage
.
Under ordinary circumstances, if record
is null
, then message
will be null
.
Otherwise, message
will be record.getRecord()
or some submessage of that, possibly null
if
the corresponding field is missing.evaluateMessage
in interface KeyExpression
M
- the type of recordrecord
- the recordmessage
- the Protobuf message to evaluate againstKeyExpression.evaluate(com.apple.foundationdb.record.provider.foundationdb.FDBRecord<M>)
public boolean createsDuplicates()
KeyExpression
FanType.FanOut
set (either directly
or indirectly).createsDuplicates
in interface KeyExpression
true
if this expression can evaluate to multiple values and false
otherwisepublic int getColumnSize()
KeyExpression
KeyExpression.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.getColumnSize
in interface KeyExpression
@Nonnull public RecordMetaDataProto.Field toProto() throws KeyExpression.SerializationException
toProto
in interface KeyExpression
KeyExpression.SerializationException
@Nonnull public RecordMetaDataProto.KeyExpression toKeyExpression()
toKeyExpression
in interface KeyExpression
@Nonnull public KeyExpression normalizeForPlanner(@Nonnull Source source, @Nonnull List<String> fieldNamePrefix)
KeyExpression
ElementKeyExpression
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 the
ElementKeyExpression
at the leaves of the sub-tree rooted at the NestingKeyExpression
. This
extra information is tracked in the fieldNamePrefix
.
normalizeForPlanner
in interface KeyExpression
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 expressionElementKeyExpression
s at its leaves@Nonnull public NestingKeyExpression nest(@Nonnull String fieldName)
nest(field(fieldName))
fieldName
- the name of the nested field. This is contextual, there is no need to use the full path.@Nonnull public NestingKeyExpression nest(@Nonnull String fieldName, @Nonnull KeyExpression.FanType fanType)
nest(field(fieldName, fanType))
fieldName
- the name of the nested fieldfanType
- how to handle the nested field repeated state@Nonnull public NestingKeyExpression nest(@Nonnull KeyExpression first, @Nonnull KeyExpression second, @Nonnull KeyExpression... rest)
nest(concat(first, second, rest))
.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@Nonnull public NestingKeyExpression nest(@Nonnull KeyExpression child)
child
- a child expression to be evaluated on the message that this field hasInvalidExpressionException
- if this field is of concatenate type
At least for now.@Nonnull public GroupingKeyExpression ungrouped()
@Nonnull public GroupingKeyExpression groupBy(@Nonnull KeyExpression groupByFirst, @Nonnull KeyExpression... groupByRest)
@Nonnull public SplitKeyExpression split(int splitSize)
@Nonnull public Descriptors.Descriptor getDescriptor(@Nonnull Descriptors.Descriptor parentDescriptor)
@Nonnull public KeyExpression.FanType getFanType()
@Nonnull public Key.Evaluated.NullStandin getNullStandin()
public int planHash()
PlanHashable
hashCode
, but with the additional guarantee that is is stable across JVMs.planHash
in interface PlanHashable
public boolean equalsAtomic(AtomKeyExpression other)
equalsAtomic
in interface AtomKeyExpression