Search in sources :

Example 41 with MappingField

use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.

the class AvroResolver method resolveFields.

static List<MappingField> resolveFields(Schema schema) {
    Map<String, MappingField> fields = new LinkedHashMap<>();
    for (Schema.Field avroField : schema.getFields()) {
        String name = avroField.name();
        QueryDataType type = resolveType(avroField.schema().getType());
        MappingField field = new MappingField(name, type);
        fields.putIfAbsent(field.name(), field);
    }
    return new ArrayList<>(fields.values());
}
Also used : QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) MappingField(com.hazelcast.sql.impl.schema.MappingField) LinkedHashMap(java.util.LinkedHashMap)

Example 42 with MappingField

use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.

the class CsvResolver method resolveFields.

static List<MappingField> resolveFields(Set<String> header) {
    Map<String, MappingField> fields = new LinkedHashMap<>();
    for (String name : header) {
        MappingField field = new MappingField(name, QueryDataType.VARCHAR);
        fields.putIfAbsent(field.name(), field);
    }
    return new ArrayList<>(fields.values());
}
Also used : ArrayList(java.util.ArrayList) MappingField(com.hazelcast.sql.impl.schema.MappingField) LinkedHashMap(java.util.LinkedHashMap)

Example 43 with MappingField

use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.

the class MetadataCompactResolver method resolveAndValidateFields.

@Override
public Stream<MappingField> resolveAndValidateFields(boolean isKey, List<MappingField> userFields, Map<String, String> options, InternalSerializationService serializationService) {
    if (userFields.isEmpty()) {
        throw QueryException.error("Column list is required for Compact format");
    }
    String typeNameProperty = isKey ? OPTION_KEY_COMPACT_TYPE_NAME : OPTION_VALUE_COMPACT_TYPE_NAME;
    String typeName = options.get(typeNameProperty);
    if (typeName == null) {
        throw QueryException.error("Unable to resolve table metadata. Missing ['typeName'] option");
    }
    Map<QueryPath, MappingField> fields = extractFields(userFields, isKey);
    return fields.entrySet().stream().map(entry -> {
        QueryPath path = entry.getKey();
        if (path.getPath() == null) {
            throw QueryException.error("Cannot use the '" + path + "' field with Compact serialization");
        }
        QueryDataType type = entry.getValue().type();
        if (type == QueryDataType.OBJECT) {
            throw QueryException.error("Cannot derive Compact type for '" + type.getTypeFamily() + "'");
        }
        return entry.getValue();
    });
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) MappingField(com.hazelcast.sql.impl.schema.MappingField)

Example 44 with MappingField

use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.

the class MetadataPortableResolver method resolveAndValidateFields.

@Override
public Stream<MappingField> resolveAndValidateFields(boolean isKey, List<MappingField> userFields, Map<String, String> options, InternalSerializationService serializationService) {
    Map<QueryPath, MappingField> userFieldsByPath = extractFields(userFields, isKey);
    ClassDefinition classDefinition = findClassDefinition(isKey, options, serializationService);
    return userFields.isEmpty() ? resolveFields(isKey, classDefinition) : resolveAndValidateFields(isKey, userFieldsByPath, classDefinition);
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) MappingField(com.hazelcast.sql.impl.schema.MappingField) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition)

Example 45 with MappingField

use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.

the class MetadataPortableResolver method resolveMetadata.

private static KvMetadata resolveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<QueryPath, MappingField> fieldsByPath, @Nonnull ClassDefinition clazz) {
    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, GenericQueryTargetDescriptor.DEFAULT, new PortableUpsertTargetDescriptor(clazz));
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) ArrayList(java.util.ArrayList) PortableUpsertTargetDescriptor(com.hazelcast.jet.sql.impl.inject.PortableUpsertTargetDescriptor) TableField(com.hazelcast.sql.impl.schema.TableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) MappingField(com.hazelcast.sql.impl.schema.MappingField) KvMetadata(com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField)

Aggregations

MappingField (com.hazelcast.sql.impl.schema.MappingField)52 Test (org.junit.Test)23 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)19 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)18 ArrayList (java.util.ArrayList)14 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)10 Mapping (com.hazelcast.sql.impl.schema.Mapping)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Parameters (junitparams.Parameters)8 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)7 TableField (com.hazelcast.sql.impl.schema.TableField)7 MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)7 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)6 LinkedHashMap (java.util.LinkedHashMap)6 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)4 KvMetadata (com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata)3 QueryException (com.hazelcast.sql.impl.QueryException)3 SerializationConfig (com.hazelcast.config.SerializationConfig)2 View (com.hazelcast.sql.impl.schema.view.View)2