calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject calcite git commit: [CALCITE-1076] Update RelMdDistribution to match other metadata APIs (Ted Xu)
Date Fri, 05 Feb 2016 11:45:21 GMT
Repository: calcite
Updated Branches:
  refs/heads/master 7e5710fc7 -> 4dfd6dbb2


[CALCITE-1076] Update RelMdDistribution to match other metadata APIs (Ted Xu)

Add RelMdDistribution to the list of standard metadata providers.

Add several tests for RelMdDistribution to RelMetadataTest.

Close apache/calcite#194


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/4dfd6dbb
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/4dfd6dbb
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/4dfd6dbb

Branch: refs/heads/master
Commit: 4dfd6dbb232718ca60b0a4885b6e37194cfdf3c7
Parents: 7e5710f
Author: 少杰 <shaojie@alibaba-inc.com>
Authored: Fri Feb 5 10:57:21 2016 +0800
Committer: Julian Hyde <jhyde@apache.org>
Committed: Fri Feb 5 00:26:17 2016 -0800

----------------------------------------------------------------------
 .../metadata/DefaultRelMetadataProvider.java    |  1 +
 .../calcite/rel/metadata/RelMdDistribution.java | 20 +++++-----
 .../calcite/rel/metadata/RelMetadataQuery.java  | 16 ++++++++
 .../apache/calcite/test/RelMetadataTest.java    | 40 ++++++++++++++++++++
 4 files changed, 67 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/4dfd6dbb/core/src/main/java/org/apache/calcite/rel/metadata/DefaultRelMetadataProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/DefaultRelMetadataProvider.java
b/core/src/main/java/org/apache/calcite/rel/metadata/DefaultRelMetadataProvider.java
index eddf9b9..e40f1d4 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/DefaultRelMetadataProvider.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/DefaultRelMetadataProvider.java
@@ -44,6 +44,7 @@ public class DefaultRelMetadataProvider extends ChainedRelMetadataProvider
{
             RelMdPopulationSize.SOURCE,
             RelMdSize.SOURCE,
             RelMdParallelism.SOURCE,
+            RelMdDistribution.SOURCE,
             RelMdMemory.SOURCE,
             RelMdDistinctRowCount.SOURCE,
             RelMdSelectivity.SOURCE,

http://git-wip-us.apache.org/repos/asf/calcite/blob/4dfd6dbb/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistribution.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistribution.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistribution.java
index f7b5c83..80f4e37 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistribution.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistribution.java
@@ -63,46 +63,46 @@ public class RelMdDistribution {
    * @param rel Relational expression
    * @return Relational expression's distribution
    */
-  public RelDistribution distribution(RelMetadataQuery mq, RelNode rel) {
+  public RelDistribution distribution(RelNode rel, RelMetadataQuery mq) {
     return RelDistributions.SINGLETON;
   }
 
-  public RelDistribution distribution(RelMetadataQuery mq, SingleRel rel) {
+  public RelDistribution distribution(SingleRel rel, RelMetadataQuery mq) {
     return mq.distribution(rel.getInput());
   }
 
-  public RelDistribution distribution(RelMetadataQuery mq, BiRel rel) {
+  public RelDistribution distribution(BiRel rel, RelMetadataQuery mq) {
     return mq.distribution(rel.getLeft());
   }
 
-  public RelDistribution distribution(RelMetadataQuery mq, SetOp rel) {
+  public RelDistribution distribution(SetOp rel, RelMetadataQuery mq) {
     return mq.distribution(rel.getInputs().get(0));
   }
 
-  public RelDistribution distribution(RelMetadataQuery mq, TableScan scan) {
+  public RelDistribution distribution(TableScan scan, RelMetadataQuery mq) {
     return table(scan.getTable());
   }
 
-  public RelDistribution distribution(RelMetadataQuery mq, Project project) {
+  public RelDistribution distribution(Project project, RelMetadataQuery mq) {
     return project(mq, project.getInput(), project.getProjects());
   }
 
-  public RelDistribution distribution(RelMetadataQuery mq, Values values) {
+  public RelDistribution distribution(Values values, RelMetadataQuery mq) {
     return values(values.getRowType(), values.getTuples());
   }
 
-  public RelDistribution distribution(RelMetadataQuery mq, Exchange exchange) {
+  public RelDistribution distribution(Exchange exchange, RelMetadataQuery mq) {
     return exchange(exchange.distribution);
   }
 
-  public RelDistribution distribution(RelMetadataQuery mq, HepRelVertex rel) {
+  public RelDistribution distribution(HepRelVertex rel, RelMetadataQuery mq) {
     return mq.distribution(rel.getCurrentRel());
   }
 
   // Helper methods
 
   /** Helper method to determine a
-   * {@link TableScan}'s collation. */
+   * {@link TableScan}'s distribution. */
   public static RelDistribution table(RelOptTable table) {
     return table.getDistribution();
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/4dfd6dbb/core/src/main/java/org/apache/calcite/rel/metadata/RelMetadataQuery.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMetadataQuery.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMetadataQuery.java
index f4eb748..b6eed5b 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMetadataQuery.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMetadataQuery.java
@@ -549,6 +549,22 @@ public abstract class RelMetadataQuery {
     return b == null || b;
   }
 
+  /**
+   * Returns the
+   * {@link BuiltInMetadata.Distribution#distribution()}
+   * statistic.
+   *
+   * @param rel          the relational expression
+   *
+   * @return description of how the rows in the relational expression are
+   * physically distributed
+   */
+  public RelDistribution getDistribution(RelNode rel) {
+    final BuiltInMetadata.Distribution metadata =
+        rel.metadata(BuiltInMetadata.Distribution.class, this);
+    return metadata.distribution();
+  }
+
   private static boolean isPercentage(Double result, boolean fail) {
     if (result != null) {
       final double d = result;

http://git-wip-us.apache.org/repos/asf/calcite/blob/4dfd6dbb/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
index 96cd23b..56c458e 100644
--- a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
@@ -26,6 +26,8 @@ import org.apache.calcite.rel.InvalidRelException;
 import org.apache.calcite.rel.RelCollation;
 import org.apache.calcite.rel.RelCollationTraitDef;
 import org.apache.calcite.rel.RelCollations;
+import org.apache.calcite.rel.RelDistribution;
+import org.apache.calcite.rel.RelDistributions;
 import org.apache.calcite.rel.RelFieldCollation;
 import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.RelRoot;
@@ -38,6 +40,7 @@ import org.apache.calcite.rel.core.Project;
 import org.apache.calcite.rel.core.SemiJoin;
 import org.apache.calcite.rel.core.Sort;
 import org.apache.calcite.rel.logical.LogicalAggregate;
+import org.apache.calcite.rel.logical.LogicalExchange;
 import org.apache.calcite.rel.logical.LogicalFilter;
 import org.apache.calcite.rel.logical.LogicalJoin;
 import org.apache.calcite.rel.logical.LogicalProject;
@@ -1315,6 +1318,43 @@ public class RelMetadataTest extends SqlToRelTestBase {
         sortsAs("[IS NOT DISTINCT FROM($0, CASE(=(1, 1), null, 1))]"));
   }
 
+  @Test public void testDistributionSimple() {
+    RelNode rel = convertSql("select * from emp where deptno = 10");
+    final RelMetadataQuery mq = RelMetadataQuery.instance();
+    RelDistribution d = mq.getDistribution(rel);
+    assertThat(d, is(RelDistributions.BROADCAST_DISTRIBUTED));
+  }
+
+  @Test public void testDistributionHash() {
+    final RelNode rel = convertSql("select * from emp");
+    final RelDistribution dist = RelDistributions.hash(ImmutableList.of(1));
+    final LogicalExchange exchange = LogicalExchange.create(rel, dist);
+
+    final RelMetadataQuery mq = RelMetadataQuery.instance();
+    RelDistribution d = mq.getDistribution(exchange);
+    assertThat(d, is(dist));
+  }
+
+  @Test public void testDistributionHashEmpty() {
+    final RelNode rel = convertSql("select * from emp");
+    final RelDistribution dist = RelDistributions.hash(ImmutableList.<Integer>of());
+    final LogicalExchange exchange = LogicalExchange.create(rel, dist);
+
+    final RelMetadataQuery mq = RelMetadataQuery.instance();
+    RelDistribution d = mq.getDistribution(exchange);
+    assertThat(d, is(dist));
+  }
+
+  @Test public void testDistributionSingleton() {
+    final RelNode rel = convertSql("select * from emp");
+    final RelDistribution dist = RelDistributions.SINGLETON;
+    final LogicalExchange exchange = LogicalExchange.create(rel, dist);
+
+    final RelMetadataQuery mq = RelMetadataQuery.instance();
+    RelDistribution d = mq.getDistribution(exchange);
+    assertThat(d, is(dist));
+  }
+
   /**
    * Matcher that succeeds for any collection that, when converted to strings
    * and sorted on those strings, matches the given reference string.


Mime
View raw message