Search in sources :

Example 1 with MappingField

use of com.hazelcast.sql.impl.schema.MappingField 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 MappingField

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

the class MetadataCompactResolver method resolveSchema.

private Schema resolveSchema(String typeName, Map<QueryPath, MappingField> fields) {
    SchemaWriter schemaWriter = new SchemaWriter(typeName);
    for (Entry<QueryPath, MappingField> entry : fields.entrySet()) {
        String name = entry.getKey().getPath();
        QueryDataType type = entry.getValue().type();
        schemaWriter.addField(new FieldDescriptor(name, resolveToCompactKind(type.getTypeFamily())));
    }
    return schemaWriter.build();
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) MappingField(com.hazelcast.sql.impl.schema.MappingField) SchemaWriter(com.hazelcast.internal.serialization.impl.compact.SchemaWriter) FieldDescriptor(com.hazelcast.internal.serialization.impl.compact.FieldDescriptor)

Example 3 with MappingField

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

the class MetadataPortableResolver method resolveFields.

Stream<MappingField> resolveFields(boolean isKey, @Nullable ClassDefinition clazz) {
    if (clazz == null || clazz.getFieldCount() == 0) {
        // ClassDefinition does not exist, or it is empty, map the whole value
        String name = isKey ? KEY : VALUE;
        return Stream.of(new MappingField(name, QueryDataType.OBJECT, name));
    }
    return clazz.getFieldNames().stream().map(name -> {
        QueryPath path = new QueryPath(name, isKey);
        QueryDataType type = resolvePortableType(clazz.getFieldType(name));
        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 4 with MappingField

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

the class MetadataPortableResolver method resolveClassDefinition.

@Nonnull
private static ClassDefinition resolveClassDefinition(boolean isKey, Map<String, String> options, Collection<MappingField> fields, InternalSerializationService serializationService) {
    Tuple3<Integer, Integer, Integer> settings = settings(isKey, options);
    // noinspection ConstantConditions
    ClassDefinition classDefinition = serializationService.getPortableContext().lookupClassDefinition(settings.f0(), settings.f1(), settings.f2());
    if (classDefinition != null) {
        return classDefinition;
    }
    ClassDefinitionBuilder classDefinitionBuilder = new ClassDefinitionBuilder(settings.f0(), settings.f1(), settings.f2());
    for (MappingField field : fields) {
        String name = field.name();
        QueryDataType type = field.type();
        switch(type.getTypeFamily()) {
            case BOOLEAN:
                classDefinitionBuilder.addBooleanField(name);
                break;
            case TINYINT:
                classDefinitionBuilder.addByteField(name);
                break;
            case SMALLINT:
                classDefinitionBuilder.addShortField(name);
                break;
            case INTEGER:
                classDefinitionBuilder.addIntField(name);
                break;
            case BIGINT:
                classDefinitionBuilder.addLongField(name);
                break;
            case REAL:
                classDefinitionBuilder.addFloatField(name);
                break;
            case DOUBLE:
                classDefinitionBuilder.addDoubleField(name);
                break;
            case DECIMAL:
                classDefinitionBuilder.addDecimalField(name);
                break;
            case VARCHAR:
                classDefinitionBuilder.addStringField(name);
                break;
            case TIME:
                classDefinitionBuilder.addTimeField(name);
                break;
            case DATE:
                classDefinitionBuilder.addDateField(name);
                break;
            case TIMESTAMP:
                classDefinitionBuilder.addTimestampField(name);
                break;
            case TIMESTAMP_WITH_TIME_ZONE:
                classDefinitionBuilder.addTimestampWithTimezoneField(name);
                break;
            default:
        }
    }
    return classDefinitionBuilder.build();
}
Also used : QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) MappingField(com.hazelcast.sql.impl.schema.MappingField) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) Nonnull(javax.annotation.Nonnull)

Example 5 with MappingField

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

the class MetadataPortableResolver method resolveMetadata.

@Override
public KvMetadata resolveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<String, String> options, InternalSerializationService serializationService) {
    Map<QueryPath, MappingField> fieldsByPath = extractFields(resolvedFields, isKey);
    ClassDefinition clazz = resolveClassDefinition(isKey, options, fieldsByPath.values(), serializationService);
    return resolveMetadata(isKey, resolvedFields, fieldsByPath, clazz);
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) MappingField(com.hazelcast.sql.impl.schema.MappingField) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition)

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