Search in sources :

Example 6 with TableField

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

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

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

Example 9 with TableField

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

the class TestAbstractSqlConnector method createTable.

@Nonnull
@Override
public Table createTable(@Nonnull NodeEngine nodeEngine, @Nonnull String schemaName, @Nonnull String mappingName, @Nonnull String externalName, @Nonnull Map<String, String> options, @Nonnull List<MappingField> resolvedFields) {
    String[] names = options.get(OPTION_NAMES).split(DELIMITER);
    String[] types = options.get(OPTION_TYPES).split(DELIMITER);
    assert names.length == types.length;
    List<TableField> fields = new ArrayList<>(names.length);
    for (int i = 0; i < names.length; i++) {
        fields.add(new TableField(names[i], resolveTypeForTypeFamily(QueryDataTypeFamily.valueOf(types[i])), false));
    }
    List<Object[]> rows = new ArrayList<>();
    String[] rowsSerialized = options.get(OPTION_VALUES).split(VALUES_DELIMITER);
    for (String rowSerialized : rowsSerialized) {
        if (rowSerialized.isEmpty()) {
            continue;
        }
        String[] values = rowSerialized.split(DELIMITER);
        assert values.length == fields.size();
        Object[] row = new Object[values.length];
        for (int i = 0; i < values.length; i++) {
            String value = values[i];
            if (NULL.equals(value)) {
                row[i] = null;
            } else {
                row[i] = fields.get(i).getType().convert(values[i]);
            }
        }
        rows.add(row);
    }
    boolean streaming = Boolean.parseBoolean(options.get(OPTION_STREAMING));
    return new TestTable(this, schemaName, mappingName, fields, rows, streaming);
}
Also used : ArrayList(java.util.ArrayList) TableField(com.hazelcast.sql.impl.schema.TableField) Nonnull(javax.annotation.Nonnull)

Example 10 with TableField

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

the class PartitionedMapPlanObjectKeyTest method test_partitioned.

@Test
public void test_partitioned() {
    String schema1 = "schema1";
    String schema2 = "schema2";
    String tableName1 = "table1";
    String tableName2 = "table2";
    String mapName1 = "map1";
    String mapName2 = "map2";
    List<TableField> fields1 = singletonList(new MapTableField("field1", QueryDataType.INT, true, QueryPath.KEY_PATH));
    List<TableField> fields2 = singletonList(new MapTableField("field2", QueryDataType.INT, true, QueryPath.KEY_PATH));
    Set<String> conflictingSchemas1 = Collections.singleton("schema1");
    Set<String> conflictingSchemas2 = Collections.singleton("schema2");
    QueryTargetDescriptor keyDescriptor1 = GenericQueryTargetDescriptor.DEFAULT;
    QueryTargetDescriptor keyDescriptor2 = new TestTargetDescriptor();
    QueryTargetDescriptor valueDescriptor1 = GenericQueryTargetDescriptor.DEFAULT;
    QueryTargetDescriptor valueDescriptor2 = new TestTargetDescriptor();
    Object keyJetMetadata1 = new Object();
    Object valueJetMetadata1 = new Object();
    Object keyJetMetadata2 = new Object();
    Object valueJetMetadata2 = new Object();
    List<MapTableIndex> indexes1 = singletonList(new MapTableIndex("idx", IndexType.SORTED, 0, emptyList(), emptyList()));
    List<MapTableIndex> indexes2 = singletonList(new MapTableIndex("idx", IndexType.HASH, 0, emptyList(), emptyList()));
    boolean hd1 = false;
    boolean hd2 = true;
    PartitionedMapPlanObjectKey objectId = new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd1);
    checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd1), true);
    checkEquals(objectId, new PartitionedMapPlanObjectKey(schema2, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd1), false);
    checkEquals(objectId, new PartitionedMapPlanObjectKey(schema2, tableName2, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd1), false);
    checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName2, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd1), false);
    checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields2, conflictingSchemas1, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd1), false);
    checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas2, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd1), false);
    checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor2, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd1), false);
    checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor2, keyJetMetadata1, valueJetMetadata1, indexes1, hd1), false);
    checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor2, keyJetMetadata2, valueJetMetadata1, indexes1, hd1), false);
    checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor2, keyJetMetadata1, valueJetMetadata2, indexes1, hd1), false);
    checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes2, hd1), false);
    checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd2), false);
}
Also used : GenericQueryTargetDescriptor(com.hazelcast.sql.impl.extract.GenericQueryTargetDescriptor) QueryTargetDescriptor(com.hazelcast.sql.impl.extract.QueryTargetDescriptor) TableField(com.hazelcast.sql.impl.schema.TableField) PartitionedMapPlanObjectKey(com.hazelcast.sql.impl.schema.map.PartitionedMapTable.PartitionedMapPlanObjectKey) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

TableField (com.hazelcast.sql.impl.schema.TableField)22 MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)15 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)13 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)12 ArrayList (java.util.ArrayList)10 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)8 MappingField (com.hazelcast.sql.impl.schema.MappingField)7 KvMetadata (com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata)5 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 Nonnull (javax.annotation.Nonnull)3 Test (org.junit.Test)3 ConstantTableStatistics (com.hazelcast.sql.impl.schema.ConstantTableStatistics)2 Parameters (junitparams.Parameters)2 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)2 ImmutableList (com.google.common.collect.ImmutableList)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 Schema (com.hazelcast.internal.serialization.impl.compact.Schema)1 FilePlanObjectKey (com.hazelcast.jet.sql.impl.connector.file.FileTable.FilePlanObjectKey)1