public RexNode get(int index) { final int pos = posList.get(index); return RexInputRef.of(pos, rowType); } });
@Override public RexNode visitInputRef(RexInputRef inputRef) { return RexInputRef.of(inputRef.getIndex(), input.getRowType()); } }
/** * Translate a field access, possibly through a projection, to an underlying Druid dataSource. * * @param rowSignature row signature of underlying Druid dataSource * @param project projection, or null * @param fieldNumber number of the field to access * * @return row expression */ public static RexNode fromFieldAccess( final RowSignature rowSignature, final Project project, final int fieldNumber ) { if (project == null) { // I don't think the factory impl matters here. return RexInputRef.of(fieldNumber, rowSignature.getRelDataType(new JavaTypeFactoryImpl())); } else { return project.getChildExps().get(fieldNumber); } }
listBuilder.add(RexInputRef.of(key, leftPartialQuery.getRowType()));
belowProjectExprs.add(project.getChildExps().get(i)); belowProjectColumnNames.add(project.getRowType().getFieldNames().get(i)); topProjectExprs.add(RexInputRef.of(i, project.getRowType()));
protected MutableRel invert(MutableRel model, MutableRel input, MutableProject project) { LOGGER.trace("SubstitutionVisitor: invert:\nmodel: {}\ninput: {}\nproject: {}\n", model, input, project); if (project.getProjects().size() < model.getRowType().getFieldCount()) { throw MatchFailed.INSTANCE; } final List<RexNode> exprList = new ArrayList<>(); final RexBuilder rexBuilder = model.cluster.getRexBuilder(); for (RelDataTypeField field : model.getRowType().getFieldList()) { exprList.add(rexBuilder.makeZeroLiteral(field.getType())); } for (Ord<RexNode> expr : Ord.zip(project.getProjects())) { if (expr.e instanceof RexInputRef) { final int target = ((RexInputRef) expr.e).getIndex(); exprList.set(target, rexBuilder.ensureType(expr.e.getType(), RexInputRef.of(expr.i, input.rowType), false)); } else { throw MatchFailed.INSTANCE; } } return MutableProject.of(model.rowType, input, exprList); } }
belowProjectExprs.add(project.getChildExps().get(i)); belowProjectColumnNames.add(project.getRowType().getFieldNames().get(i)); topProjectExprs.add(RexInputRef.of(i, project.getRowType()));
conditions.add( rexBuilder.makeCall(callOp, RexInputRef.of(newLeftPos, newLeftOutput), new RexInputRef(newLeftFieldCount + newRightPos, newRightOutput.get(newRightPos).getType()))); new RexInputRef(newLeftFieldCount + newRightPos, newRightOutput.get(newRightPos).getType()), RexInputRef.of(newLeftPos, newLeftOutput)));
conditions.add( rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, RexInputRef.of(newLeftPos, newLeftOutput), new RexInputRef(newLeftFieldCount + newRightPos, newRightOutput.get(newRightPos).getType())));
public RexNode get(int index) { final int pos = posList.get(index); return RexInputRef.of(pos, rowType); } });
/** * Creates a reference to a given field in a row type. */ public static RexInputRef of(int index, RelDataType rowType) { return of(index, rowType.getFieldList()); }
public RexNode rexFilterArgument() { return agg.call.filterArg < 0 ? null : RexInputRef.of(agg.call.filterArg, inputPhysType.getRowType()); }
@Override public RexNode get(int index) { if (index < originalFieldSize) { return RexInputRef.of(index, inputRowType.getFieldList()); } else { return colRefStarExprs.get(index - originalFieldSize); } } };
@Override public RexNode visitInputRef(RexInputRef inputRef) { assert mapOldToNewIndex.containsKey(inputRef.getIndex()); int newIndex = mapOldToNewIndex.get(inputRef.getIndex()); final RexInputRef ref = RexInputRef.of(newIndex, rowType); if (ref.getIndex() == inputRef.getIndex() && ref.getType() == inputRef.getType()) { return inputRef; // re-use old object, to prevent needless expr cloning } else { return ref; } } });
@Test public void testExpressionLineageInnerJoinRight() { // ename is column 0 in catalog.sales.bonus final RelNode rel = convertSql("select bonus.ename from emp join bonus using (ename)"); final RelMetadataQuery mq = RelMetadataQuery.instance(); final RexNode ref = RexInputRef.of(0, rel.getRowType().getFieldList()); final Set<RexNode> r = mq.getExpressionLineage(rel, ref); assertThat(r.size(), is(1)); final RexTableInputRef result = (RexTableInputRef) r.iterator().next(); assertTrue(result.getQualifiedName().equals(ImmutableList.of("CATALOG", "SALES", "BONUS"))); assertThat(result.getIndex(), is(0)); }
@Test public void testExpressionLineageInnerJoinLeft() { // ename is column 1 in catalog.sales.emp final RelNode rel = convertSql("select ename from emp,dept"); final RelMetadataQuery mq = RelMetadataQuery.instance(); final RexNode ref = RexInputRef.of(0, rel.getRowType().getFieldList()); final Set<RexNode> r = mq.getExpressionLineage(rel, ref); assertThat(r.size(), is(1)); final RexTableInputRef result = (RexTableInputRef) r.iterator().next(); assertTrue(result.getQualifiedName().equals(EMP_QNAME)); assertThat(result.getIndex(), is(1)); }
@Test public void testExpressionLineageStar() { // All columns in output final RelNode tableRel = convertSql("select * from emp"); final RelMetadataQuery mq = RelMetadataQuery.instance(); final RexNode ref = RexInputRef.of(4, tableRel.getRowType().getFieldList()); final Set<RexNode> r = mq.getExpressionLineage(tableRel, ref); final String inputRef = RexInputRef.of(4, tableRel.getRowType().getFieldList()).toString(); assertThat(r.size(), is(1)); final String resultString = r.iterator().next().toString(); assertThat(resultString, startsWith(EMP_QNAME.toString())); assertThat(resultString, endsWith(inputRef)); }
@Test public void testExpressionLineageAggregateAggColumn() { // lineage cannot be determined final RelNode rel = convertSql("select deptno, count(*) from emp where deptno > 10 " + "group by deptno having count(*) = 0"); final RelMetadataQuery mq = RelMetadataQuery.instance(); final RexNode ref = RexInputRef.of(1, rel.getRowType().getFieldList()); final Set<RexNode> r = mq.getExpressionLineage(rel, ref); assertNull(r); }
@Test public void testExpressionLineageValues() { // lineage cannot be determined final RelNode rel = convertSql("select * from (values (1), (2)) as t(c)"); final RelMetadataQuery mq = RelMetadataQuery.instance(); final RexNode ref = RexInputRef.of(0, rel.getRowType().getFieldList()); final Set<RexNode> r = mq.getExpressionLineage(rel, ref); assertNull(r); }
@Test public void testExpressionLineageOuterJoin() { // lineage cannot be determined final RelNode rel = convertSql("select name as dname from emp left outer join dept" + " on emp.deptno = dept.deptno"); final RelMetadataQuery mq = RelMetadataQuery.instance(); final RexNode ref = RexInputRef.of(0, rel.getRowType().getFieldList()); final Set<RexNode> r = mq.getExpressionLineage(rel, ref); assertNull(r); }