[
https://issues.apache.org/jira/browse/CALCITE-486?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14247221#comment-14247221
]
Vladimir Sitnikov commented on CALCITE-486:
-------------------------------------------
Here you go:
{code:java}
/**
* Tests that even though trivial "rename columns" projection is removed,
* the query still returns proper column names.
*/
@Test public void testValuesCompositeRenamedSameNamesUnion() {
CalciteAssert.that()
.with(CalciteAssert.Config.REGULAR)
.query("select \"deptno\", \"deptno\" from \"hr\".\"depts\" union
select \"deptno\", \"empid\" from \"hr\".\"emps\"")
.explainContains(
"PLAN=EnumerableUnion(all=[false])\n"
+ " EnumerableCalc(expr#0..2=[{inputs}], deptno=[$t0],
deptno0=[$t0])\n"
+ " EnumerableTableScan(table=[[hr, depts]])\n"
+ " EnumerableCalc(expr#0..4=[{inputs}], deptno=[$t1],
empid=[$t0])\n"
+ " EnumerableTableScan(table=[[hr, emps]])\n")
.returnsUnordered(
"deptno=10; deptno=110",
"deptno=10; deptno=10",
"deptno=20; deptno=200",
"deptno=10; deptno=100",
"deptno=10; deptno=150",
"deptno=30; deptno=30",
"deptno=40; deptno=40");
}
{code}
{code:java}
/* 23 */ final int inp0_ =
((org.apache.calcite.test.JdbcTest.Department)
inputEnumerator.current()).deptno;
/* 24 */ return new Object[] {
/* 25 */ inp0_,
/* 26 */ inp0_};
...
/* 51 */ final org.apache.calcite.test.JdbcTest.Employee current =
(org.apache.calcite.test.JdbcTest.Employee) inputEnumerator.current();
/* 52 */ return new Object[] {
/* 53 */ current.deptno,
/* 54 */ current.empid};
...
/* 61 */ return child0.union(child1);
{code}
> Fast-path for EnumerableCalc in case of trivial program
> -------------------------------------------------------
>
> Key: CALCITE-486
> URL: https://issues.apache.org/jira/browse/CALCITE-486
> Project: Calcite
> Issue Type: Bug
> Reporter: Vladimir Sitnikov
> Assignee: Julian Hyde
> Labels: newbie
>
> It looks like in case when row type differs just in the column names,
> enumerable is still processed.
> {{JdbcTest.testInnerJoinValues}}, {{...SELECT * FROM (VALUES (10,
> 'SameName')) AS t (id, desc)...}}
> Note how input "VALUES" is passed through custom enumerable that has no
> meaning.
> This should be optimized.
> {code:java}
> /* 5 */ final org.apache.calcite.linq4j.Enumerable _inputEnumerable =
> org.apache.calcite.linq4j.Linq4j.asEnumerable(new Object[] {
> /* 6 */ new Object[] {
> /* 7 */ 10,
> /* 8 */ "SameName"}});
> ...
> /* 25 */ public Object current() {
> /* 26 */ final Object[] current = (Object[])
> inputEnumerator.current();
> /* 27 */ return new Object[] {
> /* 28 */ current[0],
> /* 29 */ current[1]};
> /* 30 */ }
> {code}
> Full code
> {code:java}
> /* 1 */ org.apache.calcite.DataContext root;
> /* 2 */
> /* 3 */ public org.apache.calcite.linq4j.Enumerable bind(final
> org.apache.calcite.DataContext root0) {
> /* 4 */ root = root0;
> /* 5 */ final org.apache.calcite.linq4j.Enumerable _inputEnumerable =
> org.apache.calcite.linq4j.Linq4j.asEnumerable(new Object[] {
> /* 6 */ new Object[] {
> /* 7 */ 10,
> /* 8 */ "SameName"}});
> /* 9 */ final org.apache.calcite.linq4j.AbstractEnumerable left = new
> org.apache.calcite.linq4j.AbstractEnumerable(){
> /* 10 */ public org.apache.calcite.linq4j.Enumerator enumerator() {
> /* 11 */ return new org.apache.calcite.linq4j.Enumerator(){
> /* 12 */ public final org.apache.calcite.linq4j.Enumerator
> inputEnumerator = _inputEnumerable.enumerator();
> /* 13 */ public void reset() {
> /* 14 */ inputEnumerator.reset();
> /* 15 */ }
> /* 16 */
> /* 17 */ public boolean moveNext() {
> /* 18 */ return inputEnumerator.moveNext();
> /* 19 */ }
> /* 20 */
> /* 21 */ public void close() {
> /* 22 */ inputEnumerator.close();
> /* 23 */ }
> /* 24 */
> /* 25 */ public Object current() {
> /* 26 */ final Object[] current = (Object[])
> inputEnumerator.current();
> /* 27 */ return new Object[] {
> /* 28 */ current[0],
> /* 29 */ current[1]};
> /* 30 */ }
> /* 31 */
> /* 32 */ };
> /* 33 */ }
> /* 34 */
> /* 35 */ };
> /* 36 */ final org.apache.calcite.linq4j.Enumerable _inputEnumerable0 =
> left.join(org.apache.calcite.linq4j.Linq4j.asEnumerable(((org.apache.calcite.test.JdbcTest.LingualSchema)
> ((org.apache.calcite.adapter.java.ReflectiveSchema)
> root.getRootSchema().getSubSchema("SALES").unwrap(org.apache.calcite.adapter.java.ReflectiveSchema.class)).getTarget()).EMPS),
> new org.apache.calcite.linq4j.function.Function1() {
> /* 37 */ public java.util.List apply(Object[] v1) {
> /* 38 */ return java.util.Collections.EMPTY_LIST;
> /* 39 */ }
> /* 40 */ public Object apply(Object v1) {
> /* 41 */ return apply(
> /* 42 */ (Object[]) v1);
> /* 43 */ }
> /* 44 */ }
> /* 45 */ , new org.apache.calcite.linq4j.function.Function1() {
> /* 46 */ public java.util.List
> apply(org.apache.calcite.test.JdbcTest.LingualEmp v1) {
> /* 47 */ return java.util.Collections.EMPTY_LIST;
> /* 48 */ }
> /* 49 */ public Object apply(Object v1) {
> /* 50 */ return apply(
> /* 51 */ (org.apache.calcite.test.JdbcTest.LingualEmp) v1);
> /* 52 */ }
> /* 53 */ }
> /* 54 */ , new org.apache.calcite.linq4j.function.Function2() {
> /* 55 */ public Object[] apply(Object[] left,
> org.apache.calcite.test.JdbcTest.LingualEmp right) {
> /* 56 */ return new Object[] {
> /* 57 */ left[0],
> /* 58 */ left[1],
> /* 59 */ right.EMPNO,
> /* 60 */ right.DEPTNO};
> /* 61 */ }
> /* 62 */ public Object[] apply(Object left, Object right) {
> /* 63 */ return apply(
> /* 64 */ (Object[]) left,
> /* 65 */ (org.apache.calcite.test.JdbcTest.LingualEmp) right);
> /* 66 */ }
> /* 67 */ }
> /* 68 */ , null, false, false);
> /* 69 */ final org.apache.calcite.linq4j.AbstractEnumerable child = new
> org.apache.calcite.linq4j.AbstractEnumerable(){
> /* 70 */ public org.apache.calcite.linq4j.Enumerator enumerator() {
> /* 71 */ return new org.apache.calcite.linq4j.Enumerator(){
> /* 72 */ public final org.apache.calcite.linq4j.Enumerator
> inputEnumerator = _inputEnumerable0.enumerator();
> /* 73 */ public void reset() {
> /* 74 */ inputEnumerator.reset();
> /* 75 */ }
> /* 76 */
> /* 77 */ public boolean moveNext() {
> /* 78 */ while (inputEnumerator.moveNext()) {
> /* 79 */ final Object[] current = (Object[])
> inputEnumerator.current();
> /* 80 */ if
> (org.apache.calcite.runtime.SqlFunctions.toInt(current[3]) ==
> org.apache.calcite.runtime.SqlFunctions.toInt(current[0]) &&
> org.apache.calcite.runtime.SqlFunctions.eq(current[1] == null ? (String) null
> : current[1].toString(), "SameName")) {
> /* 81 */ return true;
> /* 82 */ }
> /* 83 */ }
> /* 84 */ return false;
> /* 85 */ }
> /* 86 */
> /* 87 */ public void close() {
> /* 88 */ inputEnumerator.close();
> /* 89 */ }
> /* 90 */
> /* 91 */ public Object current() {
> /* 92 */ final Object[] current = (Object[])
> inputEnumerator.current();
> /* 93 */ return new Object[] {
> /* 94 */ current[2],
> /* 95 */ current[1]};
> /* 96 */ }
> /* 97 */
> /* 98 */ };
> /* 99 */ }
> /* 100 */
> /* 101 */ };
> /* 102 */ return
> child.distinct(org.apache.calcite.linq4j.function.Functions.arrayComparer());
> /* 103 */ }
> /* 104 */
> /* 105 */
> /* 106 */ public java.lang.reflect.Type getElementType() {
> /* 107 */ return java.lang.Object[].class;
> /* 108 */ }
> /* 109 */
> /* 110 */
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)