use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class IgniteSqlValidator method createSourceSelectForUpdate.
/**
* {@inheritDoc}
*/
@Override
protected SqlSelect createSourceSelectForUpdate(SqlUpdate call) {
final SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO);
final SqlIdentifier targetTable = (SqlIdentifier) call.getTargetTable();
final SqlValidatorTable table = getCatalogReader().getTable(targetTable.names);
SqlIdentifier alias = call.getAlias() != null ? call.getAlias() : new SqlIdentifier(deriveAlias(targetTable, 0), SqlParserPos.ZERO);
table.unwrap(IgniteTable.class).descriptor().selectForUpdateRowType((IgniteTypeFactory) typeFactory).getFieldNames().stream().map(name -> alias.plus(name, SqlParserPos.ZERO)).forEach(selectList::add);
int ordinal = 0;
// Force unique aliases to avoid a duplicate for Y with SET X=Y
for (SqlNode exp : call.getSourceExpressionList()) {
selectList.add(SqlValidatorUtil.addAlias(exp, SqlUtil.deriveAliasFromOrdinal(ordinal++)));
}
SqlNode sourceTable = call.getTargetTable();
if (call.getAlias() != null) {
sourceTable = SqlValidatorUtil.addAlias(sourceTable, call.getAlias().getSimple());
}
return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable, call.getCondition(), null, null, null, null, null, null, null);
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class ProjectableFilterableTableScan method pushUpPredicate.
/**
* PushUpPredicate.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
public RexNode pushUpPredicate() {
if (condition == null || projects == null) {
return replaceLocalRefs(condition);
}
IgniteTypeFactory typeFactory = Commons.typeFactory(getCluster());
IgniteTable tbl = getTable().unwrap(IgniteTable.class);
Mappings.TargetMapping mapping = RexUtils.inversePermutation(projects, tbl.getRowType(typeFactory, requiredColumns), true);
RexShuttle shuttle = new RexShuttle() {
@Override
public RexNode visitLocalRef(RexLocalRef ref) {
int targetRef = mapping.getSourceOpt(ref.getIndex());
if (targetRef == -1) {
throw new ControlFlowException();
}
return new RexInputRef(targetRef, ref.getType());
}
};
List<RexNode> conjunctions = new ArrayList<>();
for (RexNode conjunction : RelOptUtil.conjunctions(condition)) {
try {
conjunctions.add(shuttle.apply(conjunction));
} catch (ControlFlowException ignore) {
// No-op
}
}
return RexUtil.composeConjunction(builder(getCluster()), conjunctions, true);
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class AbstractAggregatePlannerTest method createBroadcastTable.
/**
* CreateBroadcastTable.
*
* @return REPLICATED test table (ID, VAL0, VAL1, GRP0, GRP1)
*/
@NotNull
protected TestTable createBroadcastTable() {
IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
TestTable tbl = new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("VAL0", f.createJavaType(Integer.class)).add("VAL1", f.createJavaType(Integer.class)).add("GRP0", f.createJavaType(Integer.class)).add("GRP1", f.createJavaType(Integer.class)).build()) {
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.broadcast();
}
};
return tbl;
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class CorrelatedNestedLoopJoinPlannerTest method testInvalidIndexExpressions.
/**
* Check join with not equi condition. Current implementation of the CorrelatedNestedLoopJoinTest is not applicable
* for such case.
*/
@Test
public void testInvalidIndexExpressions() throws Exception {
IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
publicSchema.addTable("T0", new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("JID", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.broadcast();
}
}.addIndex(RelCollations.of(ImmutableIntList.of(1, 0)), "t0_jid_idx"));
publicSchema.addTable("T1", new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("JID", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.broadcast();
}
}.addIndex(RelCollations.of(ImmutableIntList.of(1, 0)), "t1_jid_idx"));
String sql = "select * " + "from t0 " + "join t1 on t0.jid + 2 > t1.jid * 2";
IgniteRel phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "NestedLoopJoinConverter", "FilterSpoolMergeRule");
assertNotNull(phys);
}
use of org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory in project ignite-3 by apache.
the class HashAggregatePlannerTest method subqueryWithAggregate.
/**
* SubqueryWithAggregate.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*
* @throws Exception If failed.
*/
@Test
public void subqueryWithAggregate() throws Exception {
IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
TestTable employer = new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("NAME", f.createJavaType(String.class)).add("SALARY", f.createJavaType(Double.class)).build()) {
@Override
public IgniteDistribution distribution() {
return IgniteDistributions.affinity(0, "Employers", "hash");
}
};
IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
publicSchema.addTable("EMPS", employer);
String sql = "SELECT * FROM emps WHERE emps.salary = (SELECT AVG(emps.salary) FROM emps)";
IgniteRel phys = physicalPlan(sql, publicSchema);
assertNotNull(phys);
IgniteReduceHashAggregate rdcAgg = findFirstNode(phys, byClass(IgniteReduceHashAggregate.class));
IgniteMapHashAggregate mapAgg = findFirstNode(phys, byClass(IgniteMapHashAggregate.class));
assertNotNull(rdcAgg, "Invalid plan\n" + RelOptUtil.toString(phys));
assertNotNull(mapAgg, "Invalid plan\n" + RelOptUtil.toString(phys));
assertThat("Invalid plan\n" + RelOptUtil.toString(phys), first(rdcAgg.getAggregateCalls()).getAggregation(), IsInstanceOf.instanceOf(SqlAvgAggFunction.class));
assertThat("Invalid plan\n" + RelOptUtil.toString(phys), first(mapAgg.getAggCallList()).getAggregation(), IsInstanceOf.instanceOf(SqlAvgAggFunction.class));
}
Aggregations