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

Allow adding and subtracting timestamp types in the multi-stage engine #14782

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

yashmayya
Copy link
Collaborator

  • Prior to Polymorphic binary arithmetic scalar functions #14089, the ADD and SUB scalar functions in Pinot were not aliased to the Calcite standard operators + / -. This meant that the scalar function definition was used and that allowed for things like SUB(ts_col1, ts_col2) or ADD(ts_col1, ts_literal).
  • However, things like ts_col1 - ts_col2 or ts_col1 + ts_col2 were still not allowed since the Calcite standard operators only support these operand types - numeric and numeric, datetime types and intervals, or intervals and intervals (see here). This led to an inconsistent experience with Pinot's operators. Also, note that Postgres supports directly subtracting timestamp types (but only adding timestamps to intervals).
  • This patch fixes the above regression with ADD and SUB. Also, since Pinot uses long types for timestamps internally and we support such operations in the single-stage engine, this patch also adds support for timestamp types with + and - in the multi-stage engine.

@yashmayya yashmayya added the multi-stage Related to the multi-stage query engine label Jan 9, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jan 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.85%. Comparing base (59551e4) to head (e29de98).
Report is 1553 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #14782      +/-   ##
============================================
+ Coverage     61.75%   63.85%   +2.09%     
- Complexity      207     1607    +1400     
============================================
  Files          2436     2704     +268     
  Lines        133233   150930   +17697     
  Branches      20636    23318    +2682     
============================================
+ Hits          82274    96370   +14096     
- Misses        44911    47344    +2433     
- Partials       6048     7216    +1168     
Flag Coverage Δ
custom-integration1 100.00% <ø> (+99.99%) ⬆️
integration 100.00% <ø> (+99.99%) ⬆️
integration1 100.00% <ø> (+99.99%) ⬆️
integration2 0.00% <ø> (ø)
java-11 63.83% <100.00%> (+2.12%) ⬆️
java-21 63.74% <100.00%> (+2.12%) ⬆️
skip-bytebuffers-false 63.84% <100.00%> (+2.10%) ⬆️
skip-bytebuffers-true 63.71% <100.00%> (+35.98%) ⬆️
temurin 63.85% <100.00%> (+2.09%) ⬆️
unittests 63.84% <100.00%> (+2.09%) ⬆️
unittests1 56.31% <100.00%> (+9.42%) ⬆️
unittests2 34.12% <100.00%> (+6.39%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

// operations, so we need to define our own operators. Note that Postgres supports - on TIMESTAMP types, but not +.
// Calcite only supports such operations if the second operand is an interval (similar to Postgres for the +
// operator).
public static final SqlBinaryOperator PINOT_PLUS =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to explicitly register them? Or just let the scalar function register it which has very loose check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works for ADD / SUB, but not for + / - since those are unique operators. We get an error like this during query compilation (sample query - SELECT ts - CAST(1234567890 AS TIMESTAMP) from airlineStats LIMIT 1;) if we try to register + / - as Pinot scalar functions -

Invalid number of arguments to function '-'. Was expecting 2 arguments

Copy link
Collaborator Author

@yashmayya yashmayya Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that should be fixable by adding a new constructor to PinotSqlFunction and allowing caller to pass in SqlKind though.

Edit: We'd also need to define the right precedence and associativity, so maybe this way is simpler?
Edit 2: We should also be defining them as SqlMonotonicBinaryOperator, and not SqlFunction (like scalar function registry does).

@yashmayya yashmayya marked this pull request as ready for review January 9, 2025 07:27
@yashmayya yashmayya merged commit 09cce36 into apache:master Jan 9, 2025
21 checks passed
yashmayya added a commit to yashmayya/pinot that referenced this pull request Jan 9, 2025
zeronerdzerogeekzerocool pushed a commit to zeronerdzerogeekzerocool/pinot that referenced this pull request Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multi-stage Related to the multi-stage query engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants