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

Support SET key=value syntax #9017

Merged
merged 4 commits into from
Jul 12, 2022
Merged

Conversation

walterddr
Copy link
Contributor

@walterddr walterddr commented Jul 5, 2022

Background

context: #8906

Description

This PR introduces a new way to set environmental options for executing a SQL query on Pinot.

Syntax examples for single and multiple environment options:

SET skipUpsert = 'false';
SELECT count(*) FROM tbl
SET foo = 'bar';
SET some_key = 'some_value';
SELECT * FROM tbl

Details

  • ; at the end of the SET statement indicate it is an end of a statement; However, Pinot doesn't support multiple statements, thus all SET statement(s) are only valid within the SQL query string context.
    • this means first executing ALTER SESSION SET key = 'value'; and then executing another query won't affect the query.
    • this also means, effectively one pinot query string is one individual, isolated user session.
  • we allow multiple SET statements within a single query string

Copy link
Contributor

@Jackie-Jiang Jackie-Jiang left a comment

Choose a reason for hiding this comment

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

LGTM otherwise

return options;
}

private static void setOptions(PinotQuery pinotQuery, List<String> optionsStatements) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes it is for backward compatibility will remove once the OPTION_REGEX is removed.

@codecov-commenter
Copy link

Codecov Report

Merging #9017 (c260a3e) into master (de16a0a) will decrease coverage by 3.23%.
The diff coverage is 74.32%.

❗ Current head c260a3e differs from pull request most recent head 5b7c51c. Consider uploading reports for the commit 5b7c51c to get more accurate results

@@             Coverage Diff              @@
##             master    #9017      +/-   ##
============================================
- Coverage     70.08%   66.85%   -3.24%     
+ Complexity     4957     4766     -191     
============================================
  Files          1827     1369     -458     
  Lines         96064    69842   -26222     
  Branches      14356    10912    -3444     
============================================
- Hits          67327    46693   -20634     
+ Misses        24092    19864    -4228     
+ Partials       4645     3285    -1360     
Flag Coverage Δ
integration1 ?
integration2 ?
unittests1 66.85% <74.32%> (-0.02%) ⬇️
unittests2 ?

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

Impacted Files Coverage Δ
...g/apache/pinot/common/metrics/ControllerMeter.java 0.00% <0.00%> (-100.00%) ⬇️
.../pinot/core/query/scheduler/PriorityScheduler.java 77.77% <ø> (-0.31%) ⬇️
...local/indexsegment/mutable/MutableSegmentImpl.java 54.34% <42.85%> (-0.56%) ⬇️
...org/apache/pinot/sql/parsers/CalciteSqlParser.java 86.41% <77.77%> (-1.56%) ⬇️
.../pinot/common/restlet/resources/TableTierInfo.java 100.00% <100.00%> (ø)
...rg/apache/pinot/sql/parsers/SqlNodeAndOptions.java 100.00% <100.00%> (ø)
...g/apache/pinot/sql/parsers/dml/InsertIntoFile.java 85.18% <100.00%> (ø)
...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%) ⬇️
... and 700 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update de16a0a...5b7c51c. Read the comment docs.

}
if (sqlType == null) {
throw new SqlCompilationException("SqlNode with statement not found!");
Copy link
Contributor

@siddharthteotia siddharthteotia Jul 12, 2022

Choose a reason for hiding this comment

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

Should we check that there has to be exactly 1 query/DQL statement unless it was an INSERT call ?

SET skipUpsert = 'false';

The above has no query statement but just the option SET which by alone is meaningless ?

Assert.assertEquals(pinotQuery.getQueryOptions().get("foo"), "1234");
Assert.assertEquals(pinotQuery.getQueryOptions().get("bar"), "'potato'");

// test invalid options
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also add a test where you have 2 DQL statements and 0 or more SET statements ?

@walterddr walterddr merged commit 0b657cf into apache:master Jul 12, 2022
@walterddr walterddr deleted the query_option_using_set branch December 6, 2023 16:24
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.

4 participants