calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [12/14] calcite git commit: [CALCITE-1266] RelBuilder.field gets offsets wrong
Date Tue, 31 May 2016 23:24:10 GMT
[CALCITE-1266] RelBuilder.field gets offsets wrong


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

Branch: refs/heads/branch-avatica-1.8
Commit: 48e434263e526dcfa0c367e523cdc83b5989ab16
Parents: d757201
Author: Julian Hyde <jhyde@apache.org>
Authored: Tue May 31 11:37:31 2016 -0700
Committer: Julian Hyde <jhyde@apache.org>
Committed: Tue May 31 11:37:31 2016 -0700

----------------------------------------------------------------------
 .../org/apache/calcite/tools/RelBuilder.java    | 20 +++++++++++++++++++-
 .../apache/calcite/test/PigRelBuilderTest.java  |  2 +-
 .../org/apache/calcite/test/RelBuilderTest.java |  6 +++---
 .../org/apache/calcite/test/RelOptRulesTest.xml |  2 +-
 4 files changed, 24 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/48e43426/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
index acc9363..d912ba2 100644
--- a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
+++ b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
@@ -250,6 +250,20 @@ public class RelBuilder {
     return peek(inputCount - 1 - inputOrdinal);
   }
 
+  /** Returns the number of fields in all inputs before (to the left of)
+   * the given input.
+   *
+   * @param inputCount Number of inputs
+   * @param inputOrdinal Input ordinal
+   */
+  private int inputOffset(int inputCount, int inputOrdinal) {
+    int offset = 0;
+    for (int i = 0; i < inputOrdinal; i++) {
+      offset += peek(inputCount, i).getRowType().getFieldCount();
+    }
+    return offset;
+  }
+
   // Methods that return scalar expressions
 
   /** Creates a literal (constant expression). */
@@ -327,7 +341,11 @@ public class RelBuilder {
       throw new IllegalArgumentException("field ordinal [" + fieldOrdinal
           + "] out of range; input fields are: " + rowType.getFieldNames());
     }
-    return cluster.getRexBuilder().makeInputRef(input, fieldOrdinal);
+    final RelDataType fieldType =
+        rowType.getFieldList().get(fieldOrdinal).getType();
+    final int offset = inputOffset(inputCount, inputOrdinal);
+    return cluster.getRexBuilder()
+        .makeInputRef(fieldType, offset + fieldOrdinal);
   }
 
   /** Creates a reference to a field of the current record which originated

http://git-wip-us.apache.org/repos/asf/calcite/blob/48e43426/core/src/test/java/org/apache/calcite/test/PigRelBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/PigRelBuilderTest.java b/core/src/test/java/org/apache/calcite/test/PigRelBuilderTest.java
index d1b9f33..d877097 100644
--- a/core/src/test/java/org/apache/calcite/test/PigRelBuilderTest.java
+++ b/core/src/test/java/org/apache/calcite/test/PigRelBuilderTest.java
@@ -117,7 +117,7 @@ public class PigRelBuilderTest {
             builder.groupKey("DEPTNO").alias("e"),
             builder.groupKey("DEPTNO").alias("d"))
         .build();
-    final String plan = "LogicalJoin(condition=[=($0, $0)], joinType=[inner])\n"
+    final String plan = "LogicalJoin(condition=[=($0, $2)], joinType=[inner])\n"
         + "  LogicalAggregate(group=[{0}], EMP=[COLLECT($8)])\n"
         + "    LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4],
SAL=[$5], COMM=[$6], DEPTNO=[$7], $f8=[ROW($0, $1, $2, $3, $4, $5, $6, $7)])\n      LogicalTableScan(table=[[scott,
EMP]])\n  LogicalAggregate(group=[{0}], DEPT=[COLLECT($3)])\n"
         + "    LogicalProject(DEPTNO=[$0], DNAME=[$1], LOC=[$2], $f3=[ROW($0, $1, $2)])\n"

http://git-wip-us.apache.org/repos/asf/calcite/blob/48e43426/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java b/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
index e6ea995..bb9f7b4 100644
--- a/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
@@ -815,7 +815,7 @@ public class RelBuilderTest {
                     builder.field(2, 1, "DEPTNO")))
             .build();
     final String expected = ""
-        + "LogicalJoin(condition=[=($7, $0)], joinType=[inner])\n"
+        + "LogicalJoin(condition=[=($7, $8)], joinType=[inner])\n"
         + "  LogicalFilter(condition=[IS NULL($6)])\n"
         + "    LogicalTableScan(table=[[scott, EMP]])\n"
         + "  LogicalTableScan(table=[[scott, DEPT]])\n";
@@ -834,7 +834,7 @@ public class RelBuilderTest {
             .join(JoinRelType.INNER, "DEPTNO")
             .build();
     final String expected = ""
-        + "LogicalJoin(condition=[=($7, $0)], joinType=[inner])\n"
+        + "LogicalJoin(condition=[=($7, $8)], joinType=[inner])\n"
         + "  LogicalFilter(condition=[IS NULL($6)])\n"
         + "    LogicalTableScan(table=[[scott, EMP]])\n"
         + "  LogicalTableScan(table=[[scott, DEPT]])\n";
@@ -864,7 +864,7 @@ public class RelBuilderTest {
             .build();
     // Note that "dept.deptno IS NOT NULL" has been simplified away.
     final String expected = ""
-        + "LogicalJoin(condition=[AND(=($7, $0), =($0, 123))], joinType=[left])\n"
+        + "LogicalJoin(condition=[AND(=($7, $8), =($0, 123))], joinType=[left])\n"
         + "  LogicalTableScan(table=[[scott, EMP]])\n"
         + "  LogicalTableScan(table=[[scott, DEPT]])\n";
     assertThat(str(root), is(expected));

http://git-wip-us.apache.org/repos/asf/calcite/blob/48e43426/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index 20c5c0f..506f2dd 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -4666,7 +4666,7 @@ LogicalProject(DEPTNO=[$7])
 LogicalProject(EMPNO=[$0])
   LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6],
DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
     LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6],
DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10], $f0=[$11])
-      LogicalJoin(condition=[<($2, $3)], joinType=[left])
+      LogicalJoin(condition=[<($11, $12)], joinType=[left])
         LogicalTableScan(table=[[CATALOG, SALES, EMP]])
         LogicalJoin(condition=[true], joinType=[left])
           LogicalJoin(condition=[true], joinType=[left])


Mime
View raw message