Search in sources :

Example 71 with RecordMetaDataBuilder

use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.

the class MetaDataEvolutionValidatorTest method changeFormerIndexName.

@Test
public void changeFormerIndexName() {
    RecordMetaDataBuilder metaData1Builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    metaData1Builder.removeIndex("MySimpleRecord$str_value_indexed");
    RecordMetaData metaData1 = metaData1Builder.getRecordMetaData();
    RecordMetaDataProto.MetaData.Builder metaData2ProtoBuilder = metaData1.toProto().toBuilder().setVersion(metaData1.getVersion() + 1);
    metaData2ProtoBuilder.setFormerIndexes(0, metaData2ProtoBuilder.getFormerIndexesBuilder(0).setFormerName("some_other_name"));
    RecordMetaData metaData2 = RecordMetaData.build(metaData2ProtoBuilder.build());
    assertInvalid("name of former index differs from prior version", metaData1, metaData2);
    metaData2ProtoBuilder.setFormerIndexes(0, metaData2ProtoBuilder.getFormerIndexesBuilder(0).clearFormerName());
    metaData2 = RecordMetaData.build(metaData2ProtoBuilder.build());
    assertInvalid("name of former index differs from prior version", metaData1, metaData2);
    // For existing former indexes, changing the name is not allowed even with the laxer validation option
    MetaDataEvolutionValidator laxerValidator = MetaDataEvolutionValidator.newBuilder().setAllowMissingFormerIndexNames(true).build();
    assertInvalid("name of former index differs from prior version", laxerValidator, metaData1, metaData2);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) RecordMetaData(com.apple.foundationdb.record.RecordMetaData) Test(org.junit.jupiter.api.Test)

Example 72 with RecordMetaDataBuilder

use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.

the class MetaDataProtoTest method metadataProtoSimple.

@Test
public void metadataProtoSimple() throws KeyExpression.DeserializationException, KeyExpression.SerializationException {
    List<Descriptors.FileDescriptor> files = Arrays.asList(TestRecords1Proto.getDescriptor(), TestRecords2Proto.getDescriptor(), TestRecords4Proto.getDescriptor(), TestRecords5Proto.getDescriptor(), TestRecords6Proto.getDescriptor(), TestRecords7Proto.getDescriptor(), TestRecordsChained1Proto.getDescriptor(), TestRecordsChained2Proto.getDescriptor(), TestRecordsImportProto.getDescriptor(), TestRecordsImportFlatProto.getDescriptor(), TestRecordsMultiProto.getDescriptor(), TestRecordsParentChildRelationshipProto.getDescriptor(), TestRecordsWithUnionProto.getDescriptor(), TestRecordsIndexCompatProto.getDescriptor());
    for (int i = 0; i < files.size(); i++) {
        Descriptors.FileDescriptor file = files.get(i);
        RecordMetaData metaData = RecordMetaData.build(file);
        RecordMetaDataBuilder builder = RecordMetaData.newBuilder();
        builder.addDependencies(BASE_DEPENDENCIES);
        RecordMetaData metaDataRedone = builder.setRecords(metaData.toProto()).getRecordMetaData();
        verifyEquals(metaData, metaDataRedone);
    }
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Descriptors(com.google.protobuf.Descriptors) Test(org.junit.jupiter.api.Test)

Example 73 with RecordMetaDataBuilder

use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.

the class FDBRecordStorePerformanceTest method createMetaData.

public void createMetaData() {
    FDBDatabaseFactory factory = FDBDatabaseFactory.instance();
    factory.setDirectoryCacheSize(databaseParameters.pathCache);
    fdb = factory.getDatabase();
    RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    metaDataBuilder.setSplitLongRecords(databaseParameters.splitRecords);
    if (databaseParameters.stringSize > 100) {
        metaDataBuilder.removeIndex("MySimpleRecord$str_value_indexed");
    }
    if (databaseParameters.rankIndex) {
        metaDataBuilder.removeIndex("MySimpleRecord$num_value_unique");
        metaDataBuilder.addIndex("MySimpleRecord", new Index("num_value_unique_rank", Key.Expressions.field("num_value_unique").ungrouped(), EmptyKeyExpression.EMPTY, IndexTypes.RANK, Collections.emptyMap()));
    }
    metaData = metaDataBuilder.getRecordMetaData();
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Index(com.apple.foundationdb.record.metadata.Index)

Example 74 with RecordMetaDataBuilder

use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.

the class FDBRecordStoreTestBase method openNewUnionRecordStore.

@Nonnull
protected FDBRecordStore openNewUnionRecordStore(FDBRecordContext context) {
    RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecordsWithUnionProto.getDescriptor());
    metaDataBuilder.addUniversalIndex(new Index("versions", field("etag")));
    metaDataBuilder.addMultiTypeIndex(// partial_versions explicitly does not include MySimpleRecord3
    Arrays.asList(metaDataBuilder.getRecordType("MySimpleRecord"), metaDataBuilder.getRecordType("MySimpleRecord2")), new Index("partial_versions", field("etag")));
    metaDataBuilder.addUniversalIndex(new Index("cross_versions", field("nested").nest("etag")));
    metaDataBuilder.addMultiTypeIndex(Arrays.asList(metaDataBuilder.getRecordType("MySimpleRecord"), metaDataBuilder.getRecordType("MySimpleRecord2"), metaDataBuilder.getRecordType("MySimpleRecord3")), new Index("partial_nested_versions", concat(field("nested").nest(field("etag")), field("etag"))));
    createOrOpenRecordStore(context, metaDataBuilder.getRecordMetaData());
    return recordStore;
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Index(com.apple.foundationdb.record.metadata.Index) Nonnull(javax.annotation.Nonnull)

Example 75 with RecordMetaDataBuilder

use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.

the class MetaDataEvolutionValidatorTest method removeFormerIndex.

// Former index tests
@Test
public void removeFormerIndex() {
    RecordMetaDataBuilder metaData1Builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    metaData1Builder.removeIndex("MySimpleRecord$str_value_indexed");
    RecordMetaData metaData1 = metaData1Builder.getRecordMetaData();
    RecordMetaData metaData2 = RecordMetaData.build(metaData1.toProto().toBuilder().setVersion(metaData1.getVersion() + 1).clearFormerIndexes().build());
    assertInvalid("former index removed", metaData1, metaData2);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

RecordMetaDataBuilder (com.apple.foundationdb.record.RecordMetaDataBuilder)150 Test (org.junit.jupiter.api.Test)91 RecordMetaData (com.apple.foundationdb.record.RecordMetaData)69 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 Nonnull (javax.annotation.Nonnull)22 Index (com.apple.foundationdb.record.metadata.Index)21 Descriptors (com.google.protobuf.Descriptors)15 TestRecords1Proto (com.apple.foundationdb.record.TestRecords1Proto)14 KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)14 RecordMetaDataProto (com.apple.foundationdb.record.RecordMetaDataProto)13 ByteString (com.google.protobuf.ByteString)13 Tuple (com.apple.foundationdb.tuple.Tuple)12 Collections (java.util.Collections)12 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)11 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)11 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)11 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)11 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)11 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)10 BooleanSource (com.apple.test.BooleanSource)10