Search in sources :

Example 16 with QueryDataType

use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.

the class SqlCreateIndexTest method checkPlan.

private void checkPlan(boolean withIndex, boolean sorted, String sql, String mapName) {
    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(map), mapTableFields), map.size());
    assertThat(table.getProjects().size()).isEqualTo(2);
    OptimizerTestSupport.Result optimizationResult = optimizePhysical(sql, parameterTypes, table);
    if (sorted) {
        if (withIndex) {
            assertPlan(optimizationResult.getPhysical(), plan(planRow(0, IndexScanMapPhysicalRel.class)));
        } else {
            assertPlan(optimizationResult.getPhysical(), plan(planRow(0, SortPhysicalRel.class), planRow(1, FullScanPhysicalRel.class)));
        }
    } else {
        assertPlan(optimizationResult.getLogical(), plan(planRow(0, FullScanLogicalRel.class)));
        assertPlan(optimizationResult.getPhysical(), plan(planRow(0, withIndex ? 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 17 with QueryDataType

use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.

the class HazelcastTypeUtils method canCast.

public static boolean canCast(RelDataType sourceType, RelDataType targetType) {
    if (targetType.equals(sourceType)) {
        return true;
    }
    if (sourceType.isStruct() || targetType.isStruct()) {
        if (sourceType.getSqlTypeName() != SqlTypeName.ROW) {
            throw new IllegalArgumentException("Unexpected source type: " + sourceType);
        }
        if (targetType.getSqlTypeName() != SqlTypeName.ROW) {
            throw new IllegalArgumentException("Unexpected target type: " + targetType);
        }
        int n = targetType.getFieldCount();
        if (sourceType.getFieldCount() != n) {
            return false;
        }
        for (int i = 0; i < n; ++i) {
            RelDataTypeField toField = targetType.getFieldList().get(i);
            RelDataTypeField fromField = sourceType.getFieldList().get(i);
            if (!canCast(toField.getType(), fromField.getType())) {
                return false;
            }
        }
        return true;
    }
    QueryDataType queryFrom = toHazelcastType(sourceType);
    QueryDataType queryTo = toHazelcastType(targetType);
    return queryFrom.getConverter().canConvertTo(queryTo.getTypeFamily());
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType)

Example 18 with QueryDataType

use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.

the class HazelcastTypeUtils method toHazelcastTypeFromSqlTypeName.

public static QueryDataType toHazelcastTypeFromSqlTypeName(SqlTypeName sqlTypeName) {
    SqlTypeFamily sqlTypeNameFamily = sqlTypeName.getFamily();
    if (sqlTypeNameFamily == SqlTypeFamily.INTERVAL_YEAR_MONTH) {
        return QueryDataType.INTERVAL_YEAR_MONTH;
    } else if (sqlTypeNameFamily == SqlTypeFamily.INTERVAL_DAY_TIME) {
        return QueryDataType.INTERVAL_DAY_SECOND;
    }
    QueryDataType queryDataType = CALCITE_TO_HZ.get(sqlTypeName);
    if (queryDataType == null) {
        throw new IllegalArgumentException("Unexpected SQL type: " + sqlTypeName);
    }
    return queryDataType;
}
Also used : SqlTypeFamily(org.apache.calcite.sql.type.SqlTypeFamily) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType)

Example 19 with QueryDataType

use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.

the class SqlIndexAbstractTest method checkPlan.

private void checkPlan(boolean withIndex, String sql) {
    List<QueryDataType> parameterTypes = asList(QueryDataType.INT, f1.getFieldConverterType(), f2.getFieldConverterType());
    List<TableField> mapTableFields = asList(new MapTableField("__key", QueryDataType.INT, false, QueryPath.KEY_PATH), new MapTableField("field1", f1.getFieldConverterType(), false, new QueryPath("field1", false)), new MapTableField("field2", f2.getFieldConverterType(), false, new QueryPath("field2", false)));
    HazelcastTable table = partitionedTable(mapName, mapTableFields, getPartitionedMapIndexes(mapContainer(map), mapTableFields), map.size());
    OptimizerTestSupport.Result optimizationResult = optimizePhysical(sql, parameterTypes, table);
    assertPlan(optimizationResult.getLogical(), plan(planRow(0, FullScanLogicalRel.class)));
    assertPlan(optimizationResult.getPhysical(), plan(planRow(0, withIndex ? IndexScanMapPhysicalRel.class : FullScanPhysicalRel.class)));
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) 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) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) TableField(com.hazelcast.sql.impl.schema.TableField) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField)

Example 20 with QueryDataType

use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.

the class SqlIndexCastTest method checkIndexUsage.

private void checkIndexUsage(SqlStatement statement, ExpressionType<?> field, boolean expectedIndexUsage) {
    List<QueryDataType> parameterTypes = asList(QueryDataType.INT, field.getFieldConverterType());
    List<TableField> mapTableFields = asList(new MapTableField("__key", QueryDataType.INT, false, QueryPath.KEY_PATH), new MapTableField("field1", field.getFieldConverterType(), false, new QueryPath("field1", false)));
    HazelcastTable table = partitionedTable(MAP_NAME, mapTableFields, getPartitionedMapIndexes(mapContainer(instance().getMap(MAP_NAME)), mapTableFields), 1);
    Result optimizationResult = optimizePhysical(statement.getSql(), parameterTypes, table);
    assertPlan(optimizationResult.getLogical(), plan(planRow(0, FullScanLogicalRel.class)));
    assertPlan(optimizationResult.getPhysical(), plan(planRow(0, expectedIndexUsage ? IndexScanMapPhysicalRel.class : FullScanPhysicalRel.class)));
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) 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) 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)

Aggregations

QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)61 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)23 MappingField (com.hazelcast.sql.impl.schema.MappingField)17 ArrayList (java.util.ArrayList)16 TableField (com.hazelcast.sql.impl.schema.TableField)14 MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)13 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)10 RelDataType (org.apache.calcite.rel.type.RelDataType)7 OptimizerTestSupport (com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport)6 IndexScanMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel)6 FullScanPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.FullScanPhysicalRel)5 Nonnull (javax.annotation.Nonnull)5 IndexEqualsFilter (com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter)4 Test (org.junit.Test)4 IndexType (com.hazelcast.config.IndexType)3 KvMetadata (com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 HashMap (java.util.HashMap)3 List (java.util.List)3