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

Adding Calcite SQL Parser and make another entry point to query Pinot #4387

Merged
merged 5 commits into from Jul 10, 2019

Conversation

xiangfu0
Copy link
Contributor

@xiangfu0 xiangfu0 commented Jun 30, 2019

As part of winedepot#14, this PR implements a Calcite SQL parser to compile SQL to PinotQuery.

Something to be noticed as syntax backward incompatible with PQL.

  1. '!=' is not supported, need to replace it with '<>';
  2. Double quote is used for identifier;
  3. Single quotes are used for string literal and it's part of the parsed string. It's up to us to keep it or remove it.

Currently I removed the single quote from StringLiteral to match PQL parsing behavior.
See:

org.apache.pinot.common.utils.request.RequestUtils

literal.setStringValue(node.toString().replaceAll("^\'|\'$", ""));

@codecov-io
Copy link

codecov-io commented Jun 30, 2019

Codecov Report

Merging #4387 into master will increase coverage by 9.79%.
The diff coverage is 57.7%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master   #4387      +/-   ##
===========================================
+ Coverage      55.7%   65.5%   +9.79%     
  Complexity       20      20              
===========================================
  Files          1066    1075       +9     
  Lines         55403   55835     +432     
  Branches       7894    7964      +70     
===========================================
+ Hits          30865   36573    +5708     
+ Misses        22150   16644    -5506     
- Partials       2388    2618     +230
Impacted Files Coverage Δ Complexity Δ
...org/apache/pinot/common/utils/CommonConstants.java 48.97% <ø> (+18.54%) 0 <0> (ø) ⬇️
...pql/parsers/PinotQuery2BrokerRequestConverter.java 87.37% <100%> (+2.67%) 0 <0> (ø) ⬇️
...che/pinot/pql/parsers/pql2/ast/OrderByAstNode.java 83.33% <100%> (ø) 0 <0> (ø) ⬇️
...g/apache/pinot/sql/parsers/CalciteSqlCompiler.java 100% <100%> (ø) 0 <0> (?)
...roker/requesthandler/BaseBrokerRequestHandler.java 77.5% <100%> (+66.95%) 0 <0> (ø) ⬇️
...pinot/pql/parsers/pql2/ast/InPredicateAstNode.java 42.46% <100%> (ø) 0 <0> (ø) ⬇️
.../pql/parsers/pql2/ast/BetweenPredicateAstNode.java 33.96% <100%> (ø) 0 <0> (ø) ⬇️
...not/pql/parsers/pql2/ast/PredicateListAstNode.java 76.74% <100%> (ø) 0 <0> (ø) ⬇️
...inot/pql/parsers/pql2/ast/OutputColumnAstNode.java 95.12% <100%> (+19.51%) 0 <0> (ø) ⬇️
...attenNestedPredicatesFilterQueryTreeOptimizer.java 88.88% <100%> (+0.42%) 0 <0> (ø) ⬇️
... and 364 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 33f583b...fd8ec34. Read the comment docs.

Copy link
Member

@kishoreg kishoreg left a comment

Choose a reason for hiding this comment

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

Can we not parse PQL using calcite after removing options.

@@ -83,6 +88,22 @@ public BrokerResponse executeQuery(String brokerAddress, String query)
}
}

@Override
public BrokerResponse executeSqlQuery(String brokerAddress, String query)
Copy link
Member

Choose a reason for hiding this comment

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

better to add another overloaded parameter to executeQueryAsync to take queryFormat as a param (default can be PQL for now)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make Query an object

}
}

public boolean validate(BrokerRequest br1, BrokerRequest br2) {
Copy link
Member

Choose a reason for hiding this comment

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

we should move this to some Validator so that we can invoke it from other places

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -338,6 +337,13 @@ public BrokerResponse handleRequest(JsonNode request, @Nullable RequesterIdentit
return brokerResponse;
}

private PinotQueryRequest getPinotQueryRequest(JsonNode request) {
if (request.has(SQL)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to assert that only one of SQL|PQL is specified in the request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since sql support is newly added, I feel it's ok to keep sql parsing as first priority comparing to PQL.
So existing PQL user won't get affected.

public void testPqlAndSqlCompatible()
throws Exception {
final BufferedReader brPql = new BufferedReader(new InputStreamReader(
PqlAndCalciteSqlCompatibilityTest.class.getClassLoader().getResourceAsStream("pql_queries.list")));
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the queries.list comprehensive enough to test all the various PQL syntax features?

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 don't think this will cover full syntax features. I've added some more queries into it. We should keep adding more query patterns.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, we should ensure that we have full coverage before we advertise the SQL option. Let's open a issue to track that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do

@@ -96,6 +96,10 @@
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this have a lot more functionality than the complier that we won't need? If so, is there a different artifact to include that just has what we need?

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 is the artifact we need in order to use SqlParser(https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql/parser/SqlParser.java).

Copy link
Contributor

Choose a reason for hiding this comment

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

So are we bringing in a lot more (in calcite-core) than we need? Probably we don't have an option, but in case we do, consider just getting the minimal artifact available that we need.

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, we may exclude the unnecessary dependencies once conflict is found.

Copy link
Contributor

@mayankshriv mayankshriv left a comment

Choose a reason for hiding this comment

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

A couple of minor comments need responding before pushing the change. LGTM, otherwise.

@xiangfu0 xiangfu0 merged commit a7c419a into apache:master Jul 10, 2019
@xiangfu0 xiangfu0 deleted the upstream_master branch July 10, 2019 20:43
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.

None yet

4 participants