Search in sources :

Example 1 with IndexDefinition

use of com.palantir.atlasdb.table.description.IndexDefinition in project atlasdb by palantir.

the class IndexTestSchema method generateSchema.

// Table/IndexDefinition syntax
@SuppressWarnings({ "checkstyle:Indentation", "checkstyle:RightCurly" })
private static Schema generateSchema() {
    Schema schema = new Schema("IndexTest", IndexTest.class.getPackage().getName() + ".generated", Namespace.DEFAULT_NAMESPACE, OptionalType.JAVA8);
    schema.addTableDefinition("data", new TableDefinition() {

        {
            rowName();
            rowComponent("id", ValueType.FIXED_LONG);
            columns();
            column("value", "v", ValueType.FIXED_LONG);
        }
    });
    schema.addIndexDefinition("index1", new IndexDefinition(IndexType.CELL_REFERENCING) {

        {
            onTable("data");
            rowName();
            componentFromColumn("value", ValueType.FIXED_LONG, "value", "_value");
            dynamicColumns();
            componentFromRow("id", ValueType.FIXED_LONG);
            rangeScanAllowed();
        }
    });
    schema.addIndexDefinition("index2", new IndexDefinition(IndexType.CELL_REFERENCING) {

        {
            onTable("data");
            rowName();
            componentFromColumn("value", ValueType.FIXED_LONG, "value", "_value");
            componentFromRow("id", ValueType.FIXED_LONG);
            rangeScanAllowed();
        }
    });
    schema.addIndexDefinition("index3", new IndexDefinition(IndexType.CELL_REFERENCING) {

        {
            onTable("data");
            rowName();
            componentFromIterableColumn("value", ValueType.FIXED_LONG, ValueByteOrder.ASCENDING, "value", "ImmutableList.of(_value)");
            rangeScanAllowed();
        }
    });
    schema.addIndexDefinition("index4", new IndexDefinition(IndexType.CELL_REFERENCING) {

        {
            onTable("data");
            rowName();
            componentFromIterableColumn("value1", ValueType.FIXED_LONG, ValueByteOrder.ASCENDING, "value", "ImmutableList.of(_value)");
            componentFromIterableColumn("value2", ValueType.FIXED_LONG, ValueByteOrder.ASCENDING, "value", "ImmutableList.of(_value)");
            rangeScanAllowed();
        }
    });
    schema.addTableDefinition("two_columns", new TableDefinition() {

        {
            rowName();
            rowComponent("id", ValueType.FIXED_LONG);
            columns();
            column("foo", "f", ValueType.FIXED_LONG);
            column("bar", "b", ValueType.FIXED_LONG);
        }
    });
    schema.addIndexDefinition("foo_to_id", new IndexDefinition(IndexType.CELL_REFERENCING) {

        {
            onTable("two_columns");
            rowName();
            hashFirstRowComponent();
            componentFromColumn("foo", ValueType.FIXED_LONG, "foo", "_value");
            dynamicColumns();
            componentFromRow("id", ValueType.FIXED_LONG);
        }
    });
    schema.addIndexDefinition("foo_to_id_cond", new IndexDefinition(IndexType.CELL_REFERENCING) {

        {
            onTable("two_columns");
            onCondition("foo", "_value > 1");
            rowName();
            componentFromColumn("foo", ValueType.FIXED_LONG, "foo", "_value");
            dynamicColumns();
            componentFromRow("id", ValueType.FIXED_LONG);
        }
    });
    return schema;
}
Also used : IndexDefinition(com.palantir.atlasdb.table.description.IndexDefinition) AtlasSchema(com.palantir.atlasdb.schema.AtlasSchema) Schema(com.palantir.atlasdb.table.description.Schema) TableDefinition(com.palantir.atlasdb.table.description.TableDefinition)

Example 2 with IndexDefinition

use of com.palantir.atlasdb.table.description.IndexDefinition in project atlasdb by palantir.

the class ProfileSchema method generateSchema.

private static Schema generateSchema() {
    Schema schema = new Schema("Profile", ProfileSchema.class.getPackage().getName() + ".generated", Namespace.DEFAULT_NAMESPACE, OptionalType.JAVA8);
    schema.addTableDefinition("user_profile", new TableDefinition() {

        {
            allSafeForLoggingByDefault();
            rowName();
            rowComponent("id", ValueType.UUID);
            columns();
            column("metadata", "m", ProfilePersistence.UserProfile.class);
            column("create", "c", CreationData.Persister.class);
            column("json", "j", JsonNodePersister.class);
            column("photo_stream_id", "p", ValueType.FIXED_LONG);
        }
    });
    schema.addIndexDefinition("user_birthdays", new IndexDefinition(IndexType.CELL_REFERENCING) {

        {
            onTable("user_profile");
            allSafeForLoggingByDefault();
            rowName();
            componentFromColumn("birthday", ValueType.VAR_SIGNED_LONG, "metadata", "_value.getBirthEpochDay()");
            dynamicColumns();
            componentFromRow("id", ValueType.UUID);
            rangeScanAllowed();
            ignoreHotspottingChecks();
        }
    });
    schema.addIndexDefinition("created", new IndexDefinition(IndexType.CELL_REFERENCING) {

        {
            onTable("user_profile");
            allSafeForLoggingByDefault();
            rowName();
            componentFromColumn("time", ValueType.VAR_LONG, "create", "_value.getTimeCreated()");
            dynamicColumns();
            componentFromRow("id", ValueType.UUID);
            rangeScanAllowed();
            ignoreHotspottingChecks();
        }
    });
    schema.addIndexDefinition("cookies", new IndexDefinition(IndexType.CELL_REFERENCING) {

        {
            onTable("user_profile");
            allSafeForLoggingByDefault();
            rowName();
            componentFromIterableColumn("cookie", ValueType.STRING, ValueByteOrder.ASCENDING, "json", "com.palantir.example.profile.schema.ProfileSchema.getCookies(_value)");
            dynamicColumns();
            componentFromRow("id", ValueType.UUID);
            rangeScanAllowed();
        }
    });
    schema.addStreamStoreDefinition(new StreamStoreDefinitionBuilder("user_photos", "user_photos", ValueType.VAR_LONG).tableNameLogSafety(TableMetadataPersistence.LogSafety.SAFE).build());
    return schema;
}
Also used : IndexDefinition(com.palantir.atlasdb.table.description.IndexDefinition) StreamStoreDefinitionBuilder(com.palantir.atlasdb.schema.stream.StreamStoreDefinitionBuilder) AtlasSchema(com.palantir.atlasdb.schema.AtlasSchema) Schema(com.palantir.atlasdb.table.description.Schema) TableDefinition(com.palantir.atlasdb.table.description.TableDefinition) JsonNodePersister(com.palantir.atlasdb.persister.JsonNodePersister) JsonNodePersister(com.palantir.atlasdb.persister.JsonNodePersister)

Aggregations

AtlasSchema (com.palantir.atlasdb.schema.AtlasSchema)2 IndexDefinition (com.palantir.atlasdb.table.description.IndexDefinition)2 Schema (com.palantir.atlasdb.table.description.Schema)2 TableDefinition (com.palantir.atlasdb.table.description.TableDefinition)2 JsonNodePersister (com.palantir.atlasdb.persister.JsonNodePersister)1 StreamStoreDefinitionBuilder (com.palantir.atlasdb.schema.stream.StreamStoreDefinitionBuilder)1