calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [2/3] calcite git commit: [CALCITE-1168] Add DESCRIBE statement (Arina Ielchiieva)
Date Sat, 30 Apr 2016 01:25:04 GMT
[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 <arina.yelchiyeva@gmail.com>
Authored: Mon Mar 28 19:13:22 2016 +0300
Committer: Julian Hyde <jhyde@apache.org>
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;
+}
+{
+(
+    <DESCRIBE> { pos = getPos(); }
+   (<SCHEMA> | <DATABASE>)
+    {
+        return new SqlDescribeSchema(pos, CompoundIdentifier());
+    }
+)
+    |
+(
+    <DESCRIBE> { 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() :
         | <CONTINUE>
         | <CURSOR_NAME>
         | <DATA>
+        | <DATABASE>
         | <DATETIME_INTERVAL_CODE>
         | <DATETIME_INTERVAL_PRECISION>
         | <DEFAULTS>

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 <code>SqlDescribeSchema</code> 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<SqlNode> 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 <code>SqlDescribeTable</code> 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<SqlNode> 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,


Mime
View raw message