helloppx commented on a change in pull request #1680: [CALCITE-3621] Push down 
sort to DB, SQL of Sort rel contains explicit field name instead of *
URL: https://github.com/apache/calcite/pull/1680#discussion_r360756860
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
 ##########
 @@ -634,6 +634,13 @@ public Result visit(Sort e) {
     }
     Result x = visitChild(0, e.getInput());
     Builder builder = x.builder(e, Clause.ORDER_BY);
+    if (builder.select.getSelectList() == null) {
 
 Review comment:
   When JdbcSort is used, a regression issue will be trigged: 
JdbcTest#testSelfJoinDifferentColumns()
   
   RelToSqlConverter visits the Sort and then produce a SQL "SELECT * from (t 
JOIN t0 ...) order by ...)". However t and t0 include one same name field 
"last_name". The outter Project will miss the correct field name.
   So I think this change is needed.
   
   Before SQL:
   select e1."full_name"
     from "foodmart"."employee" as e1
     join "foodmart"."employee" as e2 on e1."first_name" = e2."last_name"
   order by e1."last_name" limit 3
   
   Following is the regression issue info:
   REL:
   JdbcToEnumerableConverter
   --JdbcProject(full_name=[$1], last_name=[$3])
   ----JdbcSort(sort0=[$3], dir0=[ASC], fetch=[3])
   ------JdbcJoin(condition=[=($2, $0)], joinType=[inner])
   --------JdbcProject(last_name=[$3])
   ----------JdbcTableScan(table=[[foodmart, employee]])
   --------JdbcProject(full_name=[$1], first_name=[$2], last_name=[$3])
   ----------JdbcTableScan(table=[[foodmart, employee]])
   
   After SQL:
   SELECT "t2"."full_name", "t2"."last_name0" AS "last_name"
   FROM (SELECT *
   FROM (SELECT "last_name"
   FROM "foodmart"."employee") AS "t"
   INNER JOIN (SELECT "full_name", "first_name", "last_name"
   FROM "foodmart"."employee") AS "t0" ON "t"."last_name" = "t0"."first_name"
   ORDER BY "t0"."last_name" NULLS LAST
   LIMIT 3) AS "t2"

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to