Search in sources :

Example 41 with HazelcastTable

use of com.hazelcast.jet.sql.impl.schema.HazelcastTable in project hazelcast by hazelcast.

the class LogicalSelectTest method test_selectByKeyWithProjectExpression.

@Test
public void test_selectByKeyWithProjectExpression() {
    HazelcastTable table = partitionedTable("m", asList(field(KEY, INT), field(VALUE, VARCHAR)), 1);
    assertPlan(optimizeLogical("SELECT this || '-s' FROM m WHERE __key = 1", table), plan(planRow(0, SelectByKeyMapLogicalRel.class)));
}
Also used : HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) Test(org.junit.Test)

Example 42 with HazelcastTable

use of com.hazelcast.jet.sql.impl.schema.HazelcastTable in project hazelcast by hazelcast.

the class LogicalStreamAggTest method test.

@Test
public void test() {
    HazelcastTable table = partitionedTable("map", asList(field(KEY, INT), field(VALUE, INT)), 1);
    List<QueryDataType> parameterTypes = asList(QueryDataType.INT, QueryDataType.INT);
    final String sql = "SELECT window_start, window_end, SUM(__key) FROM " + "TABLE(HOP(" + "  (SELECT * FROM TABLE(IMPOSE_ORDER((SELECT __key, this FROM map), DESCRIPTOR(__key), 1))), " + "DESCRIPTOR(__key), 2, 1)) " + "GROUP BY window_start, window_end, __key, this";
    assertPlan(optimizePhysical(sql, parameterTypes, table).getPhysical(), plan(planRow(0, ProjectPhysicalRel.class), planRow(1, AggregateCombineByKeyPhysicalRel.class), planRow(2, AggregateAccumulateByKeyPhysicalRel.class), planRow(3, ProjectPhysicalRel.class), planRow(4, SlidingWindowPhysicalRel.class), planRow(5, FullScanPhysicalRel.class)));
}
Also used : QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) Test(org.junit.Test)

Example 43 with HazelcastTable

use of com.hazelcast.jet.sql.impl.schema.HazelcastTable in project hazelcast by hazelcast.

the class PhysicalJoinTest method when_isSimpleJoin_then_useNestedLoopJoin.

@Test
public void when_isSimpleJoin_then_useNestedLoopJoin() {
    HazelcastTable tableLeft = partitionedTable("l", asList(field(KEY, INT), field(VALUE, INT)), 1);
    HazelcastTable tableRight = partitionedTable("r", asList(field(KEY, INT), field(VALUE, INT)), 1);
    String query = "SELECT * FROM l JOIN r ON l.__key = r.__key";
    assertPlan(optimizePhysical(query, asList(INT, INT, INT, INT), tableLeft, tableRight).getPhysical(), plan(planRow(0, JoinNestedLoopPhysicalRel.class), planRow(1, FullScanPhysicalRel.class), planRow(1, FullScanPhysicalRel.class)));
}
Also used : HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) Test(org.junit.Test)

Example 44 with HazelcastTable

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

use of com.hazelcast.jet.sql.impl.schema.HazelcastTable in project hazelcast by hazelcast.

the class LogicalDeleteTest method test_deleteByKeyWithLiteralExpression.

@Test
public void test_deleteByKeyWithLiteralExpression() {
    HazelcastTable table = partitionedTable("m", asList(field(KEY, INT), field(VALUE, VARCHAR)), 1);
    assertPlan(optimizeLogical("DELETE FROM m WHERE __key = 1 + 1", table), plan(planRow(0, DeleteByKeyMapLogicalRel.class)));
}
Also used : HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) Test(org.junit.Test)

Aggregations

HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)70 Test (org.junit.Test)48 TableField (com.hazelcast.sql.impl.schema.TableField)8 MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)8 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)8 IndexScanMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel)7 RexNode (org.apache.calcite.rex.RexNode)7 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)6 Parameters (junitparams.Parameters)6 OptimizerTestSupport (com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport)5 HazelcastRelOptTable (com.hazelcast.jet.sql.impl.schema.HazelcastRelOptTable)5 ArrayList (java.util.ArrayList)5 FullScanPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.FullScanPhysicalRel)4 RelOptTable (org.apache.calcite.plan.RelOptTable)4 RelTraitSet (org.apache.calcite.plan.RelTraitSet)3 RelCollation (org.apache.calcite.rel.RelCollation)3 RelNode (org.apache.calcite.rel.RelNode)3 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)3 SqlValidatorTable (org.apache.calcite.sql.validate.SqlValidatorTable)3 RexBuilder (org.apache.calcite.rex.RexBuilder)2