Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
None
Description
The Order By Keys when resolved during RelToSql Conversion is hardcoded to fallback to Original Expression instead of an alias(if present)
This should be based on the Dialect set in RelToSqlConverter.
If the Order By Key is a Projection which was Aliased, the Output query contains the original column name instead of the Alias, which is not allowed in HIVE as valid Order By keys are to be selected from Select List Identifiers only.
Generated SQL(Failing in hive!),
Select first_name as n1 from emp order by first_name;
Expected SQL,
Select first_name as n1 from emp order by n1;
The Code Excerpt Responsible for this particular use case:- (SqlImplementor.java:952)
public SqlNode field(int ordinal) { final SqlNode selectItem = selectList.get(ordinal); switch (selectItem.getKind()) { case AS: return ((SqlCall) selectItem).operand(0); } return selectItem; }
I create the TableScan, Projection(with the alias) & Sort in the mentioned order.
Attachments
Issue Links
- Blocked
-
CALCITE-4987 JDBC adapter generates incorrect query when ORDER BY alias collides with field in SELECT ITEM
- In Progress
- relates to
-
CALCITE-4987 JDBC adapter generates incorrect query when ORDER BY alias collides with field in SELECT ITEM
- In Progress
- links to