phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maryann...@apache.org
Subject phoenix git commit: PHOENIX-2229 Support CREATE VIEW in Phoenix-Calcite Integration
Date Tue, 19 Jul 2016 02:13:27 GMT
Repository: phoenix
Updated Branches:
  refs/heads/calcite 3d4a75feb -> 1601f533a


PHOENIX-2229 Support CREATE VIEW in Phoenix-Calcite Integration


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/1601f533
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/1601f533
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/1601f533

Branch: refs/heads/calcite
Commit: 1601f533aad85971d6ba9d2cdf70b81e7d1103a8
Parents: 3d4a75f
Author: maryannxue <maryann.xue@gmail.com>
Authored: Mon Jul 18 22:13:15 2016 -0400
Committer: maryannxue <maryann.xue@gmail.com>
Committed: Mon Jul 18 22:13:15 2016 -0400

----------------------------------------------------------------------
 .../src/main/codegen/includes/parserImpls.ftl   | 23 ++------------------
 .../calcite/jdbc/PhoenixPrepareImpl.java        |  9 +++++++-
 .../phoenix/calcite/parse/SqlCreateTable.java   |  4 ----
 3 files changed, 10 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/1601f533/phoenix-core/src/main/codegen/includes/parserImpls.ftl
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/codegen/includes/parserImpls.ftl b/phoenix-core/src/main/codegen/includes/parserImpls.ftl
index 7ce1596..3c9d6dc 100644
--- a/phoenix-core/src/main/codegen/includes/parserImpls.ftl
+++ b/phoenix-core/src/main/codegen/includes/parserImpls.ftl
@@ -35,24 +35,14 @@ SqlNode SqlCommit() :
     }
 }
 
-// Remove when
-//  [CALCITE-851] Add original SQL string as a field in the parser
-// is fixed.
-JAVACODE
-public String originalSql() {
-   return org.apache.phoenix.calcite.jdbc.PhoenixPrepareImpl.THREAD_SQL_STRING.get();
-}
-
 SqlNode SqlCreateView() :
 {
     SqlParserPos pos;
-    SqlParserPos queryPos;
     SqlIdentifier tableName;
     boolean ifNotExists;
     SqlNodeList columnDefs;
     SqlIdentifier baseTableName;
     SqlNode where;
-    String viewStatementString;
     SqlNodeList tableOptions;
 }
 {
@@ -75,21 +65,12 @@ SqlNode SqlCreateView() :
         }
     )
     (
-        <AS> <SELECT> { queryPos = getPos(); } <STAR> <FROM>
-        baseTableName = DualIdentifier()
+        <AS> <SELECT> <STAR> <FROM> baseTableName = DualIdentifier()
         where = WhereOpt()
-        {
-            queryPos = queryPos.plus(getPos());
-            String sql = originalSql();
-            int start = SqlParserUtil.lineColToIndex(sql, queryPos.getLineNum(), queryPos.getColumnNum());
-            int end = SqlParserUtil.lineColToIndex(sql, queryPos.getEndLineNum(), queryPos.getEndColumnNum());
-            viewStatementString = sql.substring(start, end + 1);            
-        }
         |
         {
             baseTableName = null;
             where = null;
-            viewStatementString = null;
         }
     )
     (
@@ -102,7 +83,7 @@ SqlNode SqlCreateView() :
     {
         return new SqlCreateTable(pos.plus(getPos()), tableName,
             SqlLiteral.createBoolean(ifNotExists, SqlParserPos.ZERO),
-            columnDefs, baseTableName, where, viewStatementString, tableOptions);
+            columnDefs, baseTableName, where, tableOptions);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1601f533/phoenix-core/src/main/java/org/apache/phoenix/calcite/jdbc/PhoenixPrepareImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/jdbc/PhoenixPrepareImpl.java
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/jdbc/PhoenixPrepareImpl.java
index c9d372d..ec2cdc0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/jdbc/PhoenixPrepareImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/jdbc/PhoenixPrepareImpl.java
@@ -28,6 +28,8 @@ import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.sql.SqlNodeList;
 import org.apache.calcite.sql.SqlTableOptionNode;
 import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.parser.SqlParserUtil;
 import org.apache.calcite.tools.Program;
 import org.apache.calcite.tools.Programs;
 import org.apache.calcite.util.Holder;
@@ -219,7 +221,12 @@ public class PhoenixPrepareImpl extends CalcitePrepareImpl {
                     if (table.whereNode == null) {
                         where = null;
                     } else {
-                        where = new SQLParser(table.viewStatementString).parseQuery().getWhere();
+                        String sql = THREAD_SQL_STRING.get();
+                        SqlParserPos wherePos = table.whereNode.getParserPosition();
+                        int start = SqlParserUtil.lineColToIndex(sql, wherePos.getLineNum(),
wherePos.getColumnNum());
+                        int end = SqlParserUtil.lineColToIndex(sql, wherePos.getEndLineNum(),
wherePos.getEndColumnNum());
+                        String whereString = sql.substring(start, end + 1);
+                        where = new SQLParser(whereString).parseExpression();
                     }
                 }
                 final List<ParseNode> splitNodes;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1601f533/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlCreateTable.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlCreateTable.java
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlCreateTable.java
index 7c153d8..dc4c5a7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlCreateTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlCreateTable.java
@@ -43,7 +43,6 @@ public class SqlCreateTable extends SqlCall {
     public final SqlNodeList pkConstraintColumnDefs;
     public final SqlIdentifier baseTableName;
     public final SqlNode whereNode;
-    public final String viewStatementString;
     public final SqlNodeList tableOptions;
     public final SqlNodeList splitKeyList;
     
@@ -67,7 +66,6 @@ public class SqlCreateTable extends SqlCall {
         this.pkConstraintColumnDefs = pkConstraintColumnDefs;
         this.baseTableName = null;
         this.whereNode = null;
-        this.viewStatementString = null;
         this.tableOptions = tableOptions;
         this.splitKeyList = splitKeyList;
     }
@@ -80,7 +78,6 @@ public class SqlCreateTable extends SqlCall {
             SqlNodeList columnDefs,
             SqlIdentifier baseTableName,
             SqlNode whereNode,
-            String viewStatementString,
             SqlNodeList tableOptions) {
         super(pos);
         this.operator = new SqlDdlOperator("CREATE VIEW", SqlKind.CREATE_VIEW);
@@ -91,7 +88,6 @@ public class SqlCreateTable extends SqlCall {
         this.pkConstraintColumnDefs = SqlNodeList.EMPTY;
         this.baseTableName = baseTableName;
         this.whereNode = whereNode;
-        this.viewStatementString = viewStatementString;
         this.tableOptions = tableOptions;
         this.splitKeyList = SqlNodeList.EMPTY;
     }


Mime
View raw message