Repository: phoenix Updated Branches: refs/heads/calcite 28ec5c872 -> 9a79dc99a
PHOENIX-2740 Support DROP INDEX 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/9a79dc99 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/9a79dc99 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/9a79dc99 Branch: refs/heads/calcite Commit: 9a79dc99a54206e038e9577e4937e50e950b09be Parents: 28ec5c8 Author: maryannxue <maryann....@gmail.com> Authored: Thu Aug 4 13:35:00 2016 -0400 Committer: maryannxue <maryann....@gmail.com> Committed: Thu Aug 4 13:35:00 2016 -0400 ---------------------------------------------------------------------- .../apache/phoenix/calcite/CalciteDDLIT.java | 35 ++++++----- phoenix-core/src/main/codegen/data/Parser.tdd | 1 + .../src/main/codegen/includes/parserImpls.ftl | 29 +++++++++ .../calcite/jdbc/PhoenixPrepareImpl.java | 16 +++++ .../phoenix/calcite/parse/SqlDdlOperator.java | 17 +++++ .../phoenix/calcite/parse/SqlDropIndex.java | 65 ++++++++++++++++++++ .../phoenix/calcite/parse/SqlDropSequence.java | 17 +++++ .../phoenix/calcite/parse/SqlDropTable.java | 17 +++++ 8 files changed, 180 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a79dc99/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 d3c45ae..1814516 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 @@ -8,35 +8,36 @@ public class CalciteDDLIT extends BaseCalciteIT { private static final Properties PROPS = new Properties(); @Test public void testCreateView() throws Exception { - start(PROPS).sql("create table \"t0\"(\"a\" varchar(20) not null primary key, b integer)").execute(); - start(PROPS).sql("create view v1 as select * from \"t0\"").execute(); - start(PROPS).sql("create view v2 as select * from \"t0\" where \"a\" = 'x'").execute(); + start(PROPS).sql("create table \"t0\"(\"a\" varchar(20) not null primary key, b integer)").execute().close(); + start(PROPS).sql("create view v1 as select * from \"t0\"").execute().close(); + start(PROPS).sql("create view v2 as select * from \"t0\" where \"a\" = 'x'").execute().close(); } @Test public void testCreateTable() throws Exception { - start(PROPS).sql("create table t1(a varchar(20) not null primary key, b integer, c decimal(10, 2), d integer array, e varchar array[5])").execute(); - start(PROPS).sql("create table if not exists t1(a varchar not null primary key, b integer)").execute(); + start(PROPS).sql("create table t1(a varchar(20) not null primary key, b integer, c decimal(10, 2), d integer array, e varchar array[5])").execute().close(); + start(PROPS).sql("create table if not exists t1(a varchar not null primary key, b integer)").execute().close(); } @Test public void testCreateTableWithPrimaryKeyConstraint() throws Exception { - start(PROPS).sql("create table t2(a bigint not null ROW_TIMESTAMP, b integer not null, c double constraint pk primary key(a,b)) SPLIT ON('a','b')").execute(); + start(PROPS).sql("create table t2(a bigint not null ROW_TIMESTAMP, b integer not null, c double constraint pk primary key(a,b)) SPLIT ON('a','b')").execute().close(); } @Test public void testCreateTableWithTableOptions() throws Exception { - start(PROPS).sql("create table t3(a bigint not null ROW_TIMESTAMP, b integer not null, c double constraint pk primary key(a,b)) SALT_BUCKET=4").execute(); + start(PROPS).sql("create table t3(a bigint not null ROW_TIMESTAMP, b integer not null, c double constraint pk primary key(a,b)) SALT_BUCKET=4").execute().close(); } @Test public void testCreateTableWithTableOptionsAndSplits() throws Exception { - 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(); + 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().close(); } @Test public void testCreateAndDropIndex() throws Exception { - start(PROPS).sql("create table itest(a varchar(20) not null primary key, b integer, c decimal(10, 2), d bigint, e varchar)").execute(); - start(PROPS).sql("create index idx1 on itest(b desc, c) include (d)").execute(); - start(PROPS).sql("create local index idx2 on itest(d, e desc)").execute(); - start(PROPS).sql("create index if not exists idx3 on itest(b + c) include (d, e)").execute(); - //start(PROPS).sql("drop index idx1").execute(); - //start(PROPS).sql("drop index if exists idx2").execute(); + start(PROPS).sql("create table itest(a varchar(20) not null primary key, b integer, c decimal(10, 2), d bigint, e varchar)").execute().close(); + start(PROPS).sql("create index idx1 on itest(b desc, c) include (d)").execute().close(); + start(PROPS).sql("create local index idx2 on itest(d, e desc)").execute().close(); + start(PROPS).sql("create index if not exists idx3 on itest(b + c) include (d, e)").execute().close(); + start(PROPS).sql("drop index idx1 on itest").execute().close(); + start(PROPS).sql("drop index if exists idx2 on itest").execute().close(); + start(PROPS).sql("drop index idx3 on itest").execute().close(); } @Test public void testCreateAndDropSequence() throws Exception { @@ -45,8 +46,8 @@ public class CalciteDDLIT extends BaseCalciteIT { } @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(); - start(PROPS).sql("create table t5(a bigint not null primary key, b varchar)").execute(); + start(PROPS).sql("create table t5(a varchar not null primary key, b varchar)").execute().close(); + start(PROPS).sql("drop table t5").execute().close(); + start(PROPS).sql("create table t5(a bigint not null primary key, b varchar)").execute().close(); } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a79dc99/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 8bfe486..a3091fd 100644 --- a/phoenix-core/src/main/codegen/data/Parser.tdd +++ b/phoenix-core/src/main/codegen/data/Parser.tdd @@ -58,6 +58,7 @@ "SqlCreateIndex()", "SqlCreateSequence()", "SqlDropTableOrDropView()", + "SqlDropIndex()", "SqlDropSequence()", ] http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a79dc99/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 cdcded1..f501e33 100644 --- a/phoenix-core/src/main/codegen/includes/parserImpls.ftl +++ b/phoenix-core/src/main/codegen/includes/parserImpls.ftl @@ -330,6 +330,35 @@ SqlNode SqlDropTableOrDropView() : /** * Parses statement + * DROP INDEX + */ +SqlNode SqlDropIndex() : +{ + SqlParserPos pos; + SqlIdentifier indexName; + boolean ifExists; + SqlIdentifier dataTableName; +} +{ + <DROP> { pos = getPos(); } <INDEX> + ( + <IF> <EXISTS> { ifExists = true; } + | + { + ifExists = false; + } + ) + indexName = SimpleIdentifier() + <ON> + dataTableName = DualIdentifier() + { + return new SqlDropIndex(pos.plus(getPos()), indexName, + SqlLiteral.createBoolean(ifExists, SqlParserPos.ZERO), dataTableName); + } +} + +/** + * Parses statement * DROP SEQUENCE */ SqlNode SqlDropSequence() : http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a79dc99/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 e4afbe0..0a3baa9 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 @@ -43,6 +43,7 @@ import org.apache.phoenix.calcite.PhoenixSchema; import org.apache.phoenix.calcite.parse.SqlCreateIndex; import org.apache.phoenix.calcite.parse.SqlCreateSequence; import org.apache.phoenix.calcite.parse.SqlCreateTable; +import org.apache.phoenix.calcite.parse.SqlDropIndex; import org.apache.phoenix.calcite.parse.SqlDropSequence; import org.apache.phoenix.calcite.parse.SqlDropTable; import org.apache.phoenix.calcite.parser.PhoenixParserImpl; @@ -70,6 +71,7 @@ import org.apache.phoenix.parse.ColumnName; import org.apache.phoenix.parse.CreateIndexStatement; import org.apache.phoenix.parse.CreateSequenceStatement; import org.apache.phoenix.parse.CreateTableStatement; +import org.apache.phoenix.parse.DropIndexStatement; import org.apache.phoenix.parse.DropSequenceStatement; import org.apache.phoenix.parse.DropTableStatement; import org.apache.phoenix.parse.IndexKeyConstraint; @@ -379,6 +381,20 @@ public class PhoenixPrepareImpl extends CalcitePrepareImpl { client.dropTable(drop); break; } + case DROP_INDEX: { + final SqlDropIndex index = (SqlDropIndex) node; + final NamedNode name = NamedNode.caseSensitiveNamedNode(index.indexName.getSimple()); + final TableName dataTableName; + if (index.dataTableName.isSimple()) { + dataTableName = TableName.create(null, index.dataTableName.getSimple()); + } else { + dataTableName = TableName.create(index.dataTableName.names.get(0), index.dataTableName.names.get(1)); + } + final DropIndexStatement drop = nodeFactory.dropIndex(name, dataTableName, index.ifExists.booleanValue()); + MetaDataClient client = new MetaDataClient(connection); + client.dropIndex(drop); + break; + } case DROP_SEQUENCE: { final SqlDropSequence sequence = (SqlDropSequence) node; final TableName name; http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a79dc99/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDdlOperator.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDdlOperator.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDdlOperator.java index c1009b1..1ccd5c7 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDdlOperator.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDdlOperator.java @@ -1,3 +1,20 @@ +/* + * 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 org.apache.calcite.sql.SqlCall; http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a79dc99/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropIndex.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropIndex.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropIndex.java new file mode 100644 index 0000000..0fcafd8 --- /dev/null +++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropIndex.java @@ -0,0 +1,65 @@ +/* + * 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 SqlDropIndex extends SqlCall { + public static final SqlOperator OPERATOR = new SqlDdlOperator("DROP INDEX", SqlKind.DROP_INDEX); + + public final SqlIdentifier indexName; + public final SqlLiteral ifExists; + public final SqlIdentifier dataTableName; + + public SqlDropIndex( + SqlParserPos pos, + SqlIdentifier indexName, + SqlLiteral ifExists, + SqlIdentifier dataTableName) { + super(pos); + this.indexName = indexName; + this.ifExists = ifExists; + this.dataTableName = dataTableName; + } + + @Override + public SqlOperator getOperator() { + return OPERATOR; + } + + @Override + public List<SqlNode> getOperandList() { + return ImmutableList.of(indexName, ifExists, dataTableName); + } + + @Override + public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { + // TODO Auto-generated method stub + } +} http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a79dc99/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 index d8e868c..a636071 100644 --- 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 @@ -1,3 +1,20 @@ +/* + * 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; http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a79dc99/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropTable.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropTable.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropTable.java index 27f61aa..cf89cb6 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropTable.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/parse/SqlDropTable.java @@ -1,3 +1,20 @@ +/* + * 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;