Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix literal handling in Window functions #13428

Merged
merged 1 commit into from
Jun 19, 2024

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 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
20 checks passed
@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