use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class ProjectScanMergeRule method onMatch.
/**
* {@inheritDoc}
*/
@Override
public void onMatch(RelOptRuleCall call) {
LogicalProject relProject = call.rel(0);
T scan = call.rel(1);
RelOptCluster cluster = scan.getCluster();
List<RexNode> projects = relProject.getProjects();
RexNode cond = scan.condition();
ImmutableBitSet requiredColumns = scan.requiredColumns();
List<RexNode> scanProjects = scan.projects();
// Set default traits, real traits will be calculated for physical node.
RelTraitSet traits = cluster.traitSet();
IgniteTable tbl = scan.getTable().unwrap(IgniteTable.class);
IgniteTypeFactory typeFactory = Commons.typeFactory(cluster);
if (requiredColumns == null) {
assert scanProjects == null;
ImmutableBitSet.Builder builder = ImmutableBitSet.builder();
new RexShuttle() {
@Override
public RexNode visitInputRef(RexInputRef ref) {
builder.set(ref.getIndex());
return ref;
}
}.apply(projects);
new RexShuttle() {
@Override
public RexNode visitLocalRef(RexLocalRef inputRef) {
builder.set(inputRef.getIndex());
return inputRef;
}
}.apply(cond);
requiredColumns = builder.build();
Mappings.TargetMapping targetMapping = Commons.mapping(requiredColumns, tbl.getRowType(typeFactory).getFieldCount());
projects = new RexShuttle() {
@Override
public RexNode visitInputRef(RexInputRef ref) {
return new RexLocalRef(targetMapping.getTarget(ref.getIndex()), ref.getType());
}
}.apply(projects);
cond = new RexShuttle() {
@Override
public RexNode visitLocalRef(RexLocalRef ref) {
return new RexLocalRef(targetMapping.getTarget(ref.getIndex()), ref.getType());
}
}.apply(cond);
} else {
projects = RexUtils.replaceInputRefs(projects);
}
if (scanProjects != null) {
// Merge projects.
projects = new RexShuttle() {
@Override
public RexNode visitLocalRef(RexLocalRef ref) {
return scanProjects.get(ref.getIndex());
}
}.apply(projects);
}
if (RexUtils.isIdentity(projects, tbl.getRowType(typeFactory, requiredColumns), true)) {
projects = null;
}
call.transformTo(createNode(cluster, scan, traits, projects, cond, requiredColumns));
if (!RexUtils.hasCorrelation(relProject.getProjects())) {
cluster.getPlanner().prune(relProject);
}
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class ExpressionFactoryImplTest method prepare.
@BeforeEach
public void prepare() {
RelDataTypeSystem typeSys = CALCITE_CONNECTION_CONFIG.typeSystem(RelDataTypeSystem.class, IgniteTypeSystem.INSTANCE);
typeFactory = new IgniteTypeFactory(typeSys);
expFactory = new ExpressionFactoryImpl<>(null, typeFactory, SqlConformanceEnum.DEFAULT);
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class AbstractSetOpExecutionTest method testSingleWithEmptySet.
@Test
public void testSingleWithEmptySet() {
ExecutionContext<Object[]> ctx = executionContext();
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, String.class, int.class);
List<Object[]> data = Arrays.asList(row("Igor", 1), row("Roman", 1));
// For single distribution set operations, node should not request rows from the next source if result after
// the previous source is already empty.
ScanNode<Object[]> scan1 = new ScanNode<>(ctx, rowType, data);
ScanNode<Object[]> scan2 = new ScanNode<>(ctx, rowType, data);
ScanNode<Object[]> scan3 = new ScanNode<>(ctx, rowType, Collections.emptyList());
Node<Object[]> node4 = new AbstractNode<>(ctx, rowType) {
@Override
protected void rewindInternal() {
// No-op.
}
@Override
protected Downstream<Object[]> requestDownstream(int idx) {
return null;
}
@Override
public void request(int rowsCnt) {
fail("Node should not be requested");
}
};
List<Node<Object[]>> inputs = Arrays.asList(scan1, scan2, scan3, node4);
AbstractSetOpNode<Object[]> setOpNode = setOpNodeFactory(ctx, rowType, SINGLE, false, inputs.size());
setOpNode.register(inputs);
RootNode<Object[]> root = new RootNode<>(ctx, rowType);
root.register(setOpNode);
assertFalse(root.hasNext());
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class AbstractSetOpExecutionTest method checkSetOp.
/**
* CheckSetOp.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*
* @param single Single.
* @param all All.
*/
protected void checkSetOp(boolean single, boolean all, List<List<Object[]>> dataSets, List<Object[]> expectedResult) {
ExecutionContext<Object[]> ctx = executionContext();
IgniteTypeFactory tf = ctx.getTypeFactory();
RelDataType rowType = TypeUtils.createRowType(tf, String.class, int.class);
List<Node<Object[]>> inputs = dataSets.stream().map(ds -> new ScanNode<>(ctx, rowType, ds)).collect(Collectors.toList());
AbstractSetOpNode<Object[]> setOpNode;
if (single) {
setOpNode = setOpNodeFactory(ctx, rowType, SINGLE, all, inputs.size());
} else {
setOpNode = setOpNodeFactory(ctx, rowType, MAP, all, inputs.size());
}
setOpNode.register(inputs);
if (!single) {
AbstractSetOpNode<Object[]> reduceNode = setOpNodeFactory(ctx, rowType, REDUCE, all, 1);
reduceNode.register(Collections.singletonList(setOpNode));
setOpNode = reduceNode;
}
Comparator<Object[]> cmp = ctx.expressionFactory().comparator(RelCollations.of(ImmutableIntList.of(0, 1)));
// Create sort node on the top to check sorted results.
SortNode<Object[]> sortNode = new SortNode<>(ctx, rowType, cmp);
sortNode.register(setOpNode);
RootNode<Object[]> root = new RootNode<>(ctx, rowType);
root.register(sortNode);
assertTrue(nullOrEmpty(expectedResult) || root.hasNext());
for (Object[] row : expectedResult) {
assertArrayEquals(row, root.next());
}
assertFalse(root.hasNext());
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class TableDescriptorImpl method newColumnDefaultValue.
/**
* {@inheritDoc}
*/
@Override
public RexNode newColumnDefaultValue(RelOptTable tbl, int colIdx, InitializerContext ctx) {
final ColumnDescriptor desc = descriptors[colIdx];
if (!desc.hasDefaultValue()) {
return super.newColumnDefaultValue(tbl, colIdx, ctx);
}
final RexBuilder rexBuilder = ctx.getRexBuilder();
final IgniteTypeFactory typeFactory = (IgniteTypeFactory) rexBuilder.getTypeFactory();
return rexBuilder.makeLiteral(desc.defaultValue(), desc.logicalType(typeFactory), false);
}
Aggregations