Search in sources :

Example 1 with MapTableField

use of com.hazelcast.sql.impl.schema.map.MapTableField in project hazelcast by hazelcast.

the class MetadataCompactResolver method resolveMetadata.

@Override
public KvMetadata resolveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<String, String> options, InternalSerializationService serializationService) {
    Map<QueryPath, MappingField> fieldsByPath = extractFields(resolvedFields, isKey);
    String typeNameProperty = isKey ? OPTION_KEY_COMPACT_TYPE_NAME : OPTION_VALUE_COMPACT_TYPE_NAME;
    String typeName = options.get(typeNameProperty);
    List<TableField> fields = new ArrayList<>(fieldsByPath.size());
    for (Entry<QueryPath, MappingField> entry : fieldsByPath.entrySet()) {
        QueryPath path = entry.getKey();
        QueryDataType type = entry.getValue().type();
        String name = entry.getValue().name();
        fields.add(new MapTableField(name, type, false, path));
    }
    maybeAddDefaultField(isKey, resolvedFields, fields, QueryDataType.OBJECT);
    Schema schema = resolveSchema(typeName, fieldsByPath);
    return new KvMetadata(fields, GenericQueryTargetDescriptor.DEFAULT, new CompactUpsertTargetDescriptor(schema));
}
Also used : QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) Schema(com.hazelcast.internal.serialization.impl.compact.Schema) ArrayList(java.util.ArrayList) CompactUpsertTargetDescriptor(com.hazelcast.jet.sql.impl.inject.CompactUpsertTargetDescriptor) MappingField(com.hazelcast.sql.impl.schema.MappingField) TableField(com.hazelcast.sql.impl.schema.TableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) KvMetadata(com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) QueryPath(com.hazelcast.sql.impl.extract.QueryPath)

Example 2 with MapTableField

use of com.hazelcast.sql.impl.schema.map.MapTableField in project hazelcast by hazelcast.

the class KvMetadataAvroResolver method resolveMetadata.

@Override
public KvMetadata resolveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<String, String> options, InternalSerializationService serializationService) {
    Map<QueryPath, MappingField> fieldsByPath = extractFields(resolvedFields, isKey);
    List<TableField> fields = new ArrayList<>();
    for (Entry<QueryPath, MappingField> entry : fieldsByPath.entrySet()) {
        QueryPath path = entry.getKey();
        QueryDataType type = entry.getValue().type();
        String name = entry.getValue().name();
        fields.add(new MapTableField(name, type, false, path));
    }
    maybeAddDefaultField(isKey, resolvedFields, fields, QueryDataType.OBJECT);
    return new KvMetadata(fields, AvroQueryTargetDescriptor.INSTANCE, new AvroUpsertTargetDescriptor(schema(fields).toString()));
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) ArrayList(java.util.ArrayList) AvroUpsertTargetDescriptor(com.hazelcast.jet.sql.impl.inject.AvroUpsertTargetDescriptor) MappingField(com.hazelcast.sql.impl.schema.MappingField) TableField(com.hazelcast.sql.impl.schema.TableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField)

Example 3 with MapTableField

use of com.hazelcast.sql.impl.schema.map.MapTableField in project hazelcast by hazelcast.

the class KvMetadataJavaResolver method resolvePrimitiveMetadata.

private KvMetadata resolvePrimitiveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<QueryPath, MappingField> fieldsByPath, QueryDataType type) {
    List<TableField> fields = new ArrayList<>();
    QueryPath path = isKey ? QueryPath.KEY_PATH : QueryPath.VALUE_PATH;
    MappingField field = fieldsByPath.get(path);
    if (field != null) {
        fields.add(new MapTableField(field.name(), field.type(), false, path));
    }
    maybeAddDefaultField(isKey, resolvedFields, fields, type);
    return new KvMetadata(fields, GenericQueryTargetDescriptor.DEFAULT, PrimitiveUpsertTargetDescriptor.INSTANCE);
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) ArrayList(java.util.ArrayList) TableField(com.hazelcast.sql.impl.schema.TableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) MappingField(com.hazelcast.sql.impl.schema.MappingField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField)

Example 4 with MapTableField

use of com.hazelcast.sql.impl.schema.map.MapTableField in project hazelcast by hazelcast.

the class MetadataPortableResolverTest method test_resolveMetadataWithExistingClassDefinition.

@Test
@Parameters({ "true, __key", "false, this" })
public void test_resolveMetadataWithExistingClassDefinition(boolean key, String prefix) {
    InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
    ClassDefinition classDefinition = new ClassDefinitionBuilder(1, 2, 3).addIntField("field").build();
    ss.getPortableContext().registerClassDefinition(classDefinition);
    Map<String, String> options = ImmutableMap.of((key ? OPTION_KEY_FACTORY_ID : OPTION_VALUE_FACTORY_ID), String.valueOf(classDefinition.getFactoryId()), (key ? OPTION_KEY_CLASS_ID : OPTION_VALUE_CLASS_ID), String.valueOf(classDefinition.getClassId()), (key ? OPTION_KEY_CLASS_VERSION : OPTION_VALUE_CLASS_VERSION), String.valueOf(classDefinition.getVersion()));
    KvMetadata metadata = INSTANCE.resolveMetadata(key, singletonList(field("field", QueryDataType.INT, prefix + ".field")), options, ss);
    assertThat(metadata.getFields()).containsExactly(new MapTableField("field", QueryDataType.INT, false, QueryPath.create(prefix + ".field")), new MapTableField(prefix, QueryDataType.OBJECT, true, QueryPath.create(prefix)));
    assertThat(metadata.getQueryTargetDescriptor()).isEqualTo(GenericQueryTargetDescriptor.DEFAULT);
    assertThat(metadata.getUpsertTargetDescriptor()).isEqualToComparingFieldByField(new PortableUpsertTargetDescriptor(classDefinition));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) PortableUpsertTargetDescriptor(com.hazelcast.jet.sql.impl.inject.PortableUpsertTargetDescriptor) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) KvMetadata(com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 5 with MapTableField

use of com.hazelcast.sql.impl.schema.map.MapTableField in project hazelcast by hazelcast.

the class KvMetadataAvroResolverTest method test_resolveMetadata.

@Test
@Parameters({ "true, __key", "false, this" })
@SuppressWarnings("checkstyle:LineLength")
public void test_resolveMetadata(boolean key, String prefix) {
    KvMetadata metadata = INSTANCE.resolveMetadata(key, asList(field("string", QueryDataType.VARCHAR, prefix + ".string"), 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("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"), field("object", QueryDataType.OBJECT, prefix + ".object")), emptyMap(), null);
    assertThat(metadata.getFields()).containsExactly(new MapTableField("string", QueryDataType.VARCHAR, false, QueryPath.create(prefix + ".string")), 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("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("object", QueryDataType.OBJECT, false, QueryPath.create(prefix + ".object")), new MapTableField(prefix, QueryDataType.OBJECT, true, QueryPath.create(prefix)));
    assertThat(metadata.getQueryTargetDescriptor()).isEqualTo(AvroQueryTargetDescriptor.INSTANCE);
    assertThat(metadata.getUpsertTargetDescriptor()).isEqualToComparingFieldByField(new AvroUpsertTargetDescriptor("{" + "\"type\":\"record\"" + ",\"name\":\"sql\"" + ",\"namespace\":\"jet\"" + ",\"fields\":[" + "{\"name\":\"string\",\"type\":[\"null\",\"string\"],\"default\":null}" + ",{\"name\":\"boolean\",\"type\":[\"null\",\"boolean\"],\"default\":null}" + ",{\"name\":\"byte\",\"type\":[\"null\",\"int\"],\"default\":null}" + ",{\"name\":\"short\",\"type\":[\"null\",\"int\"],\"default\":null}" + ",{\"name\":\"int\",\"type\":[\"null\",\"int\"],\"default\":null}" + ",{\"name\":\"long\",\"type\":[\"null\",\"long\"],\"default\":null}" + ",{\"name\":\"float\",\"type\":[\"null\",\"float\"],\"default\":null}" + ",{\"name\":\"double\",\"type\":[\"null\",\"double\"],\"default\":null}" + ",{\"name\":\"decimal\",\"type\":[\"null\",\"string\"],\"default\":null}" + ",{\"name\":\"time\",\"type\":[\"null\",\"string\"],\"default\":null}" + ",{\"name\":\"date\",\"type\":[\"null\",\"string\"],\"default\":null}" + ",{\"name\":\"timestamp\",\"type\":[\"null\",\"string\"],\"default\":null}" + ",{\"name\":\"timestampTz\",\"type\":[\"null\",\"string\"],\"default\":null}" + ",{\"name\":\"object\",\"type\":[\"null\",\"boolean\",\"int\",\"long\",\"float\",\"double\",\"string\"],\"default\":null}" + "]" + "}"));
}
Also used : AvroUpsertTargetDescriptor(com.hazelcast.jet.sql.impl.inject.AvroUpsertTargetDescriptor) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)27 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)17 TableField (com.hazelcast.sql.impl.schema.TableField)15 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)13 Parameters (junitparams.Parameters)12 Test (org.junit.Test)12 KvMetadata (com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata)8 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)8 ArrayList (java.util.ArrayList)8 MappingField (com.hazelcast.sql.impl.schema.MappingField)7 OptimizerTestSupport (com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport)5 FullScanPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.FullScanPhysicalRel)4 IndexScanMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel)4 PortableUpsertTargetDescriptor (com.hazelcast.jet.sql.impl.inject.PortableUpsertTargetDescriptor)3 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)2 AvroUpsertTargetDescriptor (com.hazelcast.jet.sql.impl.inject.AvroUpsertTargetDescriptor)2 CompactUpsertTargetDescriptor (com.hazelcast.jet.sql.impl.inject.CompactUpsertTargetDescriptor)2 PojoUpsertTargetDescriptor (com.hazelcast.jet.sql.impl.inject.PojoUpsertTargetDescriptor)2 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)2 ImmutableList (com.google.common.collect.ImmutableList)1