use of com.hazelcast.jet.sql.impl.schema.HazelcastTable in project hazelcast by hazelcast.
the class IndexResolver method buildCollationTrait.
/**
* Builds a collation with collation fields re-mapped according to the table projections.
*
* @param scan the logical map scan
* @param index the index
* @param ascs the collation of index fields
* @return the new collation trait
*/
private static RelCollation buildCollationTrait(FullScanLogicalRel scan, MapTableIndex index, List<Boolean> ascs) {
if (index.getType() != SORTED) {
return RelCollations.of(Collections.emptyList());
}
List<RelFieldCollation> fields = new ArrayList<>(index.getFieldOrdinals().size());
HazelcastTable table = OptUtils.extractHazelcastTable(scan);
// Extract those projections that are direct input field references. Only those can be used
// for index access
List<Integer> fieldProjects = table.getProjects().stream().filter(expr -> expr instanceof RexInputRef).map(inputRef -> ((RexInputRef) inputRef).getIndex()).collect(Collectors.toList());
for (int i = 0; i < index.getFieldOrdinals().size(); ++i) {
Integer indexFieldOrdinal = index.getFieldOrdinals().get(i);
int remappedIndexFieldOrdinal = fieldProjects.indexOf(indexFieldOrdinal);
if (remappedIndexFieldOrdinal == -1) {
// The field is not used in the query
break;
}
Direction direction = ascs.get(i) ? ASCENDING : DESCENDING;
RelFieldCollation fieldCollation = new RelFieldCollation(remappedIndexFieldOrdinal, direction);
fields.add(fieldCollation);
}
return RelCollations.of(fields);
}
use of com.hazelcast.jet.sql.impl.schema.HazelcastTable in project hazelcast by hazelcast.
the class IndexResolver method createFullIndexScan.
/**
* Creates an index scan without any filter.
*
* @param scan the original scan operator
* @param index available indexes
* @param ascs the collation of index fields
* @param nonEmptyCollation whether to filter out full index scan with no collation
* @return index scan or {@code null}
*/
private static RelNode createFullIndexScan(FullScanLogicalRel scan, MapTableIndex index, List<Boolean> ascs, boolean nonEmptyCollation) {
assert isIndexSupported(index);
RexNode scanFilter = OptUtils.extractHazelcastTable(scan).getFilter();
RelTraitSet traitSet = OptUtils.toPhysicalConvention(scan.getTraitSet());
RelCollation relCollation = buildCollationTrait(scan, index, ascs);
if (nonEmptyCollation && relCollation.getFieldCollations().size() == 0) {
// Don't make a full scan with empty collation
return null;
}
traitSet = OptUtils.traitPlus(traitSet, relCollation);
HazelcastRelOptTable originalRelTable = (HazelcastRelOptTable) scan.getTable();
HazelcastTable originalHazelcastTable = OptUtils.extractHazelcastTable(scan);
RelOptTable newRelTable = createRelTable(originalRelTable.getDelegate().getQualifiedName(), originalHazelcastTable.withFilter(null), scan.getCluster().getTypeFactory());
return new IndexScanMapPhysicalRel(scan.getCluster(), traitSet, newRelTable, index, null, null, scanFilter);
}
use of com.hazelcast.jet.sql.impl.schema.HazelcastTable 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)));
}
}
use of com.hazelcast.jet.sql.impl.schema.HazelcastTable in project hazelcast by hazelcast.
the class LogicalUpdateTest method test_updateByKeyOrKey.
@Test
public void test_updateByKeyOrKey() {
HazelcastTable table = partitionedTable("m", asList(field(KEY, INT), field(VALUE, VARCHAR)), 10);
assertPlan(optimizeLogical("UPDATE m SET this = '2' WHERE __key = 1 OR __key = 2", 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_updateByKeyWithDynamicParam.
@Test
@Parameters(method = "types")
public void test_updateByKeyWithDynamicParam(QueryDataType type) {
HazelcastTable table = partitionedTable("m", asList(field(KEY, type), field(VALUE, VARCHAR)), 1);
assertPlan(optimizeLogical("UPDATE m SET this = '2' WHERE __key = ?", table), plan(planRow(0, UpdateByKeyMapLogicalRel.class)));
}
Aggregations