Search in sources :

Example 6 with QueryPath

use of com.hazelcast.sql.impl.extract.QueryPath in project hazelcast by hazelcast.

the class MetadataPortableResolver method resolveAndValidateFields.

private static Stream<MappingField> resolveAndValidateFields(boolean isKey, Map<QueryPath, MappingField> userFieldsByPath, @Nullable ClassDefinition clazz) {
    if (clazz == null) {
        // CLassDefinition does not exist, make sure there are no OBJECT fields
        return userFieldsByPath.values().stream().peek(mappingField -> {
            QueryDataType type = mappingField.type();
            if (type == QueryDataType.OBJECT) {
                throw QueryException.error("Cannot derive Portable type for '" + type.getTypeFamily() + "'");
            }
        });
    }
    for (String name : clazz.getFieldNames()) {
        QueryPath path = new QueryPath(name, isKey);
        QueryDataType type = resolvePortableType(clazz.getFieldType(name));
        MappingField userField = userFieldsByPath.get(path);
        if (userField != null && !type.getTypeFamily().equals(userField.type().getTypeFamily())) {
            throw QueryException.error("Mismatch between declared and resolved type: " + userField.name());
        }
    }
    return userFieldsByPath.values().stream();
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) MappingField(com.hazelcast.sql.impl.schema.MappingField)

Example 7 with QueryPath

use of com.hazelcast.sql.impl.extract.QueryPath 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 8 with QueryPath

use of com.hazelcast.sql.impl.extract.QueryPath in project hazelcast by hazelcast.

the class KvMetadataJavaResolver method resolveAndValidateObjectFields.

private Stream<MappingField> resolveAndValidateObjectFields(boolean isKey, List<MappingField> userFields, Class<?> clazz) {
    Map<QueryPath, MappingField> userFieldsByPath = extractFields(userFields, isKey);
    for (Entry<String, Class<?>> classField : FieldsUtil.resolveClass(clazz).entrySet()) {
        QueryPath path = new QueryPath(classField.getKey(), isKey);
        QueryDataType type = QueryDataTypeUtils.resolveTypeForClass(classField.getValue());
        MappingField userField = userFieldsByPath.get(path);
        if (userField != null && !type.getTypeFamily().equals(userField.type().getTypeFamily())) {
            throw QueryException.error("Mismatch between declared and resolved type for field '" + userField.name() + "'. Declared: " + userField.type().getTypeFamily() + ", resolved: " + type.getTypeFamily());
        }
    }
    return userFieldsByPath.values().stream();
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) MappingField(com.hazelcast.sql.impl.schema.MappingField)

Example 9 with QueryPath

use of com.hazelcast.sql.impl.extract.QueryPath in project hazelcast by hazelcast.

the class KvMetadataJavaResolver method resolveObjectFields.

private Stream<MappingField> resolveObjectFields(boolean isKey, Class<?> clazz) {
    Map<String, Class<?>> fieldsInClass = FieldsUtil.resolveClass(clazz);
    if (fieldsInClass.isEmpty()) {
        // we didn't find any non-object fields in the class, map the whole value (e.g. in java.lang.Object)
        String name = isKey ? KEY : VALUE;
        return Stream.of(new MappingField(name, QueryDataType.OBJECT, name));
    }
    return fieldsInClass.entrySet().stream().map(classField -> {
        QueryPath path = new QueryPath(classField.getKey(), isKey);
        QueryDataType type = QueryDataTypeUtils.resolveTypeForClass(classField.getValue());
        String name = classField.getKey();
        return new MappingField(name, type, path.toString());
    });
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) MappingField(com.hazelcast.sql.impl.schema.MappingField)

Example 10 with QueryPath

use of com.hazelcast.sql.impl.extract.QueryPath in project hazelcast by hazelcast.

the class KvMetadataJavaResolver method resolvePrimitiveField.

private Stream<MappingField> resolvePrimitiveField(boolean isKey, QueryDataType type) {
    QueryPath path = isKey ? QueryPath.KEY_PATH : QueryPath.VALUE_PATH;
    String name = isKey ? KEY : VALUE;
    String externalName = path.toString();
    return Stream.of(new MappingField(name, type, externalName));
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) MappingField(com.hazelcast.sql.impl.schema.MappingField)

Aggregations

QueryPath (com.hazelcast.sql.impl.extract.QueryPath)35 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)22 MappingField (com.hazelcast.sql.impl.schema.MappingField)19 MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)17 TableField (com.hazelcast.sql.impl.schema.TableField)13 ArrayList (java.util.ArrayList)10 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)6 KvMetadata (com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata)4 OptimizerTestSupport (com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport)3 Parameters (junitparams.Parameters)3 Test (org.junit.Test)3 FullScanPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.FullScanPhysicalRel)2 IndexScanMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel)2 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)2 ImmutableList (com.google.common.collect.ImmutableList)1 IndexConfig (com.hazelcast.config.IndexConfig)1 ArrayDataSerializableFactory (com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)1 FieldDescriptor (com.hazelcast.internal.serialization.impl.compact.FieldDescriptor)1 Schema (com.hazelcast.internal.serialization.impl.compact.Schema)1 SchemaWriter (com.hazelcast.internal.serialization.impl.compact.SchemaWriter)1