Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-2552

Whether the JDBC adapter generates aliases in ORDER BY should be driven by the target dialect

    XMLWordPrintableJSON

    Details

      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

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                Krishnakant A KrishnaKant Agrawal
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h