本文整理汇总了Java中org.apache.calcite.rex.RexInputRef.of方法的典型用法代码示例。如果您正苦于以下问题:Java RexInputRef.of方法的具体用法?Java RexInputRef.of怎么用?Java RexInputRef.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.rex.RexInputRef
的用法示例。
在下文中一共展示了RexInputRef.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getExpressionLineage
import org.apache.calcite.rex.RexInputRef; //导入方法依赖的package包/类
/**
* Expression lineage from {@link TableScan}.
*
* <p>We extract the fields referenced by the expression and we express them
* using {@link RexTableInputRef}.
*/
public Set<RexNode> getExpressionLineage(TableScan rel,
RelMetadataQuery mq, RexNode outputExpression) {
final RexBuilder rexBuilder = rel.getCluster().getRexBuilder();
// Extract input fields referenced by expression
final Set<RelDataTypeField> inputExtraFields = new LinkedHashSet<>();
final RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(inputExtraFields);
outputExpression.accept(inputFinder);
final ImmutableBitSet inputFieldsUsed = inputFinder.inputBitSet.build();
// Infer column origin expressions for given references
final Map<RexInputRef, Set<RexNode>> mapping = new LinkedHashMap<>();
for (int idx : inputFieldsUsed) {
final RexNode inputRef = RexTableInputRef.of(
RelTableRef.of(rel.getTable(), 0),
RexInputRef.of(idx, rel.getRowType().getFieldList()));
final Set<RexNode> originalExprs = Sets.newHashSet(inputRef);
final RexInputRef ref = RexInputRef.of(idx, rel.getRowType().getFieldList());
mapping.put(ref, originalExprs);
}
// Return result
return createAllPossibleExpressions(rexBuilder, outputExpression, mapping);
}
示例2: testExpressionLineageTwoColumns
import org.apache.calcite.rex.RexInputRef; //导入方法依赖的package包/类
@Test public void testExpressionLineageTwoColumns() {
// mgr is column 3 in catalog.sales.emp
// deptno is column 7 in catalog.sales.emp
final RelNode rel = convertSql("select mgr, deptno from emp");
final RelMetadataQuery mq = RelMetadataQuery.instance();
final RexNode ref1 = RexInputRef.of(0, rel.getRowType().getFieldList());
final Set<RexNode> r1 = mq.getExpressionLineage(rel, ref1);
assertThat(r1.size(), is(1));
final RexTableInputRef result1 = (RexTableInputRef) r1.iterator().next();
assertTrue(result1.getQualifiedName().equals(EMP_QNAME));
assertThat(result1.getIndex(), is(3));
final RexNode ref2 = RexInputRef.of(1, rel.getRowType().getFieldList());
final Set<RexNode> r2 = mq.getExpressionLineage(rel, ref2);
assertThat(r2.size(), is(1));
final RexTableInputRef result2 = (RexTableInputRef) r2.iterator().next();
assertTrue(result2.getQualifiedName().equals(EMP_QNAME));
assertThat(result2.getIndex(), is(7));
assertThat(result1.getIdentifier(), is(result2.getIdentifier()));
}
示例3: testExpressionLineageTwoColumnsSwapped
import org.apache.calcite.rex.RexInputRef; //导入方法依赖的package包/类
@Test public void testExpressionLineageTwoColumnsSwapped() {
// deptno is column 7 in catalog.sales.emp
// mgr is column 3 in catalog.sales.emp
final RelNode rel = convertSql("select deptno, mgr from emp");
final RelMetadataQuery mq = RelMetadataQuery.instance();
final RexNode ref1 = RexInputRef.of(0, rel.getRowType().getFieldList());
final Set<RexNode> r1 = mq.getExpressionLineage(rel, ref1);
assertThat(r1.size(), is(1));
final RexTableInputRef result1 = (RexTableInputRef) r1.iterator().next();
assertTrue(result1.getQualifiedName().equals(EMP_QNAME));
assertThat(result1.getIndex(), is(7));
final RexNode ref2 = RexInputRef.of(1, rel.getRowType().getFieldList());
final Set<RexNode> r2 = mq.getExpressionLineage(rel, ref2);
assertThat(r2.size(), is(1));
final RexTableInputRef result2 = (RexTableInputRef) r2.iterator().next();
assertTrue(result2.getQualifiedName().equals(EMP_QNAME));
assertThat(result2.getIndex(), is(3));
assertThat(result1.getIdentifier(), is(result2.getIdentifier()));
}
示例4: testExpressionLineageCombineTwoColumns
import org.apache.calcite.rex.RexInputRef; //导入方法依赖的package包/类
@Test public void testExpressionLineageCombineTwoColumns() {
// empno is column 0 in catalog.sales.emp
// deptno is column 7 in catalog.sales.emp
final RelNode rel = convertSql("select empno + deptno from emp");
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 RexNode result = r.iterator().next();
assertThat(result.getKind(), is(SqlKind.PLUS));
final RexCall call = (RexCall) result;
assertThat(call.getOperands().size(), is(2));
final RexTableInputRef inputRef1 = (RexTableInputRef) call.getOperands().get(0);
assertTrue(inputRef1.getQualifiedName().equals(EMP_QNAME));
assertThat(inputRef1.getIndex(), is(0));
final RexTableInputRef inputRef2 = (RexTableInputRef) call.getOperands().get(1);
assertTrue(inputRef2.getQualifiedName().equals(EMP_QNAME));
assertThat(inputRef2.getIndex(), is(7));
assertThat(inputRef1.getIdentifier(), is(inputRef2.getIdentifier()));
}
示例5: testSplitJoinConditionExpandedIsNotDistinctFrom
import org.apache.calcite.rex.RexInputRef; //导入方法依赖的package包/类
/**
* Test {@link RelOptUtil#splitJoinCondition(RelNode, RelNode, RexNode, List, List, List)}
* where the join condition contains an expanded version of IS NOT DISTINCT
*/
@Test public void testSplitJoinConditionExpandedIsNotDistinctFrom() {
int leftJoinIndex = EMP_SCAN.getRowType().getFieldNames().indexOf("DEPTNO");
int rightJoinIndex = DEPT_ROW.getFieldNames().indexOf("DEPTNO");
RexInputRef leftKeyInputRef = RexInputRef.of(leftJoinIndex, EMP_DEPT_JOIN_REL_FIELDS);
RexInputRef rightKeyInputRef =
RexInputRef.of(EMP_ROW.getFieldCount() + rightJoinIndex, EMP_DEPT_JOIN_REL_FIELDS);
RexNode joinCond = REL_BUILDER.call(SqlStdOperatorTable.OR,
REL_BUILDER.call(SqlStdOperatorTable.EQUALS, leftKeyInputRef, rightKeyInputRef),
REL_BUILDER.call(SqlStdOperatorTable.AND,
REL_BUILDER.call(SqlStdOperatorTable.IS_NULL, leftKeyInputRef),
REL_BUILDER.call(SqlStdOperatorTable.IS_NULL, rightKeyInputRef)));
splitJoinConditionHelper(
joinCond,
Collections.singletonList(leftJoinIndex),
Collections.singletonList(rightJoinIndex),
Collections.singletonList(false),
REL_BUILDER.literal(true));
}
示例6: testExpressionLineageUnion
import org.apache.calcite.rex.RexInputRef; //导入方法依赖的package包/类
@Test public void testExpressionLineageUnion() {
// sal is column 5 in catalog.sales.emp
final RelNode rel = convertSql("select sal from (\n"
+ " select * from emp union all select * from emp) "
+ "where deptno = 10");
final RelNode tableRel = convertSql("select * from emp");
final RelMetadataQuery mq = RelMetadataQuery.instance();
final RexNode ref = RexInputRef.of(0, rel.getRowType().getFieldList());
final Set<RexNode> r = mq.getExpressionLineage(rel, ref);
final String inputRef = RexInputRef.of(5, tableRel.getRowType().getFieldList()).toString();
assertThat(r.size(), is(2));
for (RexNode result : r) {
final String resultString = result.toString();
assertThat(resultString, startsWith(EMP_QNAME.toString()));
assertThat(resultString, endsWith(inputRef));
}
Iterator<RexNode> it = r.iterator();
assertThat(((RexTableInputRef) it.next()).getIdentifier(),
not(((RexTableInputRef) it.next()).getIdentifier()));
}
示例7: getAllPredicates
import org.apache.calcite.rex.RexInputRef; //导入方法依赖的package包/类
/**
* Add the Filter condition to the list obtained from the input.
*/
public RelOptPredicateList getAllPredicates(Filter filter, RelMetadataQuery mq) {
final RelNode input = filter.getInput();
final RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
final RexNode pred = filter.getCondition();
final RelOptPredicateList predsBelow = mq.getAllPredicates(input);
if (predsBelow == null) {
// Safety check
return null;
}
// Extract input fields referenced by Filter condition
final Set<RelDataTypeField> inputExtraFields = new LinkedHashSet<>();
final RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(inputExtraFields);
pred.accept(inputFinder);
final ImmutableBitSet inputFieldsUsed = inputFinder.inputBitSet.build();
// Infer column origin expressions for given references
final Map<RexInputRef, Set<RexNode>> mapping = new LinkedHashMap<>();
for (int idx : inputFieldsUsed) {
final RexInputRef ref = RexInputRef.of(idx, filter.getRowType().getFieldList());
final Set<RexNode> originalExprs = mq.getExpressionLineage(filter, ref);
if (originalExprs == null) {
// Bail out
return null;
}
mapping.put(ref, originalExprs);
}
// Replace with new expressions and return union of predicates
return predsBelow.union(rexBuilder,
RelOptPredicateList.of(rexBuilder,
RelMdExpressionLineage.createAllPossibleExpressions(rexBuilder, pred, mapping)));
}
示例8: testExpressionLineageStar
import org.apache.calcite.rex.RexInputRef; //导入方法依赖的package包/类
@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));
}
示例9: testExpressionLineageInnerJoinLeft
import org.apache.calcite.rex.RexInputRef; //导入方法依赖的package包/类
@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));
}
示例10: testExpressionLineageSelfJoin
import org.apache.calcite.rex.RexInputRef; //导入方法依赖的package包/类
@Test public void testExpressionLineageSelfJoin() {
// deptno is column 7 in catalog.sales.emp
// sal is column 5 in catalog.sales.emp
final RelNode rel = convertSql("select a.deptno, b.sal from (select * from emp limit 7) as a\n"
+ "inner join (select * from emp limit 2) as b\n"
+ "on a.deptno = b.deptno");
final RelNode tableRel = convertSql("select * from emp");
final RelMetadataQuery mq = RelMetadataQuery.instance();
final RexNode ref1 = RexInputRef.of(0, rel.getRowType().getFieldList());
final Set<RexNode> r1 = mq.getExpressionLineage(rel, ref1);
final String inputRef1 = RexInputRef.of(7, tableRel.getRowType().getFieldList()).toString();
assertThat(r1.size(), is(1));
final String resultString1 = r1.iterator().next().toString();
assertThat(resultString1, startsWith(EMP_QNAME.toString()));
assertThat(resultString1, endsWith(inputRef1));
final RexNode ref2 = RexInputRef.of(1, rel.getRowType().getFieldList());
final Set<RexNode> r2 = mq.getExpressionLineage(rel, ref2);
final String inputRef2 = RexInputRef.of(5, tableRel.getRowType().getFieldList()).toString();
assertThat(r2.size(), is(1));
final String resultString2 = r2.iterator().next().toString();
assertThat(resultString2, startsWith(EMP_QNAME.toString()));
assertThat(resultString2, endsWith(inputRef2));
assertThat(((RexTableInputRef) r1.iterator().next()).getIdentifier(),
not(((RexTableInputRef) r2.iterator().next()).getIdentifier()));
}
示例11: testExpressionLineageOuterJoin
import org.apache.calcite.rex.RexInputRef; //导入方法依赖的package包/类
@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);
}
示例12: testExpressionLineageFilter
import org.apache.calcite.rex.RexInputRef; //导入方法依赖的package包/类
@Test public void testExpressionLineageFilter() {
// ename is column 1 in catalog.sales.emp
final RelNode rel = convertSql("select ename from emp where deptno = 10");
final RelNode tableRel = convertSql("select * from emp");
final RelMetadataQuery mq = RelMetadataQuery.instance();
final RexNode ref = RexInputRef.of(0, rel.getRowType().getFieldList());
final Set<RexNode> r = mq.getExpressionLineage(rel, ref);
final String inputRef = RexInputRef.of(1, 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));
}
示例13: testExpressionLineageAggregateGroupColumn
import org.apache.calcite.rex.RexInputRef; //导入方法依赖的package包/类
@Test public void testExpressionLineageAggregateGroupColumn() {
// deptno is column 7 in catalog.sales.emp
final RelNode rel = convertSql("select deptno, count(*) from emp where deptno > 10 "
+ "group by deptno having count(*) = 0");
final RelNode tableRel = convertSql("select * from emp");
final RelMetadataQuery mq = RelMetadataQuery.instance();
final RexNode ref = RexInputRef.of(0, rel.getRowType().getFieldList());
final Set<RexNode> r = mq.getExpressionLineage(rel, ref);
final String inputRef = RexInputRef.of(7, 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));
}
示例14: testExpressionLineageAggregateAggColumn
import org.apache.calcite.rex.RexInputRef; //导入方法依赖的package包/类
@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);
}
示例15: testExpressionLineageMultiUnion
import org.apache.calcite.rex.RexInputRef; //导入方法依赖的package包/类
@Test public void testExpressionLineageMultiUnion() {
// empno is column 0 in catalog.sales.emp
// sal is column 5 in catalog.sales.emp
final RelNode rel = convertSql("select a.empno + b.sal from \n"
+ " (select empno, ename from emp,dept) a join "
+ " (select * from emp union all select * from emp) b \n"
+ " on a.empno = b.empno \n"
+ " where b.deptno = 10");
final RelMetadataQuery mq = RelMetadataQuery.instance();
final RexNode ref = RexInputRef.of(0, rel.getRowType().getFieldList());
final Set<RexNode> r = mq.getExpressionLineage(rel, ref);
// With the union, we should get two origins
// The first one should be the same one: join
// The second should come from each union input
final Set<List<String>> set = new HashSet<>();
assertThat(r.size(), is(2));
for (RexNode result : r) {
assertThat(result.getKind(), is(SqlKind.PLUS));
final RexCall call = (RexCall) result;
assertThat(call.getOperands().size(), is(2));
final RexTableInputRef inputRef1 = (RexTableInputRef) call.getOperands().get(0);
assertTrue(inputRef1.getQualifiedName().equals(EMP_QNAME));
// Add join alpha to set
set.add(inputRef1.getQualifiedName());
assertThat(inputRef1.getIndex(), is(0));
final RexTableInputRef inputRef2 = (RexTableInputRef) call.getOperands().get(1);
assertTrue(inputRef2.getQualifiedName().equals(EMP_QNAME));
assertThat(inputRef2.getIndex(), is(5));
assertThat(inputRef1.getIdentifier(), not(inputRef2.getIdentifier()));
}
assertThat(set.size(), is(1));
}