Minghui Zhu has uploaded this change for review. ( 
http://gerrit.cloudera.org:8080/19023


Change subject: IMPALA-11566: Provide SQL parsing capabilities to other 
applications in the form of jar packages
......................................................................

IMPALA-11566: Provide SQL parsing capabilities to other applications in the 
form of jar packages

We have a requirement to rewrite the parameters of a function in SQL, and there 
will be more requirements related to SQL parsing in the future. Before, we used 
jsqlParser for parsing. In order to be more compatible with impala sql, we want 
to use impala's parser.

Not all statements currently support the toSql method, so to provide complete 
parsing capabilities, it is also necessary to support the toSql method of other 
statements, such as AlterTableStmt. But in our scenario, there are only select 
and use statements, which are already supported. So all we need to do is to 
analyze all the functions in sql and type out the parser package.

We can rely on it in the pom in another project:

<dependency>
    <groupId>org.apache.impala</groupId>
    <artifactId>impala-parser</artifactId>
    <version>${impala.version}</version>
</dependency>

And then we can rewrite the sql:

public String parse(String sql) {
  StatementBase node = Parser.parse(sql);
  FunctionCallExprVisitor functionCallExprVisitor = new 
FunctionCallExprVisitor();
  node.accept(functionCallExprVisitor);
  List<FunctionCallExpr> funcCalls = functionCallExprVisitor.getFuncCalls();
  // do something with funcCalla
  return node.toSql();
}

Change-Id: I246b088310f25b809d9e598c0ecc6613d9749ee3
---
M be/src/util/backend-gflag-util.cc
M common/thrift/BackendGflags.thrift
M fe/pom.xml
M fe/src/main/java/org/apache/impala/analysis/SelectStmt.java
M fe/src/main/java/org/apache/impala/analysis/StmtNode.java
M fe/src/main/java/org/apache/impala/catalog/ScalarFunction.java
M fe/src/main/java/org/apache/impala/service/BackendConfig.java
A fe/src/main/java/org/apache/impala/util/FunctionCallExprVisitor.java
A fe/src/main/java/org/apache/impala/util/StmtVisitor.java
9 files changed, 162 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/23/19023/1
--
To view, visit http://gerrit.cloudera.org:8080/19023
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I246b088310f25b809d9e598c0ecc6613d9749ee3
Gerrit-Change-Number: 19023
Gerrit-PatchSet: 1
Gerrit-Owner: Minghui Zhu <[email protected]>

Reply via email to