Class RecordTypeKeyExpression
- java.lang.Object
-
- com.apple.foundationdb.record.metadata.expressions.BaseKeyExpression
-
- com.apple.foundationdb.record.metadata.expressions.RecordTypeKeyExpression
-
- All Implemented Interfaces:
AtomKeyExpression
,KeyExpression
,KeyExpressionWithoutChildren
,PlanHashable
@API(MAINTAINED) public class RecordTypeKeyExpression extends BaseKeyExpression implements AtomKeyExpression, KeyExpressionWithoutChildren
A key expression that indicates that a unique record type identifier should be contained within the key. The unique value can be specified explicitly or generated automatically from the corresponding field numbers in the union message descriptor. It is important that the unique identifiers are stable. A record type's identifier should never change. If it is automatically generated, that means that fields should never be removed / reused in the union message descriptor, but at most deprecated. In that way, the lowest numbered field for a given type will always be the same. If the record type key appears at the start of every primary key, the record extent is divided by type, as in other database systems.
-
-
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
-
-
Field Summary
Fields Modifier and Type Field Description static RecordTypeKeyExpression
RECORD_TYPE_KEY
static RecordMetaDataProto.KeyExpression
RECORD_TYPE_KEY_PROTO
-
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.int
getColumnSize()
Returns the number of items in each KeyValue that will be returned.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.int
planHash()
Return a hash similar tohashCode
, but with the additional guarantee that is is stable across JVMs.RecordMetaDataProto.KeyExpression
toKeyExpression()
RecordMetaDataProto.RecordTypeKey
toProto()
String
toString()
GroupingKeyExpression
ungrouped()
ARecordType
expression with no grouping keys (mostly for evaluating record functions).List<Descriptors.FieldDescriptor>
validate(Descriptors.Descriptor descriptor)
Validate this expression against a given record type descriptor.-
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, flattenForPlanner, getSubKey, hasProperInterfaces, isPrefixKey, normalizeKeyForPositions, versionColumns
-
-
-
-
Field Detail
-
RECORD_TYPE_KEY
public static final RecordTypeKeyExpression RECORD_TYPE_KEY
-
RECORD_TYPE_KEY_PROTO
public static final RecordMetaDataProto.KeyExpression RECORD_TYPE_KEY_PROTO
-
-
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
-
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
-
ungrouped
@Nonnull public GroupingKeyExpression ungrouped()
ARecordType
expression with no grouping keys (mostly for evaluating record functions).- Returns:
- a
GroupingKeyExpression
with no grouping keys
-
toProto
@Nonnull public RecordMetaDataProto.RecordTypeKey toProto() throws KeyExpression.SerializationException
- Specified by:
toProto
in interfaceKeyExpression
- Throws:
KeyExpression.SerializationException
-
toKeyExpression
@Nonnull public RecordMetaDataProto.KeyExpression toKeyExpression()
- Specified by:
toKeyExpression
in interfaceKeyExpression
-
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
-
planHash
public int planHash()
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
- Returns:
- a stable hash code
-
equalsAtomic
public boolean equalsAtomic(AtomKeyExpression other)
- Specified by:
equalsAtomic
in interfaceAtomKeyExpression
-
-