Search in sources :

Example 1 with PojoUpsertTargetDescriptor

use of com.hazelcast.jet.sql.impl.inject.PojoUpsertTargetDescriptor in project hazelcast by hazelcast.

the class KvMetadataJavaResolverTest method test_resolveMetadata.

@Test
@Parameters({ "true, __key", "false, this" })
public void test_resolveMetadata(boolean key, String prefix) {
    Map<String, String> options = ImmutableMap.of((key ? OPTION_KEY_FORMAT : OPTION_VALUE_FORMAT), JAVA_FORMAT, (key ? OPTION_KEY_CLASS : OPTION_VALUE_CLASS), Type.class.getName());
    KvMetadata metadata = INSTANCE.resolveMetadata(key, singletonList(field("field", QueryDataType.INT, prefix + ".field")), options, null);
    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 PojoUpsertTargetDescriptor(Type.class.getName(), ImmutableMap.of("field", int.class.getName())));
}
Also used : QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) PojoUpsertTargetDescriptor(com.hazelcast.jet.sql.impl.inject.PojoUpsertTargetDescriptor) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 2 with PojoUpsertTargetDescriptor

use of com.hazelcast.jet.sql.impl.inject.PojoUpsertTargetDescriptor in project hazelcast by hazelcast.

the class KvMetadataJavaResolver method resolveObjectMetadata.

private KvMetadata resolveObjectMetadata(boolean isKey, List<MappingField> resolvedFields, Map<QueryPath, MappingField> fieldsByPath, Class<?> clazz) {
    Map<String, Class<?>> typesByNames = FieldsUtil.resolveClass(clazz);
    List<TableField> fields = new ArrayList<>();
    Map<String, String> typeNamesByPaths = new HashMap<>();
    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));
        if (path.getPath() != null && typesByNames.get(path.getPath()) != null) {
            typeNamesByPaths.put(path.getPath(), typesByNames.get(path.getPath()).getName());
        }
    }
    maybeAddDefaultField(isKey, resolvedFields, fields, QueryDataType.OBJECT);
    return new KvMetadata(fields, GenericQueryTargetDescriptor.DEFAULT, new PojoUpsertTargetDescriptor(clazz.getName(), typeNamesByPaths));
}
Also used : HashMap(java.util.HashMap) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) ArrayList(java.util.ArrayList) PojoUpsertTargetDescriptor(com.hazelcast.jet.sql.impl.inject.PojoUpsertTargetDescriptor) 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) QueryPath(com.hazelcast.sql.impl.extract.QueryPath)

Aggregations

PojoUpsertTargetDescriptor (com.hazelcast.jet.sql.impl.inject.PojoUpsertTargetDescriptor)2 MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)2 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)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 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Parameters (junitparams.Parameters)1 Test (org.junit.Test)1