Search in sources :

Example 1 with AvroUpsertTargetDescriptor

use of com.hazelcast.jet.sql.impl.inject.AvroUpsertTargetDescriptor 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 2 with AvroUpsertTargetDescriptor

use of com.hazelcast.jet.sql.impl.inject.AvroUpsertTargetDescriptor 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

AvroUpsertTargetDescriptor (com.hazelcast.jet.sql.impl.inject.AvroUpsertTargetDescriptor)2 MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)2 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)1 MappingField (com.hazelcast.sql.impl.schema.MappingField)1 TableField (com.hazelcast.sql.impl.schema.TableField)1 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)1 ArrayList (java.util.ArrayList)1 Parameters (junitparams.Parameters)1 Test (org.junit.Test)1