Search in sources :

Example 61 with HazelcastTable

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

the class LogicalUpdateTest method test_updateWithConstantCondition.

@Test
public void test_updateWithConstantCondition() {
    HazelcastTable table = partitionedTable("m", asList(field(KEY, INT), field(VALUE, VARCHAR)), 10);
    assertPlan(optimizeLogical("UPDATE m SET this = '2' WHERE 1 = 1", table), plan(planRow(0, UpdateLogicalRel.class), planRow(1, FullScanLogicalRel.class)));
}
Also used : HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) Test(org.junit.Test)

Example 62 with HazelcastTable

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

the class LogicalUpdateTest method test_updateByKeyWithDynamicParamAndImplicitCastOnKey.

@Test
public void test_updateByKeyWithDynamicParamAndImplicitCastOnKey() {
    HazelcastTable table = partitionedTable("m", asList(field(KEY, INT), field(VALUE, VARCHAR)), 1);
    assertPlan(optimizeLogical("UPDATE m SET this = '2' WHERE __key = ? + 1", table), plan(planRow(0, UpdateLogicalRel.class), planRow(1, FullScanLogicalRel.class)));
}
Also used : HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) Test(org.junit.Test)

Example 63 with HazelcastTable

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

the class CalciteSqlOptimizer method extractPermissions.

private List<Permission> extractPermissions(PhysicalRel physicalRel) {
    List<Permission> permissions = new ArrayList<>();
    physicalRel.accept(new RelShuttleImpl() {

        @Override
        public RelNode visit(TableScan scan) {
            addPermissionForTable(scan.getTable(), ActionConstants.ACTION_READ);
            return super.visit(scan);
        }

        @Override
        public RelNode visit(RelNode other) {
            addPermissionForTable(other.getTable(), ActionConstants.ACTION_PUT);
            return super.visit(other);
        }

        private void addPermissionForTable(RelOptTable t, String action) {
            if (t == null) {
                return;
            }
            HazelcastTable table = t.unwrap(HazelcastTable.class);
            if (table != null && table.getTarget() instanceof AbstractMapTable) {
                String mapName = ((AbstractMapTable) table.getTarget()).getMapName();
                permissions.add(new MapPermission(mapName, action));
            }
        }
    });
    return permissions;
}
Also used : TableScan(org.apache.calcite.rel.core.TableScan) AbstractMapTable(com.hazelcast.sql.impl.schema.map.AbstractMapTable) RelNode(org.apache.calcite.rel.RelNode) MapPermission(com.hazelcast.security.permission.MapPermission) Permission(java.security.Permission) MapPermission(com.hazelcast.security.permission.MapPermission) ArrayList(java.util.ArrayList) RelShuttleImpl(org.apache.calcite.rel.RelShuttleImpl) RelOptTable(org.apache.calcite.plan.RelOptTable) SqlString(org.apache.calcite.sql.util.SqlString) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable)

Example 64 with HazelcastTable

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

the class FullScanPhysicalRel method computeSelfCost.

@Override
public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
    HazelcastTable table = getTable().unwrap(HazelcastTable.class);
    double totalRowCount = table.getStatistic().getRowCount() != null ? table.getTotalRowCount() : getTable().getRowCount();
    double filterRowCount = totalRowCount;
    if (table.getFilter() != null) {
        filterRowCount = CostUtils.adjustFilteredRowCount(totalRowCount, RelMdUtil.guessSelectivity(table.getFilter()));
    }
    return computeSelfCost(planner, totalRowCount, table.getFilter() != null, filterRowCount, table.getProjects().size());
}
Also used : HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable)

Example 65 with HazelcastTable

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

the class IndexResolver method createIndexScan.

private static IndexScanMapPhysicalRel createIndexScan(FullScanLogicalRel scan, MapTableIndex index, List<RexNode> conjunctions, List<IndexComponentFilter> filterDescriptors, List<Boolean> ascs) {
    // Collect filters and relevant expressions
    List<IndexFilter> filters = new ArrayList<>(filterDescriptors.size());
    Set<RexNode> exps = new HashSet<>();
    for (IndexComponentFilter filterDescriptor : filterDescriptors) {
        filters.add(filterDescriptor.getFilter());
        exps.addAll(filterDescriptor.getExpressions());
    }
    // Construct Calcite expressions.
    RexBuilder rexBuilder = scan.getCluster().getRexBuilder();
    RexNode exp = RexUtil.composeConjunction(rexBuilder, exps);
    List<RexNode> remainderConjunctiveExps = excludeNodes(conjunctions, exps);
    RexNode remainderExp = remainderConjunctiveExps.isEmpty() ? null : RexUtil.composeConjunction(rexBuilder, remainderConjunctiveExps);
    // Prepare traits
    RelTraitSet traitSet = scan.getTraitSet();
    // Make a collation trait
    RelCollation relCollation = buildCollationTrait(scan, index, ascs);
    traitSet = OptUtils.traitPlus(traitSet, relCollation);
    // Prepare table
    HazelcastRelOptTable originalRelTable = (HazelcastRelOptTable) scan.getTable();
    HazelcastTable originalHazelcastTable = OptUtils.extractHazelcastTable(scan);
    RelOptTable newRelTable = createRelTable(originalRelTable, originalHazelcastTable.withFilter(null), scan.getCluster().getTypeFactory());
    // Try composing the final filter out of the isolated component filters if possible
    IndexFilter filter = composeFilter(filters, index.getType(), index.getComponentsCount());
    if (filter == null) {
        return null;
    }
    // Construct the scan
    return new IndexScanMapPhysicalRel(scan.getCluster(), OptUtils.toPhysicalConvention(traitSet), newRelTable, index, filter, exp, remainderExp);
}
Also used : ArrayList(java.util.ArrayList) RelTraitSet(org.apache.calcite.plan.RelTraitSet) IndexScanMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel) RelCollation(org.apache.calcite.rel.RelCollation) HazelcastRelOptTable(com.hazelcast.jet.sql.impl.schema.HazelcastRelOptTable) RexBuilder(org.apache.calcite.rex.RexBuilder) IndexFilter(com.hazelcast.sql.impl.exec.scan.index.IndexFilter) RelOptTable(org.apache.calcite.plan.RelOptTable) HazelcastRelOptTable(com.hazelcast.jet.sql.impl.schema.HazelcastRelOptTable) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) RexNode(org.apache.calcite.rex.RexNode) HashSet(java.util.HashSet)

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