You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2020/01/20 15:01:50 UTC

[GitHub] [hive] miklosgergely opened a new pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

miklosgergely opened a new pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882
 
 
   DDLSemanticAnalyzer is a huge class, more than 4000 lines long. The goal is to refactor it in order to have everything cut into more handleable classes under the package  org.apache.hadoop.hive.ql.exec.ddl:
   
   - have a separate class for each analyzers
   - have a package for each operation, containing an analyzer, a description, and an operation, so the amount of classes under a package is more manageable
   
   Step #13: extract the table info and lock related analyzers from DDLSemanticAnalyzer, and move them under the new package.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377863758
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/TableInfoUtils.java
 ##########
 @@ -0,0 +1,53 @@
+/*
+ * 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.hadoop.hive.ql.ddl.table.info;
+
+import java.util.Map;
+
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.ddl.table.partition.PartitionUtils;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+/**
+ * Utilities used by table information DDL commands.
+ */
+public final class TableInfoUtils {
+  private TableInfoUtils() {
+    throw new UnsupportedOperationException("TableInfoUtils should not be instantiated");
+  }
+
+  public static void validateDatabase(Hive db, String databaseName) throws SemanticException {
+    try {
+      if (!db.databaseExists(databaseName)) {
+        throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName));
+      }
+    } catch (HiveException e) {
+      throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName), e);
+    }
+  }
+
+  public static void validateTable(Hive db, Table table, Map<String, String> partSpec) throws SemanticException {
+    if (partSpec != null) {
 
 Review comment:
   Fixed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377819987
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/TableInfoUtils.java
 ##########
 @@ -0,0 +1,53 @@
+/*
+ * 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.hadoop.hive.ql.ddl.table.info;
+
+import java.util.Map;
+
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.ddl.table.partition.PartitionUtils;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+/**
+ * Utilities used by table information DDL commands.
+ */
+public final class TableInfoUtils {
 
 Review comment:
   After some consideration I agree, I'll move these two functions to Hive, and get rid of this class.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377838392
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/TableInfoUtils.java
 ##########
 @@ -0,0 +1,53 @@
+/*
+ * 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.hadoop.hive.ql.ddl.table.info;
+
+import java.util.Map;
+
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.ddl.table.partition.PartitionUtils;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+/**
+ * Utilities used by table information DDL commands.
+ */
+public final class TableInfoUtils {
+  private TableInfoUtils() {
+    throw new UnsupportedOperationException("TableInfoUtils should not be instantiated");
+  }
+
+  public static void validateDatabase(Hive db, String databaseName) throws SemanticException {
+    try {
+      if (!db.databaseExists(databaseName)) {
+        throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName));
+      }
+    } catch (HiveException e) {
+      throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName), e);
+    }
+  }
+
+  public static void validateTable(Hive db, Table table, Map<String, String> partSpec) throws SemanticException {
+    if (partSpec != null) {
 
 Review comment:
   Actually no need to move it to Hive, PartitionUtils can be called directly from wherever it is needed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377864007
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/TableInfoUtils.java
 ##########
 @@ -0,0 +1,53 @@
+/*
+ * 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.hadoop.hive.ql.ddl.table.info;
+
+import java.util.Map;
+
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.ddl.table.partition.PartitionUtils;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+/**
+ * Utilities used by table information DDL commands.
+ */
+public final class TableInfoUtils {
 
 Review comment:
   Fixed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] kgyrtkirk commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377707866
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/DDLUtils.java
 ##########
 @@ -219,4 +220,21 @@ private static String getHS2Host(HiveConf conf) throws SemanticException {
 
     throw new SemanticException("Kill query is only supported in HiveServer2 (not hive cli)");
   }
+
+  /**
+   * Get the fully qualified name in the node.
+   * E.g. the node of the form ^(DOT ^(DOT a b) c) will generate a name of the form "a.b.c".
+   */
+  public static String getFQName(ASTNode node) {
 
 Review comment:
   I don't believe this method will work correctly for quoted cases like:
   ```
   `db`.`table` 
   ```
   right now I don't see the original place where this was...
   ...it work just like before?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377863674
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/desc/DescTableAnalyzer.java
 ##########
 @@ -0,0 +1,210 @@
+/*
+ * 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.hadoop.hive.ql.ddl.table.info.desc;
+
+import java.util.Map;
+
+import org.apache.hadoop.hive.common.TableName;
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.QueryState;
+import org.apache.hadoop.hive.ql.ddl.DDLWork;
+import org.apache.hadoop.hive.ql.ddl.table.info.TableInfoUtils;
+import org.apache.hadoop.hive.ql.ddl.DDLSemanticAnalyzerFactory.DDLType;
+import org.apache.hadoop.hive.ql.ddl.DDLUtils;
+import org.apache.hadoop.hive.ql.exec.Task;
+import org.apache.hadoop.hive.ql.exec.TaskFactory;
+import org.apache.hadoop.hive.ql.hooks.ReadEntity;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.InvalidTableException;
+import org.apache.hadoop.hive.ql.metadata.Partition;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.ASTNode;
+import org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer;
+import org.apache.hadoop.hive.ql.parse.HiveParser;
+import org.apache.hadoop.hive.ql.parse.HiveTableName;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+import org.apache.hadoop.hive.ql.session.SessionState;
+
+/**
+ * Analyzer for table describing commands.
+ *
+ * A query like this will generate a tree as follows
+ *   "describe formatted default.maptable partition (b=100) id;"
+ * TOK_TABTYPE
+ *   TOK_TABNAME --> root for tablename, 2 child nodes mean DB specified
+ *     default
+ *     maptable
+ *   TOK_PARTSPEC  --> root node for partition spec. else columnName
+ *     TOK_PARTVAL
+ *       b
+ *       100
+ *   id           --> root node for columnName
+ * formatted
+ */
+@DDLType(type=HiveParser.TOK_DESCTABLE)
+public class DescTableAnalyzer extends BaseSemanticAnalyzer {
+  public DescTableAnalyzer(QueryState queryState) throws SemanticException {
+    super(queryState);
+  }
+
+  @Override
+  public void analyzeInternal(ASTNode root) throws SemanticException {
+    ctx.setResFile(ctx.getLocalTmpPath());
+
+    ASTNode tableTypeExpr = (ASTNode) root.getChild(0);
+
+    TableName tableName = getTableName(tableTypeExpr);
+    Table table = getTable(tableName);
+
+    // process the second child,if exists, node to get partition spec(s)
+    Map<String, String> partitionSpec = getPartitionSpec(db, tableTypeExpr, tableName);
+    TableInfoUtils.validateTable(db, table, partitionSpec);
+
+    // process the third child node,if exists, to get partition spec(s)
+    String columnPath = getColumnPath(db, tableTypeExpr, tableName, partitionSpec);
+
+    boolean showColStats = false;
+    boolean isFormatted = false;
+    boolean isExt = false;
+    if (root.getChildCount() == 2) {
+      int descOptions = root.getChild(1).getType();
+      isFormatted = descOptions == HiveParser.KW_FORMATTED;
+      isExt = descOptions == HiveParser.KW_EXTENDED;
+      // in case of "DESCRIBE FORMATTED tablename column_name" statement, colPath will contain tablename.column_name.
+      // If column_name is not specified colPath will be equal to tableName.
+      // This is how we can differentiate if we are describing a table or column.
+      if (columnPath != null && isFormatted) {
+        showColStats = true;
+      }
+    }
+
+    inputs.add(new ReadEntity(table));
+
+    DescTableDesc desc = new DescTableDesc(ctx.getResFile(), tableName, partitionSpec, columnPath, isExt, isFormatted);
+    Task<?> task = TaskFactory.get(new DDLWork(getInputs(), getOutputs(), desc));
+    rootTasks.add(task);
+
+    task.setFetchSource(true);
+    String schema = showColStats ? DescTableDesc.COLUMN_STATISTICS_SCHEMA : DescTableDesc.SCHEMA;
+    setFetchTask(createFetchTask(schema));
+  }
+
+  /** Process the first node to extract tablename, it is either TABLENAME or DBNAME.TABLENAME if db is given. */
+  private TableName getTableName(ASTNode tableTypeExpr) throws SemanticException {
 
 Review comment:
   Fixed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] kgyrtkirk commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377701883
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/show/status/package-info.java
 ##########
 @@ -0,0 +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.
+ */
+
+/** Show table status DDL operation. */
 
 Review comment:
   I don't see any use in these package-info files...they don't add any usefull content...
   I think they could be removed...

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377820258
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/desc/DescTableAnalyzer.java
 ##########
 @@ -0,0 +1,210 @@
+/*
+ * 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.hadoop.hive.ql.ddl.table.info.desc;
+
+import java.util.Map;
+
+import org.apache.hadoop.hive.common.TableName;
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.QueryState;
+import org.apache.hadoop.hive.ql.ddl.DDLWork;
+import org.apache.hadoop.hive.ql.ddl.table.info.TableInfoUtils;
+import org.apache.hadoop.hive.ql.ddl.DDLSemanticAnalyzerFactory.DDLType;
+import org.apache.hadoop.hive.ql.ddl.DDLUtils;
+import org.apache.hadoop.hive.ql.exec.Task;
+import org.apache.hadoop.hive.ql.exec.TaskFactory;
+import org.apache.hadoop.hive.ql.hooks.ReadEntity;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.InvalidTableException;
+import org.apache.hadoop.hive.ql.metadata.Partition;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.ASTNode;
+import org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer;
+import org.apache.hadoop.hive.ql.parse.HiveParser;
+import org.apache.hadoop.hive.ql.parse.HiveTableName;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+import org.apache.hadoop.hive.ql.session.SessionState;
+
+/**
+ * Analyzer for table describing commands.
+ *
+ * A query like this will generate a tree as follows
+ *   "describe formatted default.maptable partition (b=100) id;"
+ * TOK_TABTYPE
+ *   TOK_TABNAME --> root for tablename, 2 child nodes mean DB specified
+ *     default
+ *     maptable
+ *   TOK_PARTSPEC  --> root node for partition spec. else columnName
+ *     TOK_PARTVAL
+ *       b
+ *       100
+ *   id           --> root node for columnName
+ * formatted
+ */
+@DDLType(type=HiveParser.TOK_DESCTABLE)
+public class DescTableAnalyzer extends BaseSemanticAnalyzer {
+  public DescTableAnalyzer(QueryState queryState) throws SemanticException {
+    super(queryState);
+  }
+
+  @Override
+  public void analyzeInternal(ASTNode root) throws SemanticException {
+    ctx.setResFile(ctx.getLocalTmpPath());
+
+    ASTNode tableTypeExpr = (ASTNode) root.getChild(0);
+
+    TableName tableName = getTableName(tableTypeExpr);
+    Table table = getTable(tableName);
+
+    // process the second child,if exists, node to get partition spec(s)
+    Map<String, String> partitionSpec = getPartitionSpec(db, tableTypeExpr, tableName);
+    TableInfoUtils.validateTable(db, table, partitionSpec);
+
+    // process the third child node,if exists, to get partition spec(s)
+    String columnPath = getColumnPath(db, tableTypeExpr, tableName, partitionSpec);
+
+    boolean showColStats = false;
+    boolean isFormatted = false;
+    boolean isExt = false;
+    if (root.getChildCount() == 2) {
+      int descOptions = root.getChild(1).getType();
+      isFormatted = descOptions == HiveParser.KW_FORMATTED;
+      isExt = descOptions == HiveParser.KW_EXTENDED;
+      // in case of "DESCRIBE FORMATTED tablename column_name" statement, colPath will contain tablename.column_name.
+      // If column_name is not specified colPath will be equal to tableName.
+      // This is how we can differentiate if we are describing a table or column.
+      if (columnPath != null && isFormatted) {
+        showColStats = true;
+      }
+    }
+
+    inputs.add(new ReadEntity(table));
+
+    DescTableDesc desc = new DescTableDesc(ctx.getResFile(), tableName, partitionSpec, columnPath, isExt, isFormatted);
+    Task<?> task = TaskFactory.get(new DDLWork(getInputs(), getOutputs(), desc));
+    rootTasks.add(task);
+
+    task.setFetchSource(true);
+    String schema = showColStats ? DescTableDesc.COLUMN_STATISTICS_SCHEMA : DescTableDesc.SCHEMA;
+    setFetchTask(createFetchTask(schema));
+  }
+
+  /** Process the first node to extract tablename, it is either TABLENAME or DBNAME.TABLENAME if db is given. */
+  private TableName getTableName(ASTNode tableTypeExpr) throws SemanticException {
 
 Review comment:
   I agree, will use that one instead.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377820073
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/TableInfoUtils.java
 ##########
 @@ -0,0 +1,53 @@
+/*
+ * 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.hadoop.hive.ql.ddl.table.info;
+
+import java.util.Map;
+
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.ddl.table.partition.PartitionUtils;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+/**
+ * Utilities used by table information DDL commands.
+ */
+public final class TableInfoUtils {
+  private TableInfoUtils() {
+    throw new UnsupportedOperationException("TableInfoUtils should not be instantiated");
+  }
+
+  public static void validateDatabase(Hive db, String databaseName) throws SemanticException {
 
 Review comment:
   It will be moved to Hive.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] kgyrtkirk commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377724650
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/TableInfoUtils.java
 ##########
 @@ -0,0 +1,53 @@
+/*
+ * 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.hadoop.hive.ql.ddl.table.info;
+
+import java.util.Map;
+
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.ddl.table.partition.PartitionUtils;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+/**
+ * Utilities used by table information DDL commands.
+ */
+public final class TableInfoUtils {
+  private TableInfoUtils() {
+    throw new UnsupportedOperationException("TableInfoUtils should not be instantiated");
+  }
+
+  public static void validateDatabase(Hive db, String databaseName) throws SemanticException {
 
 Review comment:
   the methods in this class should be in the "Hive" class; because the first argument of the methods are an instance of Hive

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] miklosgergely closed pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
miklosgergely closed pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377807346
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/show/status/package-info.java
 ##########
 @@ -0,0 +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.
+ */
+
+/** Show table status DDL operation. */
 
 Review comment:
   I agree, but the our checkstyle.xml tells us to put them there. I'll create a jira, and if we can agree to remove it from checkstyle.xml, then I'll remove all the package-info.java files from ddl.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377816730
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/TableInfoUtils.java
 ##########
 @@ -0,0 +1,53 @@
+/*
+ * 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.hadoop.hive.ql.ddl.table.info;
+
+import java.util.Map;
+
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.ddl.table.partition.PartitionUtils;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+/**
+ * Utilities used by table information DDL commands.
+ */
+public final class TableInfoUtils {
+  private TableInfoUtils() {
+    throw new UnsupportedOperationException("TableInfoUtils should not be instantiated");
+  }
+
+  public static void validateDatabase(Hive db, String databaseName) throws SemanticException {
+    try {
+      if (!db.databaseExists(databaseName)) {
+        throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName));
+      }
+    } catch (HiveException e) {
+      throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName), e);
+    }
+  }
+
+  public static void validateTable(Hive db, Table table, Map<String, String> partSpec) throws SemanticException {
+    if (partSpec != null) {
 
 Review comment:
   It validates that the partition exists, if there is a partition specified. It throws a SemanticException if the partition doesn't exist.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377863861
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/TableInfoUtils.java
 ##########
 @@ -0,0 +1,53 @@
+/*
+ * 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.hadoop.hive.ql.ddl.table.info;
+
+import java.util.Map;
+
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.ddl.table.partition.PartitionUtils;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+/**
+ * Utilities used by table information DDL commands.
+ */
+public final class TableInfoUtils {
+  private TableInfoUtils() {
+    throw new UnsupportedOperationException("TableInfoUtils should not be instantiated");
+  }
+
+  public static void validateDatabase(Hive db, String databaseName) throws SemanticException {
 
 Review comment:
   Fixed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] kgyrtkirk commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377723963
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/TableInfoUtils.java
 ##########
 @@ -0,0 +1,53 @@
+/*
+ * 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.hadoop.hive.ql.ddl.table.info;
+
+import java.util.Map;
+
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.ddl.table.partition.PartitionUtils;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+/**
+ * Utilities used by table information DDL commands.
+ */
+public final class TableInfoUtils {
+  private TableInfoUtils() {
+    throw new UnsupportedOperationException("TableInfoUtils should not be instantiated");
+  }
+
+  public static void validateDatabase(Hive db, String databaseName) throws SemanticException {
+    try {
+      if (!db.databaseExists(databaseName)) {
+        throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName));
+      }
+    } catch (HiveException e) {
+      throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName), e);
+    }
+  }
+
+  public static void validateTable(Hive db, Table table, Map<String, String> partSpec) throws SemanticException {
+    if (partSpec != null) {
 
 Review comment:
   what does this method validate? it only adds a nullcheck...I mean it doesn't even throw an exception ; I would expect that...from the word "validate"

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377810208
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/DDLUtils.java
 ##########
 @@ -219,4 +220,21 @@ private static String getHS2Host(HiveConf conf) throws SemanticException {
 
     throw new SemanticException("Kill query is only supported in HiveServer2 (not hive cli)");
   }
+
+  /**
+   * Get the fully qualified name in the node.
+   * E.g. the node of the form ^(DOT ^(DOT a b) c) will generate a name of the form "a.b.c".
+   */
+  public static String getFQName(ASTNode node) {
 
 Review comment:
   The original code for this was not removed yet, as it is still used by some other analyzers which are still in DDLSemanticAnalyzer, see the static class QualifiedNameUtil.  I don't see why wouldn't it work in quoted case, I guess the quotes are removed before building the ASTTree, isn't that the case?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] kgyrtkirk commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377719965
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/desc/DescTableAnalyzer.java
 ##########
 @@ -0,0 +1,210 @@
+/*
+ * 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.hadoop.hive.ql.ddl.table.info.desc;
+
+import java.util.Map;
+
+import org.apache.hadoop.hive.common.TableName;
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.QueryState;
+import org.apache.hadoop.hive.ql.ddl.DDLWork;
+import org.apache.hadoop.hive.ql.ddl.table.info.TableInfoUtils;
+import org.apache.hadoop.hive.ql.ddl.DDLSemanticAnalyzerFactory.DDLType;
+import org.apache.hadoop.hive.ql.ddl.DDLUtils;
+import org.apache.hadoop.hive.ql.exec.Task;
+import org.apache.hadoop.hive.ql.exec.TaskFactory;
+import org.apache.hadoop.hive.ql.hooks.ReadEntity;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.InvalidTableException;
+import org.apache.hadoop.hive.ql.metadata.Partition;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.ASTNode;
+import org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer;
+import org.apache.hadoop.hive.ql.parse.HiveParser;
+import org.apache.hadoop.hive.ql.parse.HiveTableName;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+import org.apache.hadoop.hive.ql.session.SessionState;
+
+/**
+ * Analyzer for table describing commands.
+ *
+ * A query like this will generate a tree as follows
+ *   "describe formatted default.maptable partition (b=100) id;"
+ * TOK_TABTYPE
+ *   TOK_TABNAME --> root for tablename, 2 child nodes mean DB specified
+ *     default
+ *     maptable
+ *   TOK_PARTSPEC  --> root node for partition spec. else columnName
+ *     TOK_PARTVAL
+ *       b
+ *       100
+ *   id           --> root node for columnName
+ * formatted
+ */
+@DDLType(type=HiveParser.TOK_DESCTABLE)
+public class DescTableAnalyzer extends BaseSemanticAnalyzer {
+  public DescTableAnalyzer(QueryState queryState) throws SemanticException {
+    super(queryState);
+  }
+
+  @Override
+  public void analyzeInternal(ASTNode root) throws SemanticException {
+    ctx.setResFile(ctx.getLocalTmpPath());
+
+    ASTNode tableTypeExpr = (ASTNode) root.getChild(0);
+
+    TableName tableName = getTableName(tableTypeExpr);
+    Table table = getTable(tableName);
+
+    // process the second child,if exists, node to get partition spec(s)
+    Map<String, String> partitionSpec = getPartitionSpec(db, tableTypeExpr, tableName);
+    TableInfoUtils.validateTable(db, table, partitionSpec);
+
+    // process the third child node,if exists, to get partition spec(s)
+    String columnPath = getColumnPath(db, tableTypeExpr, tableName, partitionSpec);
+
+    boolean showColStats = false;
+    boolean isFormatted = false;
+    boolean isExt = false;
+    if (root.getChildCount() == 2) {
+      int descOptions = root.getChild(1).getType();
+      isFormatted = descOptions == HiveParser.KW_FORMATTED;
+      isExt = descOptions == HiveParser.KW_EXTENDED;
+      // in case of "DESCRIBE FORMATTED tablename column_name" statement, colPath will contain tablename.column_name.
+      // If column_name is not specified colPath will be equal to tableName.
+      // This is how we can differentiate if we are describing a table or column.
+      if (columnPath != null && isFormatted) {
+        showColStats = true;
+      }
+    }
+
+    inputs.add(new ReadEntity(table));
+
+    DescTableDesc desc = new DescTableDesc(ctx.getResFile(), tableName, partitionSpec, columnPath, isExt, isFormatted);
+    Task<?> task = TaskFactory.get(new DDLWork(getInputs(), getOutputs(), desc));
+    rootTasks.add(task);
+
+    task.setFetchSource(true);
+    String schema = showColStats ? DescTableDesc.COLUMN_STATISTICS_SCHEMA : DescTableDesc.SCHEMA;
+    setFetchTask(createFetchTask(schema));
+  }
+
+  /** Process the first node to extract tablename, it is either TABLENAME or DBNAME.TABLENAME if db is given. */
+  private TableName getTableName(ASTNode tableTypeExpr) throws SemanticException {
 
 Review comment:
   seeing a private method like in a desc table related class is odd.
   parsing a `TOK_TABNAME` seems like a common thing to me....
   there is also `BSA.getQualifiedTableName` with similar goals
   
   we shouldn't have this logic duplicated a lot...could you open a ticket to address that?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
miklosgergely commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377820124
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/TableInfoUtils.java
 ##########
 @@ -0,0 +1,53 @@
+/*
+ * 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.hadoop.hive.ql.ddl.table.info;
+
+import java.util.Map;
+
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.ddl.table.partition.PartitionUtils;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+/**
+ * Utilities used by table information DDL commands.
+ */
+public final class TableInfoUtils {
+  private TableInfoUtils() {
+    throw new UnsupportedOperationException("TableInfoUtils should not be instantiated");
+  }
+
+  public static void validateDatabase(Hive db, String databaseName) throws SemanticException {
+    try {
+      if (!db.databaseExists(databaseName)) {
+        throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName));
+      }
+    } catch (HiveException e) {
+      throw new SemanticException(ErrorMsg.DATABASE_NOT_EXISTS.getMsg(databaseName), e);
+    }
+  }
+
+  public static void validateTable(Hive db, Table table, Map<String, String> partSpec) throws SemanticException {
+    if (partSpec != null) {
 
 Review comment:
   It will be moved to Hive.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


[GitHub] [hive] kgyrtkirk commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers

Posted by GitBox <gi...@apache.org>.
kgyrtkirk commented on a change in pull request #882: HIVE-22747 Break up DDLSemanticAnalyzer - extract Table info and lock analyzers
URL: https://github.com/apache/hive/pull/882#discussion_r377722966
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/TableInfoUtils.java
 ##########
 @@ -0,0 +1,53 @@
+/*
+ * 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.hadoop.hive.ql.ddl.table.info;
+
+import java.util.Map;
+
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.ddl.table.partition.PartitionUtils;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+/**
+ * Utilities used by table information DDL commands.
+ */
+public final class TableInfoUtils {
 
 Review comment:
   classes like this are not the best...isn't there a way to push these methods into either some existing place...place it somewhere in the object hierarchy somehow

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org