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

Push OVER Clause to underlying SQL via JDBC adapter

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.10.0
    • Fix Version/s: 1.11.0
    • Component/s: jdbc-adapter
    • Labels:
      None

      Description

      The jdbc adapter adapter should push down the OVER clause for all dialects that support window functions.

      At the moment the Rel to SQL conversion ignores the 'OVER(...)'. The RexOver expression is treated as a plain RexCall and the RexOver#window attribute is not converted into SQL.

      For example if the following sql query (using Postgres dialect):

      SELECT "id", "device_id", "transaction_value", "account_id", "ts_millis", MAX("ts_millis") OVER(partition by "device_id") as "last_version_number" 
      FROM "HAWQ"."transaction"
      WHERE "device_id" = 1445
      

      is pushed down to the jdbc like this:

      SELECT "id", "device_id", "transaction_value", "account_id", "ts_millis", MAX("ts_millis") AS "last_version_number"
      FROM "transaction"
      WHERE "device_id" = 1445
      

      The OVER clause is completely dropped! Here is the plan:

      JdbcToEnumerableConverter
        JdbcProject(id=[$0], device_id=[$1], transaction_value=[$2], account_id=[$3], ts_millis=[$4], last_version_number=[MAX($4) OVER (PARTITION BY $1 RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)])
          JdbcFilter(condition=[=($1, 1445)])
            JdbcTableScan(table=[[HAWQ, transaction]])
      

        Activity

        Hide
        tzolov Christian Tzolov added a comment -
        Show
        tzolov Christian Tzolov added a comment - Here is the initial PR: https://github.com/apache/calcite/pull/329
        Hide
        julianhyde Julian Hyde added a comment -

        Thanks. I'll review when I'm back home and have a Postgres database to test against.

        Show
        julianhyde Julian Hyde added a comment - Thanks. I'll review when I'm back home and have a Postgres database to test against.
        Show
        julianhyde Julian Hyde added a comment - Fixed in http://git-wip-us.apache.org/repos/asf/calcite/commit/e4fb4c4e . Thanks for the PR, Christian Tzolov !
        Hide
        julianhyde Julian Hyde added a comment -

        Resolved in release 1.11.0 (2017-01-11).

        Show
        julianhyde Julian Hyde added a comment - Resolved in release 1.11.0 (2017-01-11).

          People

          • Assignee:
            julianhyde Julian Hyde
            Reporter:
            tzolov Christian Tzolov
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development