Java Code Examples for org.apache.calcite.rel.metadata.RelMetadataQuery#getTableOrigin()
The following examples show how to use
org.apache.calcite.rel.metadata.RelMetadataQuery#getTableOrigin() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoptOptimizeJoinRule.java From Bats with Apache License 2.0 | 6 votes |
/** * Retrieves join factors that correspond to simple table references. A * simple table reference is a single table reference with no grouping or * aggregation. * * @param multiJoin join factors being optimized * * @return map consisting of the simple factors and the tables they * correspond */ private Map<Integer, RelOptTable> getSimpleFactors(RelMetadataQuery mq, LoptMultiJoin multiJoin) { final Map<Integer, RelOptTable> returnList = new HashMap<>(); // Loop through all join factors and locate the ones where each // column referenced from the factor is not derived and originates // from the same underlying table. Also, discard factors that // are null-generating or will be removed because of semijoins. if (multiJoin.getMultiJoinRel().isFullOuterJoin()) { return returnList; } for (int factIdx = 0; factIdx < multiJoin.getNumJoinFactors(); factIdx++) { if (multiJoin.isNullGenerating(factIdx) || (multiJoin.getJoinRemovalFactor(factIdx) != null)) { continue; } final RelNode rel = multiJoin.getJoinFactor(factIdx); final RelOptTable table = mq.getTableOrigin(rel); if (table != null) { returnList.put(factIdx, table); } } return returnList; }
Example 2
Source File: LoptOptimizeJoinRule.java From Bats with Apache License 2.0 | 6 votes |
/** * Determines whether a join is a removable self-join. It is if it's an * inner join between identical, simple factors and the equality portion of * the join condition consists of the same set of unique keys. * * @param joinRel the join * * @return true if the join is removable */ public static boolean isRemovableSelfJoin(Join joinRel) { final RelNode left = joinRel.getLeft(); final RelNode right = joinRel.getRight(); if (joinRel.getJoinType() != JoinRelType.INNER) { return false; } // Make sure the join is between the same simple factor final RelMetadataQuery mq = joinRel.getCluster().getMetadataQuery(); final RelOptTable leftTable = mq.getTableOrigin(left); if (leftTable == null) { return false; } final RelOptTable rightTable = mq.getTableOrigin(right); if (rightTable == null) { return false; } if (!leftTable.getQualifiedName().equals(rightTable.getQualifiedName())) { return false; } // Determine if the join keys are identical and unique return areSelfJoinKeysUnique(mq, left, right, joinRel.getCondition()); }
Example 3
Source File: LoptOptimizeJoinRule.java From calcite with Apache License 2.0 | 6 votes |
/** * Retrieves join factors that correspond to simple table references. A * simple table reference is a single table reference with no grouping or * aggregation. * * @param multiJoin join factors being optimized * * @return map consisting of the simple factors and the tables they * correspond */ private Map<Integer, RelOptTable> getSimpleFactors(RelMetadataQuery mq, LoptMultiJoin multiJoin) { final Map<Integer, RelOptTable> returnList = new HashMap<>(); // Loop through all join factors and locate the ones where each // column referenced from the factor is not derived and originates // from the same underlying table. Also, discard factors that // are null-generating or will be removed because of semijoins. if (multiJoin.getMultiJoinRel().isFullOuterJoin()) { return returnList; } for (int factIdx = 0; factIdx < multiJoin.getNumJoinFactors(); factIdx++) { if (multiJoin.isNullGenerating(factIdx) || (multiJoin.getJoinRemovalFactor(factIdx) != null)) { continue; } final RelNode rel = multiJoin.getJoinFactor(factIdx); final RelOptTable table = mq.getTableOrigin(rel); if (table != null) { returnList.put(factIdx, table); } } return returnList; }
Example 4
Source File: LoptOptimizeJoinRule.java From calcite with Apache License 2.0 | 6 votes |
/** * Determines whether a join is a removable self-join. It is if it's an * inner join between identical, simple factors and the equality portion of * the join condition consists of the same set of unique keys. * * @param joinRel the join * * @return true if the join is removable */ public static boolean isRemovableSelfJoin(Join joinRel) { final RelNode left = joinRel.getLeft(); final RelNode right = joinRel.getRight(); if (joinRel.getJoinType().isOuterJoin()) { return false; } // Make sure the join is between the same simple factor final RelMetadataQuery mq = joinRel.getCluster().getMetadataQuery(); final RelOptTable leftTable = mq.getTableOrigin(left); if (leftTable == null) { return false; } final RelOptTable rightTable = mq.getTableOrigin(right); if (rightTable == null) { return false; } if (!leftTable.getQualifiedName().equals(rightTable.getQualifiedName())) { return false; } // Determine if the join keys are identical and unique return areSelfJoinKeysUnique(mq, left, right, joinRel.getCondition()); }
Example 5
Source File: RelMetadataTest.java From calcite with Apache License 2.0 | 5 votes |
/** Tests calling {@link RelMetadataQuery#getTableOrigin} for * an aggregate with no columns. Previously threw. */ @Test void testEmptyAggregateTableOrigin() { final FrameworkConfig config = RelBuilderTest.config().build(); final RelBuilder builder = RelBuilder.create(config); RelMetadataQuery mq = builder.getCluster().getMetadataQuery(); RelNode agg = builder .scan("EMP") .aggregate(builder.groupKey()) .build(); final RelOptTable tableOrigin = mq.getTableOrigin(agg); assertThat(tableOrigin, nullValue()); }