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

add parsing for AT TIME ZONE #9477

Merged
merged 3 commits into from
Sep 29, 2022
Merged

add parsing for AT TIME ZONE #9477

merged 3 commits into from
Sep 29, 2022

Conversation

agavra
Copy link
Contributor

@agavra agavra commented Sep 28, 2022

This commit adds the custom Calcite extension for parsing AT TIME ZONE expressions, but does not yet support executing these queries.

I implemented the @ScalarFunction locally to make sure that it can work when fully wired in but I wanted to commit that separately because we should take care to make sure that we do it in a backwards compatible way. The complications here are that AT TIME ZONE behaves different based on whether the input type already has a time zone associated with it or not. Additionally, AT TIME ZONE returns a timestamp with time zone for non-zoned timestamps, which means we need to support both types before getting the "SQL Standard" behavior here.

Also See: postgres specficiation

@agavra agavra changed the title [multistage] add parsing for AT TIME ZONE add parsing for AT TIME ZONE Sep 28, 2022
This commit adds the custom Calcite extension for
parsing AT TIME ZONE expressions, but does not yet
support executing these queries.
@agavra agavra marked this pull request as ready for review September 28, 2022 15:08
@codecov-commenter
Copy link

codecov-commenter commented Sep 28, 2022

Codecov Report

Merging #9477 (ac61ce7) into master (3818397) will increase coverage by 32.40%.
The diff coverage is 92.30%.

@@              Coverage Diff              @@
##             master    #9477       +/-   ##
=============================================
+ Coverage     34.73%   67.14%   +32.40%     
- Complexity      194     4944     +4750     
=============================================
  Files          1910     1419      -491     
  Lines        101850    74027    -27823     
  Branches      15452    11815     -3637     
=============================================
+ Hits          35379    49704    +14325     
+ Misses        63483    20728    -42755     
- Partials       2988     3595      +607     
Flag Coverage Δ
integration2 ?
unittests1 67.14% <92.30%> (?)
unittests2 ?

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

Impacted Files Coverage Δ
...apache/pinot/sql/parsers/parser/SqlAtTimeZone.java 92.30% <92.30%> (ø)
...va/org/apache/pinot/core/routing/RoutingTable.java 0.00% <0.00%> (-100.00%) ⬇️
...va/org/apache/pinot/common/config/NettyConfig.java 0.00% <0.00%> (-100.00%) ⬇️
...a/org/apache/pinot/common/metrics/MinionMeter.java 0.00% <0.00%> (-100.00%) ⬇️
...g/apache/pinot/common/metrics/ControllerMeter.java 0.00% <0.00%> (-100.00%) ⬇️
.../apache/pinot/common/metrics/BrokerQueryPhase.java 0.00% <0.00%> (-100.00%) ⬇️
.../apache/pinot/common/metrics/MinionQueryPhase.java 0.00% <0.00%> (-100.00%) ⬇️
...ache/pinot/server/access/AccessControlFactory.java 0.00% <0.00%> (-100.00%) ⬇️
...he/pinot/common/messages/SegmentReloadMessage.java 0.00% <0.00%> (-100.00%) ⬇️
...he/pinot/common/messages/TableDeletionMessage.java 0.00% <0.00%> (-100.00%) ⬇️
... and 1618 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@walterddr walterddr left a comment

Choose a reason for hiding this comment

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

ignore

Copy link
Contributor

@walterddr walterddr left a comment

Choose a reason for hiding this comment

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

looks good to me overall. have a couple of questions

import static java.util.Objects.requireNonNull;


public class SqlAtTimeZone extends SqlSpecialOperator {
Copy link
Contributor

@walterddr walterddr Sep 28, 2022

Choose a reason for hiding this comment

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

lets model it similar to SqlTimestampAddFunction extends SqlFunction?
any specific reason we want to model it as special operator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has special syntax (it's not the usual FUN_NAME(params...)) which makes it a bit more complicated - I modeled after SqlLikeOperator which is more similar to this w.r.t syntax. I have to implement the reduceExpr to clearly indicate that the left argument comes before the operation and the right argument comes afterwards.

Comment on lines +112 to +115
{
checkNonQueryExpression(exprContext);
s.clear().add(this);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to check this. can't it be something like

SELECT * FROM tbl 
WHERE (SELECT MAX(timestampWithoutTimeZone) FROM anotherTbl) AT TIME ZONE 'Pacific' BETWEEN xxx AND xxx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I modeled this after the LIKE syntax which has that check - I'm not 100% sure why they added that restriction, because I checked Postgres and SELECT (SELECT str FROM foo) LIKE 'foo' FROM foo; works and so does nested AT TIME ZONE like your example query.

I tried these in Pinot, though, and it looks like there are other limitations that prevent us from doing that...

SELECT (SELECT str FROM foo) LIKE 'foo' FROM foo; returns the following exception in Pinot:

java.lang.ClassCastException: class org.apache.calcite.sql.SqlSelect cannot be cast to class org.apache.calcite.sql.SqlBasicCall (org.apache.calcite.sql.SqlSelect and org.apache.calcite.sql.SqlBasicCall are in unnamed module of loader 'app')

	at org.apache.pinot.sql.parsers.CalciteSqlParser.toExpression(CalciteSqlParser.java:748)
	at org.apache.pinot.sql.parsers.CalciteSqlParser.compileFunctionExpression(CalciteSqlParser.java:806)
	at org.apache.pinot.sql.parsers.CalciteSqlParser.toExpression(CalciteSqlParser.java:748)

If you feel strongly, I can remove the check, but it won't work either way without additional work (which I think we can address in a follow-up if desired)

Copy link
Contributor

Choose a reason for hiding this comment

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

for now it should be fine. since this should probably go back to calcite we can adjust later

@agavra agavra requested a review from walterddr September 29, 2022 00:01
Copy link
Contributor

@walterddr walterddr left a comment

Choose a reason for hiding this comment

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

looks good to me overall. since the actual function impl is not added yet we can adjust on later PR

Comment on lines +112 to +115
{
checkNonQueryExpression(exprContext);
s.clear().add(this);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

for now it should be fine. since this should probably go back to calcite we can adjust later

@walterddr walterddr merged commit dc84310 into apache:master Sep 29, 2022
@agavra agavra deleted the at_time_zone branch September 29, 2022 19:29
61yao pushed a commit to 61yao/pinot that referenced this pull request Oct 3, 2022
* add parsing for AT TIME ZONE

This commit adds the custom Calcite extension for
parsing AT TIME ZONE expressions, but does not yet
support executing these queries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants