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:03:56 UTC
phoenix git commit: PHOENIX-2231 Support CREATE SEQUENCE in
Phoenix/Calcite Integration
Repository: phoenix
Updated Branches:
refs/heads/calcite 50c797ffa -> 8b8563f47
PHOENIX-2231 Support CREATE 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/8b8563f4
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/8b8563f4
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/8b8563f4
Branch: refs/heads/calcite
Commit: 8b8563f4725bac5c1807222103c17dd5ecaa54c1
Parents: 50c797f
Author: maryannxue <ma...@gmail.com>
Authored: Mon Aug 1 15:03:45 2016 -0400
Committer: maryannxue <ma...@gmail.com>
Committed: Mon Aug 1 15:03:45 2016 -0400
----------------------------------------------------------------------
.../apache/phoenix/calcite/CalciteDDLIT.java | 4 +
phoenix-core/src/main/codegen/data/Parser.tdd | 2 +
.../src/main/codegen/includes/parserImpls.ftl | 59 ++++++++++++--
.../calcite/jdbc/PhoenixPrepareImpl.java | 24 ++++++
.../calcite/parse/SqlCreateSequence.java | 81 ++++++++++++++++++++
5 files changed, 165 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8b8563f4/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 22b7474..970e68d 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,6 +30,10 @@ 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 {
+ start(PROPS).sql("create sequence if not exists s0 start with 2 increment 3 minvalue 2 maxvalue 90 cycle cache 3").execute().close();
+ }
+
@Test public void testDropTable() throws Exception {
start(PROPS).sql("create table t5(a varchar not null primary key, b varchar)").execute();
start(PROPS).sql("drop table t5").execute();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8b8563f4/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 75df3fc..04f073c 100644
--- a/phoenix-core/src/main/codegen/data/Parser.tdd
+++ b/phoenix-core/src/main/codegen/data/Parser.tdd
@@ -38,6 +38,7 @@
"IF"
"ROW_TIMESTAMP"
"SPLIT"
+ "CACHE"
]
# List of keywords from "keywords" section that are not reserved.
@@ -50,6 +51,7 @@
"SqlPhoenixExplain()",
"SqlCreateView()",
"SqlCreateTable()",
+ "SqlCreateSequence()",
"SqlDropTableOrDropView()",
]
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8b8563f4/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 383e5b4..8256738 100644
--- a/phoenix-core/src/main/codegen/includes/parserImpls.ftl
+++ b/phoenix-core/src/main/codegen/includes/parserImpls.ftl
@@ -178,6 +178,60 @@ SqlNode SqlCreateTable() :
/**
* Parses statement
+ * CREATE SEQUENCE
+ */
+SqlNode SqlCreateSequence() :
+{
+ SqlParserPos pos;
+ SqlIdentifier sequenceName;
+ boolean ifNotExists = false;
+ SqlLiteral startWith = null;
+ SqlLiteral incrementBy = null;
+ SqlLiteral minValue = null;
+ SqlLiteral maxValue = null;
+ boolean cycle = false;
+ SqlLiteral cache = null;
+ Integer v;
+}
+{
+ <CREATE> { pos = getPos(); } <SEQUENCE>
+ [
+ <IF> <NOT> <EXISTS> { ifNotExists = true; }
+ ]
+ sequenceName = DualIdentifier()
+ [
+ <START> [ <WITH> ]
+ v = UnsignedIntLiteral() { startWith = SqlLiteral.createExactNumeric(v.toString(), getPos()); }
+ ]
+ [
+ <INCREMENT> [ <BY> ]
+ v = UnsignedIntLiteral() { incrementBy = SqlLiteral.createExactNumeric(v.toString(), getPos()); }
+ ]
+ [
+ <MINVALUE>
+ v = UnsignedIntLiteral() { minValue = SqlLiteral.createExactNumeric(v.toString(), getPos()); }
+ ]
+ [
+ <MAXVALUE>
+ v = UnsignedIntLiteral() { maxValue = SqlLiteral.createExactNumeric(v.toString(), getPos()); }
+ ]
+ [
+ <CYCLE> { cycle = true; }
+ ]
+ [
+ <CACHE>
+ v = UnsignedIntLiteral() { cache = SqlLiteral.createExactNumeric(v.toString(), getPos()); }
+ ]
+ {
+ return new SqlCreateSequence(pos.plus(getPos()), sequenceName,
+ SqlLiteral.createBoolean(ifNotExists, SqlParserPos.ZERO),
+ startWith, incrementBy, minValue, maxValue,
+ SqlLiteral.createBoolean(cycle, SqlParserPos.ZERO), cache);
+ }
+}
+
+/**
+ * Parses statement
* DROP TABLE
*/
SqlNode SqlDropTableOrDropView() :
@@ -290,13 +344,8 @@ SqlColumnDefNode ColumnDef() :
SqlIdentifier columnName;
SqlDataTypeNode dataType;
boolean isNull = true;
- Integer maxLength = null;
- Integer scale = null;
boolean isPk = false;
SortOrder sortOrder = SortOrder.getDefault();
- boolean isArray = false;
- Integer arrSize = null;
- String expressionStr = null;
boolean isRowTimestamp = false;
SqlParserPos pos;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8b8563f4/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 24dcbaf..cdec08e 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
@@ -36,6 +36,7 @@ import org.apache.calcite.util.Holder;
import org.apache.calcite.util.NlsString;
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.SqlDropTable;
import org.apache.phoenix.calcite.parser.PhoenixParserImpl;
@@ -50,6 +51,7 @@ import org.apache.phoenix.calcite.rules.PhoenixOrderedAggregateRule;
import org.apache.phoenix.calcite.rules.PhoenixReverseTableScanRule;
import org.apache.phoenix.calcite.rules.PhoenixSortServerJoinTransposeRule;
import org.apache.phoenix.calcite.rules.PhoenixTableScanColumnRefRule;
+import org.apache.phoenix.compile.CreateSequenceCompiler;
import org.apache.phoenix.compile.CreateTableCompiler;
import org.apache.phoenix.compile.MutationPlan;
import org.apache.phoenix.jdbc.PhoenixConnection;
@@ -57,6 +59,7 @@ import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.jdbc.PhoenixStatement.Operation;
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.DropTableStatement;
import org.apache.phoenix.parse.ParseNode;
@@ -251,6 +254,27 @@ public class PhoenixPrepareImpl extends CalcitePrepareImpl {
}
break;
}
+ case CREATE_SEQUENCE: {
+ final SqlCreateSequence sequence = (SqlCreateSequence) 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 ParseNode startWith = nodeFactory.literal(sequence.startWith.intValue(true));
+ final ParseNode incrementBy = nodeFactory.literal(sequence.incrementBy.intValue(true));
+ final ParseNode minValue = nodeFactory.literal(sequence.minValue.intValue(true));
+ final ParseNode maxValue = nodeFactory.literal(sequence.maxValue.intValue(true));
+ final ParseNode cache = nodeFactory.literal(sequence.cache.intValue(true));
+ final CreateSequenceStatement create = nodeFactory.createSequence(name, startWith, incrementBy, cache, minValue, maxValue, sequence.cycle.booleanValue(), sequence.ifNotExists.booleanValue(), 0);
+ try (final PhoenixStatement stmt = new PhoenixStatement(connection)) {
+ final CreateSequenceCompiler compiler = new CreateSequenceCompiler(stmt, Operation.UPSERT);
+ final MutationPlan plan = compiler.compile(create);
+ plan.execute();
+ }
+ break;
+ }
case DROP_TABLE:
case DROP_VIEW: {
final SqlDropTable table = (SqlDropTable) node;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/8b8563f4/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlCreateSequence.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlCreateSequence.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlCreateSequence.java
new file mode 100644
index 0000000..8e09546
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlCreateSequence.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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 SqlCreateSequence extends SqlCall {
+ public static final SqlOperator OPERATOR = new SqlDdlOperator("CREATE SEQUENCE", SqlKind.CREATE_SEQUENCE);
+
+ public final SqlIdentifier sequenceName;
+ public final SqlLiteral ifNotExists;
+ public final SqlLiteral startWith;
+ public final SqlLiteral incrementBy;
+ public final SqlLiteral minValue;
+ public final SqlLiteral maxValue;
+ public final SqlLiteral cycle;
+ public final SqlLiteral cache;
+
+ public SqlCreateSequence(
+ SqlParserPos pos,
+ SqlIdentifier sequenceName,
+ SqlLiteral ifNotExists,
+ SqlLiteral startWith,
+ SqlLiteral incrementBy,
+ SqlLiteral minValue,
+ SqlLiteral maxValue,
+ SqlLiteral cycle,
+ SqlLiteral cache) {
+ super(pos);
+ this.sequenceName = sequenceName;
+ this.ifNotExists = ifNotExists;
+ this.startWith = startWith;
+ this.incrementBy = incrementBy;
+ this.minValue = minValue;
+ this.maxValue = maxValue;
+ this.cycle = cycle;
+ this.cache = cache;
+ }
+
+ @Override
+ public SqlOperator getOperator() {
+ return OPERATOR;
+ }
+
+ @Override
+ public List<SqlNode> getOperandList() {
+ return ImmutableList.of(sequenceName, ifNotExists, startWith, incrementBy, minValue, maxValue, cycle, cache);
+ }
+
+ @Override
+ public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
+ // TODO Auto-generated method stub
+ }
+
+}