You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ra...@apache.org on 2016/12/02 16:20:15 UTC
phoenix git commit: PHOENIX-3256 Support CREATE SCHEMA in
Phoenix-Calcite Integration(Rajeshbabu)
Repository: phoenix
Updated Branches:
refs/heads/calcite f14d5a707 -> c1f4d90b7
PHOENIX-3256 Support CREATE SCHEMA in Phoenix-Calcite Integration(Rajeshbabu)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/c1f4d90b
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/c1f4d90b
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/c1f4d90b
Branch: refs/heads/calcite
Commit: c1f4d90b7cbb1eba7accf44cfb745b4d9ad05493
Parents: f14d5a7
Author: Rajeshbabu Chintaguntla <ra...@apache.org>
Authored: Fri Dec 2 22:00:04 2016 +0530
Committer: Rajeshbabu Chintaguntla <ra...@apache.org>
Committed: Fri Dec 2 22:00:04 2016 +0530
----------------------------------------------------------------------
.../org/apache/phoenix/end2end/UseSchemaIT.java | 2 +-
phoenix-core/src/main/codegen/data/Parser.tdd | 4 +
.../src/main/codegen/includes/parserImpls.ftl | 78 ++++++++++++++++++++
.../phoenix/calcite/PhoenixPrepareImpl.java | 31 +++++++-
.../phoenix/calcite/parse/SqlCreateSchema.java | 58 +++++++++++++++
.../phoenix/calcite/parse/SqlDropSchema.java | 60 +++++++++++++++
.../phoenix/calcite/parse/SqlUseSchema.java | 55 ++++++++++++++
7 files changed, 286 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/c1f4d90b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UseSchemaIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UseSchemaIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UseSchemaIT.java
index 07ae77e..8c48c23 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UseSchemaIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UseSchemaIT.java
@@ -75,7 +75,7 @@ public class UseSchemaIT extends ParallelStatsDisabledIT {
} catch (SQLException e) {
assertEquals(SQLExceptionCode.SCHEMA_NOT_FOUND.getErrorCode(), e.getErrorCode());
}
- conn.createStatement().execute("use default");
+ conn.createStatement().execute("use " + "\"DEFAULT\"");
ddl = "create table IF NOT EXISTS " + testTable + "(schema_name varchar primary key)";
conn.createStatement().execute(ddl);
conn.createStatement().executeUpdate("upsert into " + testTable + " values('"+SchemaUtil.SCHEMA_FOR_DEFAULT_NAMESPACE+"')");
http://git-wip-us.apache.org/repos/asf/phoenix/blob/c1f4d90b/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 42c060a..0df9d8c 100644
--- a/phoenix-core/src/main/codegen/data/Parser.tdd
+++ b/phoenix-core/src/main/codegen/data/Parser.tdd
@@ -53,6 +53,7 @@
"DEFAULTVALUE"
"JARS"
"UPLOAD"
+ "USE"
]
# List of keywords from "keywords" section that are not reserved.
@@ -76,6 +77,9 @@
"SqlUploadJarsNode()"
"SqlDeleteJarNode()"
"SqlAlterTable()"
+ "SqlCreateSchema()"
+ "SqlDropSchema()"
+ "SqlUseSchema()"
]
# List of methods for parsing custom literals.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/c1f4d90b/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 984009e..50e1c7a 100644
--- a/phoenix-core/src/main/codegen/includes/parserImpls.ftl
+++ b/phoenix-core/src/main/codegen/includes/parserImpls.ftl
@@ -457,6 +457,84 @@ SqlNode SqlDropSequence() :
/**
* Parses statement
+ * CREATE SCHEMA
+ */
+SqlNode SqlCreateSchema() :
+{
+ SqlParserPos pos;
+ SqlIdentifier schemaName;
+ boolean ifNotExists;
+}
+{
+ <CREATE> { pos = getPos(); } <SCHEMA>
+ (
+ <IF> <NOT> <EXISTS> { ifNotExists = true; }
+ |
+ {
+ ifNotExists = false;
+ }
+ )
+ schemaName = SimpleIdentifier()
+ {
+ return new SqlCreateSchema(pos.plus(getPos()), schemaName,
+ SqlLiteral.createBoolean(ifNotExists, SqlParserPos.ZERO));
+ }
+}
+
+/**
+ * Parses statement
+ * DROP SCHEMA
+ */
+SqlNode SqlDropSchema() :
+{
+ SqlParserPos pos;
+ SqlIdentifier schemaName;
+ boolean ifExists;
+ boolean cascade;
+}
+{
+ <DROP> { pos = getPos(); } <SCHEMA>
+ (
+ <IF> <EXISTS> { ifExists = true; }
+ |
+ {
+ ifExists = false;
+ }
+ )
+ schemaName = SimpleIdentifier()
+ (
+ <CASCADE> { cascade = true; }
+ |
+ {
+ cascade = false;
+ }
+ )
+ {
+ return new SqlDropSchema(pos.plus(getPos()), schemaName,
+ SqlLiteral.createBoolean(ifExists, SqlParserPos.ZERO),
+ SqlLiteral.createBoolean(cascade, SqlParserPos.ZERO));
+ }
+}
+
+/**
+ * Parses statement
+ * USE SCHEMA
+ */
+SqlNode SqlUseSchema() :
+{
+ SqlParserPos pos;
+ SqlIdentifier schemaName;
+}
+{
+ <USE> { pos = getPos(); }
+ schemaName = SimpleIdentifier()
+ {
+ return new SqlUseSchema(pos.plus(getPos()), schemaName);
+ }
+}
+
+/**
+ * Parses statement
* UPDATE STATISTICS
*/
SqlNode SqlUpdateStatistics() :
http://git-wip-us.apache.org/repos/asf/phoenix/blob/c1f4d90b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
index 1489ae8..c907dac 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
@@ -49,15 +49,18 @@ import org.apache.hadoop.hbase.util.Pair;
import org.apache.phoenix.calcite.parse.SqlAlterTable;
import org.apache.phoenix.calcite.parse.SqlCreateFunction;
import org.apache.phoenix.calcite.parse.SqlCreateIndex;
+import org.apache.phoenix.calcite.parse.SqlCreateSchema;
import org.apache.phoenix.calcite.parse.SqlCreateSequence;
import org.apache.phoenix.calcite.parse.SqlCreateTable;
import org.apache.phoenix.calcite.parse.SqlDeleteJarNode;
import org.apache.phoenix.calcite.parse.SqlDropFunction;
import org.apache.phoenix.calcite.parse.SqlDropIndex;
+import org.apache.phoenix.calcite.parse.SqlDropSchema;
import org.apache.phoenix.calcite.parse.SqlDropSequence;
import org.apache.phoenix.calcite.parse.SqlDropTable;
import org.apache.phoenix.calcite.parse.SqlUpdateStatistics;
import org.apache.phoenix.calcite.parse.SqlUploadJarsNode;
+import org.apache.phoenix.calcite.parse.SqlUseSchema;
import org.apache.phoenix.calcite.parser.PhoenixParserImpl;
import org.apache.phoenix.calcite.rel.PhoenixRel;
import org.apache.phoenix.calcite.rel.PhoenixServerProject;
@@ -87,11 +90,13 @@ import org.apache.phoenix.parse.ColumnDefInPkConstraint;
import org.apache.phoenix.parse.ColumnName;
import org.apache.phoenix.parse.CreateFunctionStatement;
import org.apache.phoenix.parse.CreateIndexStatement;
+import org.apache.phoenix.parse.CreateSchemaStatement;
import org.apache.phoenix.parse.CreateSequenceStatement;
import org.apache.phoenix.parse.CreateTableStatement;
import org.apache.phoenix.parse.DropColumnStatement;
import org.apache.phoenix.parse.DropFunctionStatement;
import org.apache.phoenix.parse.DropIndexStatement;
+import org.apache.phoenix.parse.DropSchemaStatement;
import org.apache.phoenix.parse.DropSequenceStatement;
import org.apache.phoenix.parse.DropTableStatement;
import org.apache.phoenix.parse.IndexKeyConstraint;
@@ -107,12 +112,14 @@ import org.apache.phoenix.parse.SQLParser;
import org.apache.phoenix.parse.TableName;
import org.apache.phoenix.parse.UDFParseNode;
import org.apache.phoenix.parse.UpdateStatisticsStatement;
+import org.apache.phoenix.parse.UseSchemaStatement;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.MetaDataClient;
import org.apache.phoenix.schema.PTable.IndexType;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.Sequence;
import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.util.SchemaUtil;
import com.google.common.base.Function;
import com.google.common.collect.ArrayListMultimap;
@@ -602,6 +609,29 @@ public class PhoenixPrepareImpl extends CalcitePrepareImpl {
new PhoenixStatement.ExecutableDeleteJarStatement(jarPath).compilePlan(phoenixStatement,
Sequence.ValueOp.VALIDATE_SEQUENCE);
((BaseMutationPlan) compilePlan).execute();
+ } else if( node instanceof SqlCreateSchema) {
+ SqlCreateSchema createSchemaNode = (SqlCreateSchema) node;
+ CreateSchemaStatement createSchema =
+ nodeFactory.createSchema(createSchemaNode.schemaName.getSimple(),
+ createSchemaNode.ifNotExists.booleanValue());
+ MetaDataClient client = new MetaDataClient(connection);
+ client.createSchema(createSchema);
+ } else if( node instanceof SqlDropSchema) {
+ SqlDropSchema dropSchemaNode = (SqlDropSchema) node;
+ DropSchemaStatement dropSchema =
+ nodeFactory.dropSchema(dropSchemaNode.schemaName.getSimple(),
+ dropSchemaNode.ifExists.booleanValue(),
+ dropSchemaNode.cascade.booleanValue());
+ MetaDataClient client = new MetaDataClient(connection);
+ client.dropSchema(dropSchema);
+ } else if( node instanceof SqlUseSchema) {
+ SqlUseSchema useSchemaNode = (SqlUseSchema) node;
+ UseSchemaStatement useSchema =
+ nodeFactory.useSchema(useSchemaNode.schemaName.getSimple().equals(
+ SchemaUtil.SCHEMA_FOR_DEFAULT_NAMESPACE) ? null
+ : useSchemaNode.schemaName.getSimple());
+ MetaDataClient client = new MetaDataClient(connection);
+ client.useSchema(useSchema);
} else {
throw new AssertionError("unknown DDL node " + node.getClass());
}
@@ -667,7 +697,6 @@ public class PhoenixPrepareImpl extends CalcitePrepareImpl {
} catch (ClassCastException e) {
}
}
-
throw new RuntimeException("Phoenix schema not found.");
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/c1f4d90b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlCreateSchema.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlCreateSchema.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlCreateSchema.java
new file mode 100644
index 0000000..17820d9
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlCreateSchema.java
@@ -0,0 +1,58 @@
+/*
+ * 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.parser.SqlParserPos;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Parse tree node for SQL {@code CREATE SCHEMA} command.
+ */
+public class SqlCreateSchema extends SqlCall {
+ public final SqlOperator operator;
+
+ public final SqlIdentifier schemaName;
+ public final SqlLiteral ifNotExists;
+
+ /** Creates a CREATE SCHEMA. */
+ public SqlCreateSchema(SqlParserPos pos, SqlIdentifier schemaName, SqlLiteral ifNotExists) {
+ super(pos);
+ this.operator = new SqlDdlOperator("CREATE SCHEMA", SqlKind.OTHER_DDL);
+ this.schemaName = schemaName;
+ this.ifNotExists = ifNotExists;
+ }
+
+ @Override
+ public SqlOperator getOperator() {
+ return this.operator;
+ }
+
+ @Override
+ public List<SqlNode> getOperandList() {
+ return ImmutableList.of(schemaName, ifNotExists);
+ }
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/c1f4d90b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropSchema.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropSchema.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropSchema.java
new file mode 100644
index 0000000..9812a97
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropSchema.java
@@ -0,0 +1,60 @@
+/*
+ * 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.parser.SqlParserPos;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Parse tree node for SQL {@code DROP SCHEMA} command.
+ */
+public class SqlDropSchema extends SqlCall {
+ public final SqlOperator operator;
+
+ public final SqlIdentifier schemaName;
+ public final SqlLiteral ifExists;
+ public final SqlLiteral cascade;
+
+ /** Creates a DROP SCHEMA. */
+ public SqlDropSchema(SqlParserPos pos, SqlIdentifier schemaName, SqlLiteral ifExists, SqlLiteral cascade) {
+ super(pos);
+ this.operator = new SqlDdlOperator("DROP SCHEMA", SqlKind.OTHER_DDL);
+ this.schemaName = schemaName;
+ this.ifExists = ifExists;
+ this.cascade = cascade;
+ }
+
+ @Override
+ public SqlOperator getOperator() {
+ return this.operator;
+ }
+
+ @Override
+ public List<SqlNode> getOperandList() {
+ return ImmutableList.of(schemaName, ifExists, cascade);
+ }
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/c1f4d90b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlUseSchema.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlUseSchema.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlUseSchema.java
new file mode 100644
index 0000000..bb116a8
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlUseSchema.java
@@ -0,0 +1,55 @@
+/*
+ * 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.SqlNode;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.parser.SqlParserPos;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Parse tree node for SQL {@code USE SCHEMA} command.
+ */
+public class SqlUseSchema extends SqlCall {
+ public final SqlOperator operator;
+
+ public final SqlIdentifier schemaName;
+
+ /** Creates a USE SCHEMA. */
+ public SqlUseSchema(SqlParserPos pos, SqlIdentifier schemaName) {
+ super(pos);
+ this.operator = new SqlDdlOperator("USE SCHEMA", SqlKind.OTHER_DDL);
+ this.schemaName = schemaName;
+ }
+
+ @Override
+ public SqlOperator getOperator() {
+ return this.operator;
+ }
+
+ @Override
+ public List<SqlNode> getOperandList() {
+ return ImmutableList.of((SqlNode)schemaName);
+ }
+}
\ No newline at end of file