Skip to content

Conversation

@xiangfu0
Copy link
Contributor

@xiangfu0 xiangfu0 commented Jun 18, 2024

Fix literal handling in Window functions:

  • WindowNode has a field constants to keep all the literals
  • The InputRef index could map to first windowInput then constants
    • e.g. assume the windowInput size is 2 and constants size is 3, then we may found InputRef from $0 to $4, and $2 to $4 are the constants references.
  • Update the arguments list RexInputRef pointing to the corresponding RexLiteral.

Sample query:

SELECT DaysSinceEpoch,
  Distance,
  LAG(Distance, 5, 10) OVER (
    ORDER BY DaysSinceEpoch
  ) AS previous_day_sales,
  Distance - LAG(Distance, 5, 10) OVER (
    ORDER BY DaysSinceEpoch
  ) AS difference
FROM airlineStats;

image

WITH tmp AS (
  select count(*) as num_trips,
    DaysSinceEpoch
  from airlineStats
  GROUP BY DaysSinceEpoch
)

SELECT DaysSinceEpoch,
  num_trips,
  LAG(num_trips, 2) OVER (
    ORDER BY DaysSinceEpoch
  ) AS previous_num_trips,
  num_trips - LAG(num_trips, 2) OVER (
    ORDER BY DaysSinceEpoch
  ) AS difference
FROM tmp;

image

@xiangfu0 xiangfu0 requested review from Jackie-Jiang and gortiz June 18, 2024 23:57
@xiangfu0 xiangfu0 force-pushed the fix-lead-lag-function-with-order branch 3 times, most recently from 69d19cd to b7ab9ea Compare June 19, 2024 00:15
@xiangfu0 xiangfu0 force-pushed the fix-lead-lag-function-with-order branch from b7ab9ea to f4ae0ef Compare June 19, 2024 00:15
@xiangfu0 xiangfu0 merged commit 55b6024 into apache:master Jun 19, 2024
@xiangfu0 xiangfu0 deleted the fix-lead-lag-function-with-order branch June 19, 2024 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants