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)));
}
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)));
}
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;
}
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());
}
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);
}
Aggregations