Java Code Examples for org.apache.calcite.rel.RelDistributions#SINGLETON
The following examples show how to use
org.apache.calcite.rel.RelDistributions#SINGLETON .
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: RelMetadataTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testDistributionSingleton() { final RelNode rel = convertSql("select * from emp"); final RelDistribution dist = RelDistributions.SINGLETON; final LogicalExchange exchange = LogicalExchange.create(rel, dist); final RelMetadataQuery mq = rel.getCluster().getMetadataQuery(); RelDistribution d = mq.getDistribution(exchange); assertThat(d, is(dist)); }
Example 2
Source File: ExchangeRemoveConstantKeysRule.java From calcite with Apache License 2.0 | 4 votes |
@Override public void onMatch(RelOptRuleCall call) { final SortExchange sortExchange = call.rel(0); final RelMetadataQuery mq = call.getMetadataQuery(); final RelNode input = sortExchange.getInput(); final RelOptPredicateList predicates = mq.getPulledUpPredicates(input); if (predicates == null) { return; } final Set<Integer> constants = new HashSet<>(); predicates.constantMap.keySet().forEach(key -> { if (key instanceof RexInputRef) { constants.add(((RexInputRef) key).getIndex()); } }); if (constants.isEmpty()) { return; } List<Integer> distributionKeys = new ArrayList<>(); boolean distributionSimplified = false; boolean hashDistribution = sortExchange.getDistribution().getType() == RelDistribution.Type.HASH_DISTRIBUTED; if (hashDistribution) { distributionKeys = simplifyDistributionKeys( sortExchange.getDistribution(), constants); distributionSimplified = distributionKeys.size() != sortExchange.getDistribution().getKeys() .size(); } final List<RelFieldCollation> fieldCollations = sortExchange .getCollation().getFieldCollations().stream().filter( fc -> !constants.contains(fc.getFieldIndex())) .collect(Collectors.toList()); boolean collationSimplified = fieldCollations.size() != sortExchange.getCollation() .getFieldCollations().size(); if (distributionSimplified || collationSimplified) { RelDistribution distribution = distributionSimplified ? (distributionKeys.isEmpty() ? RelDistributions.SINGLETON : RelDistributions.hash(distributionKeys)) : sortExchange.getDistribution(); RelCollation collation = collationSimplified ? RelCollations.of(fieldCollations) : sortExchange.getCollation(); call.transformTo(call.builder() .push(sortExchange.getInput()) .sortExchange(distribution, collation) .build()); call.getPlanner().prune(sortExchange); } }
Example 3
Source File: RelMdDistribution.java From Bats with Apache License 2.0 | 2 votes |
/** Fallback method to deduce distribution for any relational expression not * handled by a more specific method. * * @param rel Relational expression * @return Relational expression's distribution */ public RelDistribution distribution(RelNode rel, RelMetadataQuery mq) { return RelDistributions.SINGLETON; }
Example 4
Source File: RelMdDistribution.java From calcite with Apache License 2.0 | 2 votes |
/** Fallback method to deduce distribution for any relational expression not * handled by a more specific method. * * @param rel Relational expression * @return Relational expression's distribution */ public RelDistribution distribution(RelNode rel, RelMetadataQuery mq) { return RelDistributions.SINGLETON; }