Search in sources :

Example 21 with MapTableField

use of com.hazelcast.sql.impl.schema.map.MapTableField in project hazelcast by hazelcast.

the class SqlSecurityCallbackTest method checkIndexUsage.

private void checkIndexUsage(String sql, boolean expectedIndexUsage) {
    List<QueryDataType> parameterTypes = asList(QueryDataType.INT, QueryDataType.INT);
    List<TableField> mapTableFields = asList(new MapTableField("__key", QueryDataType.INT, false, QueryPath.KEY_PATH), new MapTableField("this", QueryDataType.INT, false, QueryPath.VALUE_PATH));
    HazelcastTable table = partitionedTable(mapName, mapTableFields, getPartitionedMapIndexes(mapContainer(instance().getMap(mapName)), mapTableFields), mapSize);
    OptimizerTestSupport.Result optimizationResult = optimizePhysical(sql, parameterTypes, table);
    assertPlan(optimizationResult.getLogical(), plan(planRow(0, FullScanLogicalRel.class)));
    assertPlan(optimizationResult.getPhysical(), plan(planRow(0, expectedIndexUsage ? IndexScanMapPhysicalRel.class : FullScanPhysicalRel.class)));
}
Also used : IndexScanMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) FullScanPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.FullScanPhysicalRel) OptimizerTestSupport(com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport) TableField(com.hazelcast.sql.impl.schema.TableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField)

Example 22 with MapTableField

use of com.hazelcast.sql.impl.schema.map.MapTableField in project hazelcast by hazelcast.

the class SqlNoSerializationTest method checkIndexUsage.

private void checkIndexUsage(SqlStatement statement, boolean expectedIndexUsage) {
    List<QueryDataType> parameterTypes = asList(QueryDataType.INT, QueryDataType.OBJECT, QueryDataType.INT);
    List<TableField> mapTableFields = asList(new MapTableField("__key", QueryDataType.INT, false, QueryPath.KEY_PATH), new MapTableField("this", QueryDataType.OBJECT, false, QueryPath.VALUE_PATH), new MapTableField("val", QueryDataType.INT, false, new QueryPath("val", false)));
    HazelcastTable table = partitionedTable(MAP_NAME, mapTableFields, getPartitionedMapIndexes(mapContainer(instance().getMap(MAP_NAME)), mapTableFields), KEY_COUNT);
    OptimizerTestSupport.Result optimizationResult = optimizePhysical(statement.getSql(), parameterTypes, table);
    assertPlan(optimizationResult.getLogical(), plan(planRow(0, FullScanLogicalRel.class)));
    if (expectedIndexUsage) {
        assertPlan(optimizationResult.getPhysical(), plan(planRow(0, IndexScanMapPhysicalRel.class)));
    } else {
        assertPlan(optimizationResult.getPhysical(), plan(planRow(0, FullScanPhysicalRel.class)));
    }
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) OptimizerTestSupport(com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport) TableField(com.hazelcast.sql.impl.schema.TableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField)

Example 23 with MapTableField

use of com.hazelcast.sql.impl.schema.map.MapTableField in project hazelcast by hazelcast.

the class SqlExtendedInsert method validate.

@Override
public void validate(SqlValidator validator, SqlValidatorScope scope) {
    SqlValidatorTable table0 = validator.getCatalogReader().getTable(tableNames());
    if (table0 == null) {
        super.validate(validator, scope);
        // should have failed with "Object not found"
        assert false;
    }
    HazelcastTable table = table0.unwrap(HazelcastTable.class);
    if (getTargetColumnList() == null) {
        RelDataType rowType = table.getRowType(validator.getTypeFactory());
        List<SqlNode> columnListWithoutHidden = new ArrayList<>();
        for (RelDataTypeField f : rowType.getFieldList()) {
            if (!table.isHidden(f.getName())) {
                columnListWithoutHidden.add(new SqlIdentifier(f.getName(), SqlParserPos.ZERO));
            }
        }
        overrideColumnList = new SqlNodeList(columnListWithoutHidden, SqlParserPos.ZERO);
    }
    super.validate(validator, scope);
    Map<String, TableField> fieldsMap = table.getTarget().getFields().stream().collect(Collectors.toMap(TableField::getName, f -> f));
    for (SqlNode fieldNode : getTargetColumnList()) {
        TableField field = fieldsMap.get(((SqlIdentifier) fieldNode).getSimple());
        if (field instanceof MapTableField) {
            QueryPath path = ((MapTableField) field).getPath();
            if (path.getPath() == null && field.getType().getTypeFamily() == QueryDataTypeFamily.OBJECT) {
                throw validator.newValidationError(fieldNode, RESOURCE.insertToTopLevelObject());
            }
        }
    }
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType) SqlInsert(org.apache.calcite.sql.SqlInsert) SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) SqlWriter(org.apache.calcite.sql.SqlWriter) SqlValidatorScope(org.apache.calcite.sql.validate.SqlValidatorScope) RESOURCE(com.hazelcast.jet.sql.impl.parse.ParserResource.RESOURCE) Collectors(java.util.stream.Collectors) QueryDataTypeFamily(com.hazelcast.sql.impl.type.QueryDataTypeFamily) ArrayList(java.util.ArrayList) TableField(com.hazelcast.sql.impl.schema.TableField) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) List(java.util.List) SqlLiteral(org.apache.calcite.sql.SqlLiteral) SqlNode(org.apache.calcite.sql.SqlNode) ImmutableList(com.google.common.collect.ImmutableList) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) Map(java.util.Map) QueryPath(com.hazelcast.sql.impl.extract.QueryPath) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlValidator(org.apache.calcite.sql.validate.SqlValidator) SqlValidatorTable(org.apache.calcite.sql.validate.SqlValidatorTable) SqlNodeList(org.apache.calcite.sql.SqlNodeList) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) TableField(com.hazelcast.sql.impl.schema.TableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) QueryPath(com.hazelcast.sql.impl.extract.QueryPath) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) SqlValidatorTable(org.apache.calcite.sql.validate.SqlValidatorTable) SqlNodeList(org.apache.calcite.sql.SqlNodeList) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) SqlNode(org.apache.calcite.sql.SqlNode)

Example 24 with MapTableField

use of com.hazelcast.sql.impl.schema.map.MapTableField 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 25 with MapTableField

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

Aggregations

MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)27 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)17 TableField (com.hazelcast.sql.impl.schema.TableField)15 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)13 Parameters (junitparams.Parameters)12 Test (org.junit.Test)12 KvMetadata (com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata)8 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)8 ArrayList (java.util.ArrayList)8 MappingField (com.hazelcast.sql.impl.schema.MappingField)7 OptimizerTestSupport (com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport)5 FullScanPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.FullScanPhysicalRel)4 IndexScanMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel)4 PortableUpsertTargetDescriptor (com.hazelcast.jet.sql.impl.inject.PortableUpsertTargetDescriptor)3 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)2 AvroUpsertTargetDescriptor (com.hazelcast.jet.sql.impl.inject.AvroUpsertTargetDescriptor)2 CompactUpsertTargetDescriptor (com.hazelcast.jet.sql.impl.inject.CompactUpsertTargetDescriptor)2 PojoUpsertTargetDescriptor (com.hazelcast.jet.sql.impl.inject.PojoUpsertTargetDescriptor)2 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)2 ImmutableList (com.google.common.collect.ImmutableList)1