Return-Path: X-Original-To: apmail-calcite-commits-archive@www.apache.org Delivered-To: apmail-calcite-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D428519A46 for ; Sat, 30 Apr 2016 01:25:03 +0000 (UTC) Received: (qmail 58709 invoked by uid 500); 30 Apr 2016 01:25:03 -0000 Delivered-To: apmail-calcite-commits-archive@calcite.apache.org Received: (qmail 58670 invoked by uid 500); 30 Apr 2016 01:25:03 -0000 Mailing-List: contact commits-help@calcite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@calcite.apache.org Delivered-To: mailing list commits@calcite.apache.org Received: (qmail 58615 invoked by uid 99); 30 Apr 2016 01:25:03 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 30 Apr 2016 01:25:03 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 76775DFFD9; Sat, 30 Apr 2016 01:25:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jhyde@apache.org To: commits@calcite.apache.org Date: Sat, 30 Apr 2016 01:25:04 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/3] calcite git commit: [CALCITE-1168] Add DESCRIBE statement (Arina Ielchiieva) [CALCITE-1168] Add DESCRIBE statement (Arina Ielchiieva) Project: http://git-wip-us.apache.org/repos/asf/calcite/repo Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/a065200a Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/a065200a Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/a065200a Branch: refs/heads/master Commit: a065200ad714ed5f9015e8a00b534c10f9fa6a15 Parents: b7fbb35 Author: Arina Ielchiieva Authored: Mon Mar 28 19:13:22 2016 +0300 Committer: Julian Hyde Committed: Fri Apr 29 16:53:38 2016 -0700 ---------------------------------------------------------------------- core/src/main/codegen/templates/Parser.jj | 41 ++++++++ .../apache/calcite/sql/SqlDescribeSchema.java | 77 ++++++++++++++ .../apache/calcite/sql/SqlDescribeTable.java | 104 +++++++++++++++++++ .../java/org/apache/calcite/sql/SqlKind.java | 5 + .../calcite/sql/parser/SqlParserTest.java | 18 ++++ site/_docs/reference.md | 6 ++ 6 files changed, 251 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/a065200a/core/src/main/codegen/templates/Parser.jj ---------------------------------------------------------------------- diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj index c1df4cb..3419abc 100644 --- a/core/src/main/codegen/templates/Parser.jj +++ b/core/src/main/codegen/templates/Parser.jj @@ -48,6 +48,8 @@ import org.apache.calcite.sql.SqlCollation; import org.apache.calcite.sql.SqlDataTypeSpec; import org.apache.calcite.sql.SqlDateLiteral; import org.apache.calcite.sql.SqlDelete; +import org.apache.calcite.sql.SqlDescribeSchema; +import org.apache.calcite.sql.SqlDescribeTable; import org.apache.calcite.sql.SqlDynamicParam; import org.apache.calcite.sql.SqlExplain; import org.apache.calcite.sql.SqlExplainLevel; @@ -928,6 +930,8 @@ SqlNode SqlStmt() : | stmt = SqlExplain() | + stmt = SqlDescribe() + | stmt = SqlInsert() | stmt = SqlDelete() @@ -1126,6 +1130,41 @@ SqlExplainLevel ExplainDetailLevel() : } /** +* Parsers DESCRIBE statement call +*/ +SqlNode SqlDescribe() : +{ + SqlParserPos pos; + SqlIdentifier table; + SqlIdentifier column = null; + SqlNode columnQualifier = null; +} +{ +( + { pos = getPos(); } + ( | ) + { + return new SqlDescribeSchema(pos, CompoundIdentifier()); + } +) + | +( + { pos = getPos(); } + table = CompoundIdentifier() + ( + column = CompoundIdentifier() + | + columnQualifier = StringLiteral() + | + E() + ) + { + return new SqlDescribeTable(pos, table, column, columnQualifier); + } +) +} + +/** * Parses a CALL statement. */ SqlNode SqlProcedureCall() : @@ -4838,6 +4877,7 @@ SqlPostfixOperator PostfixRowOperator() : | < CURSOR_NAME: "CURSOR_NAME" > | < CYCLE: "CYCLE" > | < DATA: "DATA" > + | < DATABASE: "DATABASE" > | < DATE: "DATE" > | < DATETIME_INTERVAL_CODE: "DATETIME_INTERVAL_CODE" > | < DATETIME_INTERVAL_PRECISION: "DATETIME_INTERVAL_PRECISION" > @@ -5340,6 +5380,7 @@ String CommonNonReservedKeyWord() : | | | + | | | | http://git-wip-us.apache.org/repos/asf/calcite/blob/a065200a/core/src/main/java/org/apache/calcite/sql/SqlDescribeSchema.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDescribeSchema.java b/core/src/main/java/org/apache/calcite/sql/SqlDescribeSchema.java new file mode 100644 index 0000000..f69b31e --- /dev/null +++ b/core/src/main/java/org/apache/calcite/sql/SqlDescribeSchema.java @@ -0,0 +1,77 @@ +/* + * 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.calcite.sql; + +import org.apache.calcite.sql.parser.SqlParserPos; +import org.apache.calcite.util.ImmutableNullableList; + +import java.util.List; + +/** + * A SqlDescribeSchema is a node of a parse tree which represents an + * DESCRIBE SCHEMA statement. + */ +public class SqlDescribeSchema extends SqlCall { + + public static final SqlSpecialOperator OPERATOR = + new SqlSpecialOperator("DESCRIBE_SCHEMA", SqlKind.DESCRIBE) { + @Override public SqlCall createCall(SqlLiteral functionQualifier, + SqlParserPos pos, SqlNode... operands) { + return new SqlDescribeSchema(pos, (SqlIdentifier) operands[0]); + } + }; + + SqlIdentifier schema; + + public SqlDescribeSchema(SqlParserPos pos, SqlIdentifier schema) { + super(pos); + this.schema = schema; + } + + @Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { + writer.keyword("DESCRIBE"); + writer.keyword("SCHEMA"); + schema.unparse(writer, leftPrec, rightPrec); + } + + @Override public void setOperand(int i, SqlNode operand) { + switch (i) { + case 0: + schema = (SqlIdentifier) operand; + break; + default: + throw new AssertionError(i); + } + } + + @Override public SqlKind getKind() { + return SqlKind.DESCRIBE; + } + + @Override public SqlOperator getOperator() { + return OPERATOR; + } + + @Override public List getOperandList() { + return ImmutableNullableList.of((SqlNode) schema); + } + + public SqlIdentifier getSchema() { return schema; } +} + +// End SqlDescribeSchema.java http://git-wip-us.apache.org/repos/asf/calcite/blob/a065200a/core/src/main/java/org/apache/calcite/sql/SqlDescribeTable.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDescribeTable.java b/core/src/main/java/org/apache/calcite/sql/SqlDescribeTable.java new file mode 100644 index 0000000..e058e07 --- /dev/null +++ b/core/src/main/java/org/apache/calcite/sql/SqlDescribeTable.java @@ -0,0 +1,104 @@ +/* + * 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.calcite.sql; + +import org.apache.calcite.sql.parser.SqlParserPos; +import org.apache.calcite.util.ImmutableNullableList; + +import java.util.List; + +/** + * A SqlDescribeTable is a node of a parse tree which represents an + * DESCRIBE table statement. + */ +public class SqlDescribeTable extends SqlCall { + + public static final SqlSpecialOperator OPERATOR = + new SqlSpecialOperator("DESCRIBE_TABLE", SqlKind.DESCRIBE) { + @Override public SqlCall createCall(SqlLiteral functionQualifier, + SqlParserPos pos, + SqlNode... operands) { + return new SqlDescribeTable(pos, + (SqlIdentifier) operands[0], + (SqlIdentifier) operands[1], + operands[2]); + } + }; + + SqlIdentifier table; + SqlIdentifier column; + SqlNode columnQualifier; + + public SqlDescribeTable(SqlParserPos pos, + SqlIdentifier table, + SqlIdentifier column, + SqlNode columnQualifier) { + super(pos); + this.table = table; + this.column = column; + this.columnQualifier = columnQualifier; + } + + @Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { + writer.keyword("DESCRIBE"); + table.unparse(writer, leftPrec, rightPrec); + if (column != null) { + column.unparse(writer, leftPrec, rightPrec); + } + if (columnQualifier != null) { + columnQualifier.unparse(writer, leftPrec, rightPrec); + } + } + + + @Override public void setOperand(int i, SqlNode operand) { + switch (i) { + case 0: + table = (SqlIdentifier) operand; + break; + case 1: + column = (SqlIdentifier) operand; + break; + case 2: + columnQualifier = operand; + break; + default: + throw new AssertionError(i); + } + } + + @Override public SqlKind getKind() { + return SqlKind.DESCRIBE; + } + + @Override public SqlOperator getOperator() { + return OPERATOR; + } + + @Override public List getOperandList() { + return ImmutableNullableList.of(table, column, columnQualifier); + } + + public SqlIdentifier getTable() { return table; } + + public SqlIdentifier getColumn() { return column; } + + public SqlNode getColumnQualifier() { return columnQualifier; } +} + +// End SqlDescribeTable.java http://git-wip-us.apache.org/repos/asf/calcite/blob/a065200a/core/src/main/java/org/apache/calcite/sql/SqlKind.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlKind.java b/core/src/main/java/org/apache/calcite/sql/SqlKind.java index bb84547..dbd6a47 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlKind.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlKind.java @@ -122,6 +122,11 @@ public enum SqlKind { EXPLAIN, /** + * DESCRIBE statement + */ + DESCRIBE, + + /** * INSERT statement */ INSERT, http://git-wip-us.apache.org/repos/asf/calcite/blob/a065200a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java index 0d7d614..2a5725d 100644 --- a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java +++ b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java @@ -2178,6 +2178,24 @@ public class SqlParserTest { + "(VALUES (ROW(TRUE)))"); } + @Test public void testDescribeSchema() { + check( + "describe schema A", + "DESCRIBE SCHEMA `A`"); + check( + "describe database A", + "DESCRIBE SCHEMA `A`"); + } + + @Test public void testDescribeTable() { + check("describe emps", + "DESCRIBE `EMPS`"); + check("describe emps col1", + "DESCRIBE `EMPS` `COL1`"); + check("describe emps 'col_'", + "DESCRIBE `EMPS` 'col_'"); + } + @Test public void testInsertSelect() { check( "insert into emps select * from emps", http://git-wip-us.apache.org/repos/asf/calcite/blob/a065200a/site/_docs/reference.md ---------------------------------------------------------------------- diff --git a/site/_docs/reference.md b/site/_docs/reference.md index aabc42f..952788d 100644 --- a/site/_docs/reference.md +++ b/site/_docs/reference.md @@ -34,6 +34,7 @@ statement: setStatement | resetStatement | explain + | describe | insert | update | merge @@ -53,6 +54,10 @@ explain: [ EXCLUDING ATTRIBUTES | INCLUDING [ ALL ] ATTRIBUTES ] FOR ( insert | update | merge | delete | query ) +describe: + DESCRIBE (SCHEMA | DATABASE) identifier + | DESCRIBE table (column | columnQualifier) + insert: ( INSERT | UPSERT ) INTO tablePrimary [ '(' column [, column ]* ')' ] @@ -310,6 +315,7 @@ CONTINUE, CURSOR_NAME, **CYCLE**, DATA, +DATABASE, **DATE**, DATETIME_INTERVAL_CODE, DATETIME_INTERVAL_PRECISION,