soumyakanti3578 commented on code in PR #6673:
URL: https://github.com/apache/hive/pull/6673#discussion_r3918624480


##########
ql/src/test/results/clientpositive/jdbc/postgres/cbo_query12.q.out:
##########
@@ -0,0 +1,22 @@
+CBO PLAN:
+HiveProject(i_item_desc=[$0], i_category=[$1], i_class=[$2], 
i_current_price=[$3], itemrevenue=[$4], revenueratio=[$5])
+  HiveSortLimit(sort0=[$1], sort1=[$2], sort2=[$6], sort3=[$0], sort4=[$5], 
dir0=[ASC], dir1=[ASC], dir2=[ASC], dir3=[ASC], dir4=[ASC], fetch=[100])

Review Comment:
   This one is due to the window function just below the Sort. The plan is:
   ```
   HiveProject(i_item_desc=[$0], i_category=[$1], i_class=[$2], 
i_current_price=[$3], itemrevenue=[$4], revenueratio=[$5])
     HiveSortLimit(sort0=[$1], sort1=[$2], sort2=[$6], sort3=[$0], sort4=[$5], 
dir0=[ASC], dir1=[ASC], dir2=[ASC], dir3=[ASC], dir4=[ASC], fetch=[100])
       HiveProject(i_item_desc=[$1], i_category=[$4], i_class=[$3], 
i_current_price=[$2], itemrevenue=[$5], revenueratio=[/(*($5, 100:DECIMAL(10, 
0)), sum($5) OVER (PARTITION BY $3 ORDER BY $3 NULLS FIRST RANGE BETWEEN 
UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING))], (tok_table_or_col 
i_item_id)=[$0])
         HiveProject(i_item_id=[$0], i_item_desc=[$1], i_current_price=[$2], 
i_class=[$3], i_category=[$4], $f5=[$5])
           HiveJdbcConverter(convention=[JDBC.POSTGRES])
             JdbcAggregate(group=[{5, 6, 7, 8, 9}], agg#0=[sum($2)])
   ```
   
   There is an explicit check for this in `JDBCRexCallValidator`:
   ```
       private boolean validRexCall(RexCall call) {
         if (call instanceof RexOver) {
           LOG.debug("RexOver operator push down is not supported for now with 
the following operator:" + call);
           return false;
         }
   ```
   And this is called by `JDBCProjectPushDownRule`, and all other push-down 
rules too:
   ```
     public boolean matches(RelOptRuleCall call) {
       final HiveProject project = call.rel(0);
       final HiveJdbcConverter conv = call.rel(1);
       for (RexNode currProject : project.getProjects()) {
         if (!JDBCRexCallValidator.isValidJdbcOperation(currProject, 
conv.getJdbcDialect())) {
           return false;
         }
         if (!validDataType(conv.getJdbcDialect(), currProject)) {
           return false;
         }
       }
   
       return true;
     }
   ```
   
   After removing the window function from the query as a test, the Sort is 
pushed down:
   ```
   HiveProject(i_item_desc=[$0], i_category=[$1], i_class=[$2], 
i_current_price=[$3], itemrevenue=[$4])
     HiveProject(i_item_desc=[$0], i_category=[$1], i_class=[$2], 
i_current_price=[$3], itemrevenue=[$4])
       HiveJdbcConverter(convention=[JDBC.POSTGRES])
         JdbcProject(i_item_desc=[$0], i_category=[$1], i_class=[$2], 
i_current_price=[$3], itemrevenue=[$4])
           JdbcSort(sort0=[$1], sort1=[$2], sort2=[$5], sort3=[$0], dir0=[ASC], 
dir1=[ASC], dir2=[ASC], dir3=[ASC], fetch=[100])
   ```
   
   P.S.: I see the identical projects, I haven't looked into it yet, but my 
guess is `PlanModifierForASTConv` introduces a Project above 
`HiveJdbcConverter`. Also, out of scope for this comment.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to