Search in sources :

Example 26 with QueryPath

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

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

Example 28 with QueryPath

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

the class KvRowProjector method createExtractors.

private static QueryExtractor[] createExtractors(QueryPath[] paths, QueryDataType[] types, QueryTarget keyTarget, QueryTarget valueTarget) {
    QueryExtractor[] extractors = new QueryExtractor[paths.length];
    for (int i = 0; i < paths.length; i++) {
        QueryPath path = paths[i];
        QueryDataType type = types[i];
        extractors[i] = path.isKey() ? keyTarget.createExtractor(path.getPath(), type) : valueTarget.createExtractor(path.getPath(), type);
    }
    return extractors;
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) QueryExtractor(com.hazelcast.sql.impl.extract.QueryExtractor)

Example 29 with QueryPath

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

the class MetadataJsonResolver method resolveMetadata.

@Override
public KvMetadata resolveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<String, String> options, InternalSerializationService serializationService) {
    Map<QueryPath, MappingField> externalFieldsByPath = extractFields(resolvedFields, isKey);
    List<TableField> fields = new ArrayList<>();
    for (Entry<QueryPath, MappingField> entry : externalFieldsByPath.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, HazelcastJsonQueryTargetDescriptor.INSTANCE, HazelcastJsonUpsertTargetDescriptor.INSTANCE);
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) ArrayList(java.util.ArrayList) 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)

Example 30 with QueryPath

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

the class QueryUtil method toPredicate.

@SuppressWarnings({ "unchecked", "rawtypes" })
static Predicate<Object, Object> toPredicate(JetSqlRow left, int[] leftEquiJoinIndices, int[] rightEquiJoinIndices, QueryPath[] rightPaths) {
    PredicateBuilder builder = Predicates.newPredicateBuilder();
    EntryObject entryObject = builder.getEntryObject();
    for (int i = 0; i < leftEquiJoinIndices.length; i++) {
        Comparable leftValue = asComparable(left.get(leftEquiJoinIndices[i]));
        // might need a change when/if IS NOT DISTINCT FROM is supported
        if (leftValue == null) {
            return null;
        }
        QueryPath rightPath = rightPaths[rightEquiJoinIndices[i]];
        EntryObject object;
        if (rightPath.isKey()) {
            object = rightPath.isTop() ? entryObject.key() : entryObject.key().get(rightPath.getPath());
        } else {
            object = rightPath.isTop() ? entryObject.get(rightPath.toString()) : entryObject.get(QueryPath.VALUE).get(rightPath.getPath());
        }
        if (i == 0) {
            object.equal(leftValue);
        } else {
            builder.and(object.equal(leftValue));
        }
    }
    return builder;
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder)

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