use of com.apple.foundationdb.record.metadata.RecordTypeBuilder in project fdb-record-layer by FoundationDB.
the class RecordMetaDataBuilder method updateRecordType.
private void updateRecordType(@Nonnull Map<String, RecordTypeBuilder> oldRecordTypes, @Nonnull Descriptors.Descriptor oldDescriptor, @Nonnull Descriptors.Descriptor newDescriptor) {
// Create a new record type based off the old one
RecordTypeBuilder oldRecordType = oldRecordTypes.get(oldDescriptor.getName());
RecordTypeBuilder newRecordType = new RecordTypeBuilder(newDescriptor, oldRecordType);
// update the record type builder
recordTypes.put(newRecordType.getName(), newRecordType);
}
use of com.apple.foundationdb.record.metadata.RecordTypeBuilder in project fdb-record-layer by FoundationDB.
the class RecordMetaDataBuilder method removeIndex.
public void removeIndex(@Nonnull String name) {
Index index = indexes.remove(name);
if (index == null) {
throw new MetaDataException("No index named " + name + " defined");
}
for (RecordTypeBuilder recordType : recordTypes.values()) {
recordType.getIndexes().remove(index);
recordType.getMultiTypeIndexes().remove(index);
}
universalIndexes.remove(name);
formerIndexes.add(new FormerIndex(index.getSubspaceKey(), index.getAddedVersion(), ++version, name));
}
use of com.apple.foundationdb.record.metadata.RecordTypeBuilder in project fdb-record-layer by FoundationDB.
the class RecordMetaDataBuilder method loadProtoExceptRecords.
@SuppressWarnings("deprecation")
private void loadProtoExceptRecords(@Nonnull RecordMetaDataProto.MetaData metaDataProto) {
for (RecordMetaDataProto.Index indexProto : metaDataProto.getIndexesList()) {
List<RecordTypeBuilder> recordTypeBuilders = new ArrayList<>(indexProto.getRecordTypeCount());
for (String recordTypeName : indexProto.getRecordTypeList()) {
recordTypeBuilders.add(getRecordType(recordTypeName));
}
try {
addMultiTypeIndex(recordTypeBuilders, new Index(indexProto));
} catch (KeyExpression.DeserializationException e) {
throw new MetaDataProtoDeserializationException(e);
}
}
for (RecordMetaDataProto.RecordType typeProto : metaDataProto.getRecordTypesList()) {
RecordTypeBuilder typeBuilder = getRecordType(typeProto.getName());
if (typeProto.hasPrimaryKey()) {
try {
typeBuilder.setPrimaryKey(KeyExpression.fromProto(typeProto.getPrimaryKey()));
} catch (KeyExpression.DeserializationException e) {
throw new MetaDataProtoDeserializationException(e);
}
}
if (typeProto.hasSinceVersion()) {
typeBuilder.setSinceVersion(typeProto.getSinceVersion());
}
if (typeProto.hasExplicitKey()) {
typeBuilder.setRecordTypeKey(LiteralKeyExpression.fromProtoValue(typeProto.getExplicitKey()));
}
}
if (metaDataProto.hasSplitLongRecords()) {
splitLongRecords = metaDataProto.getSplitLongRecords();
}
if (metaDataProto.hasStoreRecordVersions()) {
storeRecordVersions = metaDataProto.getStoreRecordVersions();
}
for (RecordMetaDataProto.FormerIndex formerIndex : metaDataProto.getFormerIndexesList()) {
formerIndexes.add(new FormerIndex(formerIndex));
}
if (metaDataProto.hasRecordCountKey()) {
try {
recordCountKey = KeyExpression.fromProto(metaDataProto.getRecordCountKey());
} catch (KeyExpression.DeserializationException e) {
throw new MetaDataProtoDeserializationException(e);
}
}
if (metaDataProto.hasVersion()) {
version = metaDataProto.getVersion();
}
for (RecordMetaDataProto.JoinedRecordType joinedProto : metaDataProto.getJoinedRecordTypesList()) {
JoinedRecordTypeBuilder typeBuilder = new JoinedRecordTypeBuilder(joinedProto, this);
syntheticRecordTypes.put(typeBuilder.getName(), typeBuilder);
}
}
use of com.apple.foundationdb.record.metadata.RecordTypeBuilder in project fdb-record-layer by FoundationDB.
the class RecordMetaDataBuilder method processRecordType.
@Nonnull
private RecordTypeBuilder processRecordType(@Nonnull Descriptors.FieldDescriptor unionField, boolean processExtensionOptions) {
Descriptors.Descriptor descriptor = unionField.getMessageType();
RecordTypeBuilder recordType = new RecordTypeBuilder(descriptor);
if (recordTypes.putIfAbsent(recordType.getName(), recordType) != null) {
throw new MetaDataException("There is already a record type named " + recordType.getName());
}
if (processExtensionOptions) {
RecordMetaDataOptionsProto.RecordTypeOptions recordTypeOptions = descriptor.getOptions().getExtension(RecordMetaDataOptionsProto.record);
if (recordTypeOptions != null && recordTypeOptions.hasSinceVersion()) {
recordType.setSinceVersion(recordTypeOptions.getSinceVersion());
}
if (recordTypeOptions != null && recordTypeOptions.hasRecordTypeKey()) {
recordType.setRecordTypeKey(LiteralKeyExpression.fromProto(recordTypeOptions.getRecordTypeKey()).getValue());
}
protoFieldOptions(recordType);
}
return recordType;
}
use of com.apple.foundationdb.record.metadata.RecordTypeBuilder in project fdb-record-layer by FoundationDB.
the class FDBInQueryTest method enumIn.
/**
* Verify that enum field indexes are used to implement IN clauses.
*/
@DualPlannerTest
void enumIn() throws Exception {
RecordMetaDataHook hook = metaData -> {
final RecordTypeBuilder type = metaData.getRecordType("MyShapeRecord");
metaData.addIndex(type, new Index("color", field("color")));
};
setupEnumShapes(hook);
final var redBlue = asList(TestRecordsEnumProto.MyShapeRecord.Color.RED, TestRecordsEnumProto.MyShapeRecord.Color.BLUE);
RecordQuery query = RecordQuery.newBuilder().setRecordType("MyShapeRecord").setFilter(Query.field("color").in(redBlue)).build();
// Index(color [EQUALS $__in_color__0]) WHERE __in_color__0 IN [RED, BLUE]
RecordQueryPlan plan = planner.plan(query);
if (planner instanceof RecordQueryPlanner) {
assertMatchesExactly(plan, descendantPlans(indexPlan().where(indexName("color"))));
assertFalse(plan.hasRecordScan(), "should not use record scan");
assertEquals(-520431454, plan.planHash(PlanHashable.PlanHashKind.LEGACY));
assertEquals(1447363737, plan.planHash(PlanHashable.PlanHashKind.FOR_CONTINUATION));
assertEquals(1442809521, plan.planHash(PlanHashable.PlanHashKind.STRUCTURAL_WITHOUT_LITERALS));
} else {
assertMatchesExactly(plan, fetchFromPartialRecordPlan(inValuesJoinPlan(coveringIndexPlan().where(indexPlanOf(indexPlan().where(indexName("color")).and(scanComparisons(equalities(exactly(anyParameterComparison()))))))).where(inValuesList(equalsObject(redBlue)))));
assertFalse(plan.hasRecordScan(), "should not use record scan");
assertEquals(1174038242, plan.planHash(PlanHashable.PlanHashKind.LEGACY));
assertEquals(-1089300981, plan.planHash(PlanHashable.PlanHashKind.FOR_CONTINUATION));
assertEquals(-1677589406, plan.planHash(PlanHashable.PlanHashKind.STRUCTURAL_WITHOUT_LITERALS));
}
try (FDBRecordContext context = openContext()) {
openEnumRecordStore(context, hook);
int i = 0;
try (RecordCursorIterator<FDBQueriedRecord<Message>> cursor = recordStore.executeQuery(plan).asIterator()) {
while (cursor.hasNext()) {
FDBQueriedRecord<Message> rec = cursor.next();
TestRecordsEnumProto.MyShapeRecord.Builder shapeRec = TestRecordsEnumProto.MyShapeRecord.newBuilder();
shapeRec.mergeFrom(Objects.requireNonNull(rec).getRecord());
assertThat(shapeRec.getColor(), is(oneOf(TestRecordsEnumProto.MyShapeRecord.Color.RED, TestRecordsEnumProto.MyShapeRecord.Color.BLUE)));
i++;
}
}
assertEquals(18, i);
TestHelpers.assertDiscardedNone(context);
}
}
Aggregations