You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ma...@apache.org on 2016/08/01 19:20:38 UTC

phoenix git commit: PHOENIX-2741 Support DROP SEQUENCE in Phoenix/Calcite Integration

Repository: phoenix
Updated Branches:
  refs/heads/calcite 8b8563f47 -> 5962a9362


PHOENIX-2741 Support DROP SEQUENCE 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/5962a936
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/5962a936
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/5962a936

Branch: refs/heads/calcite
Commit: 5962a93625a552a97f83a70d7b84e5a7ce76226e
Parents: 8b8563f
Author: maryannxue <ma...@gmail.com>
Authored: Mon Aug 1 15:20:30 2016 -0400
Committer: maryannxue <ma...@gmail.com>
Committed: Mon Aug 1 15:20:30 2016 -0400

----------------------------------------------------------------------
 .../apache/phoenix/calcite/CalciteDDLIT.java    |  3 +-
 phoenix-core/src/main/codegen/data/Parser.tdd   |  1 +
 .../src/main/codegen/includes/parserImpls.ftl   | 26 +++++++++++
 .../calcite/jdbc/PhoenixPrepareImpl.java        | 15 +++++++
 .../phoenix/calcite/parse/SqlDropSequence.java  | 45 ++++++++++++++++++++
 5 files changed, 89 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/5962a936/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteDDLIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteDDLIT.java b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteDDLIT.java
index 970e68d..e0330dc 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteDDLIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteDDLIT.java
@@ -30,8 +30,9 @@ public class CalciteDDLIT extends BaseCalciteIT {
         start(PROPS).sql("create table t4(a bigint not null ROW_TIMESTAMP, b integer not null, c double constraint pk primary key(a,b)) SALT_BUCKET=4,VERSIONS=5 SPLIT ON('a','b')").execute();
     }
     
-    @Test public void testCreateSequence() throws Exception {
+    @Test public void testCreateAndDropSequence() throws Exception {
         start(PROPS).sql("create sequence if not exists s0 start with 2 increment 3 minvalue 2 maxvalue 90 cycle cache 3").execute().close();
+        start(PROPS).sql("drop sequence if exists s0").execute().close();
     }
     
     @Test public void testDropTable() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5962a936/phoenix-core/src/main/codegen/data/Parser.tdd
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/codegen/data/Parser.tdd b/phoenix-core/src/main/codegen/data/Parser.tdd
index 04f073c..8ace311 100644
--- a/phoenix-core/src/main/codegen/data/Parser.tdd
+++ b/phoenix-core/src/main/codegen/data/Parser.tdd
@@ -53,6 +53,7 @@
     "SqlCreateTable()",
     "SqlCreateSequence()",
     "SqlDropTableOrDropView()",
+    "SqlDropSequence()",
   ]
 
   # List of methods for parsing custom literals.

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5962a936/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 8256738..a6ae9a2 100644
--- a/phoenix-core/src/main/codegen/includes/parserImpls.ftl
+++ b/phoenix-core/src/main/codegen/includes/parserImpls.ftl
@@ -271,6 +271,32 @@ SqlNode SqlDropTableOrDropView() :
     }
 }
 
+/**
+ * Parses statement
+ *   DROP SEQUENCE
+ */
+SqlNode SqlDropSequence() :
+{
+    SqlParserPos pos;
+    SqlIdentifier sequenceName;
+    boolean ifExists;
+}
+{
+    <DROP> { pos = getPos(); } <SEQUENCE>
+    (
+        <IF> <EXISTS> { ifExists = true; }
+        |
+        {
+            ifExists = false;
+        }
+    )
+    sequenceName = DualIdentifier()
+    {
+        return new SqlDropSequence(pos.plus(getPos()), sequenceName,
+            SqlLiteral.createBoolean(ifExists, SqlParserPos.ZERO));
+    }
+}
+
 SqlNodeList ColumnDefList() :
 {
     SqlParserPos pos;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5962a936/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 cdec08e..0c95a8c 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
@@ -38,6 +38,7 @@ import org.apache.calcite.util.Pair;
 import org.apache.phoenix.calcite.PhoenixSchema;
 import org.apache.phoenix.calcite.parse.SqlCreateSequence;
 import org.apache.phoenix.calcite.parse.SqlCreateTable;
+import org.apache.phoenix.calcite.parse.SqlDropSequence;
 import org.apache.phoenix.calcite.parse.SqlDropTable;
 import org.apache.phoenix.calcite.parser.PhoenixParserImpl;
 import org.apache.phoenix.calcite.rel.PhoenixRel;
@@ -61,6 +62,7 @@ import org.apache.phoenix.parse.ColumnDef;
 import org.apache.phoenix.parse.ColumnDefInPkConstraint;
 import org.apache.phoenix.parse.CreateSequenceStatement;
 import org.apache.phoenix.parse.CreateTableStatement;
+import org.apache.phoenix.parse.DropSequenceStatement;
 import org.apache.phoenix.parse.DropTableStatement;
 import org.apache.phoenix.parse.ParseNode;
 import org.apache.phoenix.parse.ParseNodeFactory;
@@ -291,6 +293,19 @@ public class PhoenixPrepareImpl extends CalcitePrepareImpl {
                 client.dropTable(drop);
                 break;
             }
+            case DROP_SEQUENCE: {
+                final SqlDropSequence sequence = (SqlDropSequence) node;
+                final TableName name;
+                if (sequence.sequenceName.isSimple()) {
+                    name = TableName.create(null, sequence.sequenceName.getSimple());
+                } else {
+                    name = TableName.create(sequence.sequenceName.names.get(0), sequence.sequenceName.names.get(1));
+                }
+                final DropSequenceStatement drop = nodeFactory.dropSequence(name, sequence.ifExists.booleanValue(), 0);
+                MetaDataClient client = new MetaDataClient(connection);
+                client.dropSequence(drop);
+                break;                
+            }
             default:
                 throw new AssertionError("unknown DDL type " + node.getKind() + " " + node.getClass());
             }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5962a936/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropSequence.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropSequence.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropSequence.java
new file mode 100644
index 0000000..d8e868c
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropSequence.java
@@ -0,0 +1,45 @@
+package org.apache.phoenix.calcite.parse;
+
+import java.util.List;
+
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.parser.SqlParserPos;
+
+import com.google.common.collect.ImmutableList;
+
+public class SqlDropSequence extends SqlCall {
+    public static final SqlOperator OPERATOR = new SqlDdlOperator("DROP SEQUENCE", SqlKind.DROP_SEQUENCE);
+    
+    public final SqlIdentifier sequenceName;
+    public final SqlLiteral ifExists;
+
+    public SqlDropSequence(
+            SqlParserPos pos,
+            SqlIdentifier sequenceName,
+            SqlLiteral ifExists) {
+        super(pos);
+        this.sequenceName = sequenceName;
+        this.ifExists = ifExists;
+    }
+
+    @Override
+    public SqlOperator getOperator() {
+        return OPERATOR;
+    }
+
+    @Override
+    public List<SqlNode> getOperandList() {
+        return ImmutableList.of(sequenceName, ifExists);
+    }
+
+    @Override
+    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
+        // TODO Auto-generated method stub
+    }
+}