Skip to content

Commit

Permalink
[OPTIQ-412] RelFieldTrimmer: when trimming SortRel, the collation and…
Browse files Browse the repository at this point in the history
… trait set don't match
  • Loading branch information
Harish Butani authored and julianhyde committed Sep 17, 2014
1 parent f715880 commit 3c32deb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/src/main/java/org/eigenbase/sql2rel/RelFieldTrimmer.java
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,11 @@ public TrimResult trimFields(
Mappings.createIdentity(fieldCount));
}

final RelNode newSort = sortFactory.createSort(sort.getTraitSet(),
newInput, RexUtil.apply(inputMapping, collation),
sort.offset, sort.fetch);
final RelCollation newCollation =
sort.getTraitSet().canonize(RexUtil.apply(inputMapping, collation));
final RelTraitSet newTraitSet = sort.getTraitSet().replace(newCollation);
final RelNode newSort = sortFactory.createSort(newTraitSet, newInput,
newCollation, sort.offset, sort.fetch);

// The result has the same mapping as the input gave us. Sometimes we
// return fields that the consumer didn't ask for, because the filter
Expand Down
10 changes: 10 additions & 0 deletions core/src/test/java/org/eigenbase/test/SqlToRelConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,16 @@ protected final void check(
Util.toLinux(sw.toString()));
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/OPTIQ-412">OPTIQ-412</a>,
* "RelFieldTrimmer: when trimming SortRel, the collation and trait set don't
* match". */
@Test public void testSortWithTrim() {
tester.assertConvertsTo(
"select ename from (select * from emp order by sal) a", "${plan}",
true);
}

/**
* Visitor that checks that every {@link RelNode} in a tree is valid.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,19 @@ ProjectRel(EMPNO=[$0], EXPR$1=[NOT(true)])
ProjectRel($f0=[$0], $f1=[true])
ProjectRel(DEPTNO=[$0])
TableAccessRel(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
<TestCase name="testSortWithTrim">
<Resource name="sql">
<![CDATA[select ename from (select * from emp order by sal) a]]>
</Resource>
<Resource name="plan">
<![CDATA[
ProjectRel(ENAME=[$0])
SortRel(sort0=[$1], dir0=[ASC])
ProjectRel(ENAME=[$1], SAL=[$5])
TableAccessRel(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
Expand Down

0 comments on commit 3c32deb

Please sign in to comment.