Search in sources :

Example 1 with SchemaWriter

use of com.hazelcast.internal.serialization.impl.compact.SchemaWriter in project hazelcast by hazelcast.

the class MetadataCompactResolver method resolveSchema.

private Schema resolveSchema(String typeName, Map<QueryPath, MappingField> fields) {
    SchemaWriter schemaWriter = new SchemaWriter(typeName);
    for (Entry<QueryPath, MappingField> entry : fields.entrySet()) {
        String name = entry.getKey().getPath();
        QueryDataType type = entry.getValue().type();
        schemaWriter.addField(new FieldDescriptor(name, resolveToCompactKind(type.getTypeFamily())));
    }
    return schemaWriter.build();
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) MappingField(com.hazelcast.sql.impl.schema.MappingField) SchemaWriter(com.hazelcast.internal.serialization.impl.compact.SchemaWriter) FieldDescriptor(com.hazelcast.internal.serialization.impl.compact.FieldDescriptor)

Example 2 with SchemaWriter

use of com.hazelcast.internal.serialization.impl.compact.SchemaWriter in project hazelcast by hazelcast.

the class MetadataCompactResolverTest method test_resolveMetadata.

@Test
@Parameters({ "true, __key", "false, this" })
public void test_resolveMetadata(boolean key, String prefix) {
    KvMetadata metadata = INSTANCE.resolveMetadata(key, asList(field("boolean", QueryDataType.BOOLEAN, prefix + ".boolean"), field("byte", QueryDataType.TINYINT, prefix + ".byte"), field("short", QueryDataType.SMALLINT, prefix + ".short"), field("int", QueryDataType.INT, prefix + ".int"), field("long", QueryDataType.BIGINT, prefix + ".long"), field("float", QueryDataType.REAL, prefix + ".float"), field("double", QueryDataType.DOUBLE, prefix + ".double"), field("decimal", QueryDataType.DECIMAL, prefix + ".decimal"), field("string", QueryDataType.VARCHAR, prefix + ".string"), field("time", QueryDataType.TIME, prefix + ".time"), field("date", QueryDataType.DATE, prefix + ".date"), field("timestamp", QueryDataType.TIMESTAMP, prefix + ".timestamp"), field("timestampTz", QueryDataType.TIMESTAMP_WITH_TZ_OFFSET_DATE_TIME, prefix + ".timestampTz")), ImmutableMap.of((key ? OPTION_KEY_COMPACT_TYPE_NAME : OPTION_VALUE_COMPACT_TYPE_NAME), "test"), createSerializationService());
    assertThat(metadata.getFields()).containsExactly(new MapTableField("boolean", QueryDataType.BOOLEAN, false, QueryPath.create(prefix + ".boolean")), new MapTableField("byte", QueryDataType.TINYINT, false, QueryPath.create(prefix + ".byte")), new MapTableField("short", QueryDataType.SMALLINT, false, QueryPath.create(prefix + ".short")), new MapTableField("int", QueryDataType.INT, false, QueryPath.create(prefix + ".int")), new MapTableField("long", QueryDataType.BIGINT, false, QueryPath.create(prefix + ".long")), new MapTableField("float", QueryDataType.REAL, false, QueryPath.create(prefix + ".float")), new MapTableField("double", QueryDataType.DOUBLE, false, QueryPath.create(prefix + ".double")), new MapTableField("decimal", QueryDataType.DECIMAL, false, QueryPath.create(prefix + ".decimal")), new MapTableField("string", QueryDataType.VARCHAR, false, QueryPath.create(prefix + ".string")), new MapTableField("time", QueryDataType.TIME, false, QueryPath.create(prefix + ".time")), new MapTableField("date", QueryDataType.DATE, false, QueryPath.create(prefix + ".date")), new MapTableField("timestamp", QueryDataType.TIMESTAMP, false, QueryPath.create(prefix + ".timestamp")), new MapTableField("timestampTz", QueryDataType.TIMESTAMP_WITH_TZ_OFFSET_DATE_TIME, false, QueryPath.create(prefix + ".timestampTz")), new MapTableField(prefix, QueryDataType.OBJECT, true, QueryPath.create(prefix)));
    assertThat(metadata.getQueryTargetDescriptor()).isEqualTo(GenericQueryTargetDescriptor.DEFAULT);
    SchemaWriter schemaWriter = new SchemaWriter("test");
    schemaWriter.addField(new FieldDescriptor("boolean", FieldKind.NULLABLE_BOOLEAN));
    schemaWriter.addField(new FieldDescriptor("byte", FieldKind.NULLABLE_INT8));
    schemaWriter.addField(new FieldDescriptor("short", FieldKind.NULLABLE_INT16));
    schemaWriter.addField(new FieldDescriptor("int", FieldKind.NULLABLE_INT32));
    schemaWriter.addField(new FieldDescriptor("long", FieldKind.NULLABLE_INT64));
    schemaWriter.addField(new FieldDescriptor("float", FieldKind.NULLABLE_FLOAT32));
    schemaWriter.addField(new FieldDescriptor("double", FieldKind.NULLABLE_FLOAT64));
    schemaWriter.addField(new FieldDescriptor("decimal", FieldKind.DECIMAL));
    schemaWriter.addField(new FieldDescriptor("string", FieldKind.STRING));
    schemaWriter.addField(new FieldDescriptor("time", FieldKind.TIME));
    schemaWriter.addField(new FieldDescriptor("date", FieldKind.DATE));
    schemaWriter.addField(new FieldDescriptor("timestamp", FieldKind.TIMESTAMP));
    schemaWriter.addField(new FieldDescriptor("timestampTz", FieldKind.TIMESTAMP_WITH_TIMEZONE));
    assertEquals(metadata.getUpsertTargetDescriptor(), new CompactUpsertTargetDescriptor(schemaWriter.build()));
}
Also used : CompactUpsertTargetDescriptor(com.hazelcast.jet.sql.impl.inject.CompactUpsertTargetDescriptor) KvMetadata(com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata) SchemaWriter(com.hazelcast.internal.serialization.impl.compact.SchemaWriter) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) FieldDescriptor(com.hazelcast.internal.serialization.impl.compact.FieldDescriptor) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 3 with SchemaWriter

use of com.hazelcast.internal.serialization.impl.compact.SchemaWriter in project hazelcast by hazelcast.

the class CompactUpsertTargetDescriptorTest method test_serialization.

@Test
public void test_serialization() {
    SchemaWriter schemaWriter = new SchemaWriter("test");
    schemaWriter.addField(new FieldDescriptor("int", FieldKind.INT32));
    schemaWriter.addField(new FieldDescriptor("long", FieldKind.INT64));
    CompactUpsertTargetDescriptor original = new CompactUpsertTargetDescriptor(schemaWriter.build());
    // when
    CompactUpsertTargetDescriptor serialized = SERIALIZATION_SERVICE.toObject(SERIALIZATION_SERVICE.toData(original));
    // then
    assertThat(serialized).isEqualToComparingFieldByField(original);
}
Also used : SchemaWriter(com.hazelcast.internal.serialization.impl.compact.SchemaWriter) FieldDescriptor(com.hazelcast.internal.serialization.impl.compact.FieldDescriptor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

FieldDescriptor (com.hazelcast.internal.serialization.impl.compact.FieldDescriptor)3 SchemaWriter (com.hazelcast.internal.serialization.impl.compact.SchemaWriter)3 Test (org.junit.Test)2 KvMetadata (com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata)1 CompactUpsertTargetDescriptor (com.hazelcast.jet.sql.impl.inject.CompactUpsertTargetDescriptor)1 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)1 MappingField (com.hazelcast.sql.impl.schema.MappingField)1 MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)1 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Parameters (junitparams.Parameters)1