You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by ru...@apache.org on 2019/07/08 07:01:13 UTC
[calcite] branch master updated: [CALCITE-3172] RelBuilder#empty
does not keep aliases
This is an automated email from the ASF dual-hosted git repository.
rubenql pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/master by this push:
new 046f9f4 [CALCITE-3172] RelBuilder#empty does not keep aliases
046f9f4 is described below
commit 046f9f4e2e3c779e4e2e61946d67a0dc124f7f72
Author: rubenada <ru...@gmail.com>
AuthorDate: Thu Jul 4 16:06:41 2019 +0200
[CALCITE-3172] RelBuilder#empty does not keep aliases
---
.../java/org/apache/calcite/tools/RelBuilder.java | 7 +++-
.../org/apache/calcite/test/RelBuilderTest.java | 44 ++++++++++++++++++++++
2 files changed, 49 insertions(+), 2 deletions(-)
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 cdf71c4..c8545ed 100644
--- a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
+++ b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
@@ -2096,14 +2096,17 @@ public class RelBuilder {
* expressions, and always produces a leaf.
*
* <p>The default implementation creates a {@link Values} with the same
- * specified row type as the input, and ignores the input entirely.
+ * specified row type and aliases as the input, and ignores the input entirely.
* But schema-on-query systems such as Drill might override this method to
* create a relation expression that retains the input, just to read its
* schema.
*/
public RelBuilder empty() {
final Frame frame = stack.pop();
- return values(frame.rel.getRowType());
+ final RelNode values =
+ valuesFactory.createValues(cluster, frame.rel.getRowType(), ImmutableList.of());
+ stack.push(new Frame(values, frame.fields));
+ return this;
}
/** Creates a {@link Values} with a specified row type.
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 c06bdeb..a71ce05 100644
--- a/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
@@ -2042,6 +2042,50 @@ public class RelBuilderTest {
assertThat(root.getRowType().getFullTypeString(), is(expectedType));
}
+ /** Test case for
+ * <a href="https://issues.apache.org/jira/browse/CALCITE-3172">[CALCITE-3172]
+ * RelBuilder#empty does not keep aliases</a>. */
+ @Test public void testEmptyWithAlias() {
+ final RelBuilder builder = RelBuilder.create(config().build());
+ final String expected =
+ "LogicalProject(DEPTNO=[$0], DNAME=[$1])\n LogicalValues(tuples=[[]])\n";
+ final String expectedType =
+ "RecordType(TINYINT NOT NULL DEPTNO, VARCHAR(14) DNAME) NOT NULL";
+
+ // Scan + Empty + Project (without alias)
+ RelNode root =
+ builder.scan("DEPT")
+ .empty()
+ .project(
+ builder.field("DEPTNO"),
+ builder.field("DNAME"))
+ .build();
+ assertThat(root, hasTree(expected));
+ assertThat(root.getRowType().getFullTypeString(), is(expectedType));
+
+ // Scan + Empty + Project (with alias)
+ root =
+ builder.scan("DEPT").as("d")
+ .empty()
+ .project(
+ builder.field(1, "d", "DEPTNO"),
+ builder.field(1, "d", "DNAME"))
+ .build();
+ assertThat(root, hasTree(expected));
+ assertThat(root.getRowType().getFullTypeString(), is(expectedType));
+
+ // Scan + Filter false (implicitly converted into Empty) + Project (with alias)
+ root =
+ builder.scan("DEPT").as("d")
+ .filter(builder.literal(false))
+ .project(
+ builder.field(1, "d", "DEPTNO"),
+ builder.field(1, "d", "DNAME"))
+ .build();
+ assertThat(root, hasTree(expected));
+ assertThat(root.getRowType().getFullTypeString(), is(expectedType));
+ }
+
@Test public void testValues() {
// Equivalent SQL:
// VALUES (true, 1), (false, -50) AS t(a, b)