kasakrisz commented on code in PR #5973:
URL: https://github.com/apache/hive/pull/5973#discussion_r2236314380


##########
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/create/CreateTableAnalyzer.java:
##########
@@ -0,0 +1,829 @@
+/*
+ * 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.create;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.common.TableName;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.metastore.TransactionalValidationListener;
+import org.apache.hadoop.hive.metastore.Warehouse;
+import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.Order;
+import org.apache.hadoop.hive.metastore.api.SQLCheckConstraint;
+import org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint;
+import org.apache.hadoop.hive.metastore.api.SQLForeignKey;
+import org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint;
+import org.apache.hadoop.hive.metastore.api.SQLPrimaryKey;
+import org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint;
+import org.apache.hadoop.hive.metastore.api.hive_metastoreConstants;
+import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.QueryState;
+import org.apache.hadoop.hive.ql.ddl.DDLSemanticAnalyzerFactory.DDLType;
+import org.apache.hadoop.hive.ql.ddl.DDLWork;
+import org.apache.hadoop.hive.ql.ddl.misc.sortoder.SortFieldDesc;
+import org.apache.hadoop.hive.ql.ddl.misc.sortoder.SortFields;
+import org.apache.hadoop.hive.ql.ddl.table.constraint.ConstraintsUtils;
+import org.apache.hadoop.hive.ql.ddl.table.convert.AlterTableConvertOperation;
+import org.apache.hadoop.hive.ql.ddl.table.create.like.CreateTableLikeDesc;
+import org.apache.hadoop.hive.ql.ddl.table.storage.skewed.SkewedTableUtils;
+import org.apache.hadoop.hive.ql.exec.TaskFactory;
+import org.apache.hadoop.hive.ql.io.SchemaInferenceUtils;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.HiveStorageHandler;
+import org.apache.hadoop.hive.ql.metadata.HiveUtils;
+import org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.ASTNode;
+import org.apache.hadoop.hive.ql.parse.CalcitePlanner;
+import org.apache.hadoop.hive.ql.parse.EximUtil;
+import org.apache.hadoop.hive.ql.parse.HiveParser;
+import org.apache.hadoop.hive.ql.parse.PartitionTransform;
+import org.apache.hadoop.hive.ql.parse.QB;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+import org.apache.hadoop.hive.ql.parse.StorageFormat;
+import org.apache.hadoop.hive.ql.parse.TableMask;
+import org.apache.hadoop.hive.ql.plan.HiveOperation;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hadoop.hive.ql.session.SessionStateUtil;
+import org.apache.hadoop.hive.ql.util.NullOrdering;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.google.common.base.Strings;
+
+import static 
org.apache.hadoop.hive.conf.HiveConf.ConfVars.HIVE_DEFAULT_STORAGE_HANDLER;
+import static 
org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.DEFAULT_TABLE_TYPE;
+import static 
org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_LOCATION;
+import static 
org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_STORAGE;
+import static 
org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.TABLE_IS_CTAS;
+
+@DDLType(types = HiveParser.TOK_CREATETABLE)
+public class CreateTableAnalyzer extends CalcitePlanner {
+
+  public CreateTableAnalyzer(QueryState queryState)
+      throws SemanticException {
+    super(queryState);
+  }
+
+  private static final String[] UPDATED_TBL_PROPS =
+      {hive_metastoreConstants.TABLE_IS_TRANSACTIONAL, 
hive_metastoreConstants.TABLE_TRANSACTIONAL_PROPERTIES, 
hive_metastoreConstants.TABLE_BUCKETING_VERSION};
+
+  @Override
+  protected ASTNode handlePostCboRewriteContext(PreCboCtx cboCtx, ASTNode 
newAST)
+      throws SemanticException {
+    if (cboCtx.getType() == PreCboCtx.Type.CTAS) {
+      // CTAS
+      init(false);
+      setAST(newAST);
+      newAST = reAnalyzeCTASAfterCbo(newAST);
+    } else {
+      // All others
+      init(false);
+    }
+    return newAST;
+  }
+
+  public ASTNode reAnalyzeCTASAfterCbo(ASTNode newAst)
+      throws SemanticException {
+    // analyzeCreateTable uses this.ast, but doPhase1 doesn't, so only reset it
+    // here.
+    newAst = analyzeCreateTable(newAst, getQB(), null);
+    if (newAst == null) {
+      LOG.error("analyzeCreateTable failed to initialize CTAS after CBO;" + " 
new ast is " + getAST().dump());
+      throw new SemanticException("analyzeCreateTable failed to initialize 
CTAS after CBO");
+    }
+    return newAst;
+  }
+
+  @Override
+  protected boolean genResolvedParseTree(ASTNode ast, PlannerContext 
plannerCtx)
+      throws SemanticException {
+    ASTNode child;
+    this.ast = ast;
+    viewsExpanded = new ArrayList<String>();
+    if ((child = analyzeCreateTable(ast, getQB(), plannerCtx)) == null) {
+      return false;
+    }
+    tableMask = new TableMask(this, conf, ctx.isSkipTableMasking());
+    gatherUserSuppliedFunctions(child);
+    Phase1Ctx ctx_1 = initPhase1Ctx();
+    if (!doPhase1(child, getQB(), ctx_1, plannerCtx)) {
+      return false;
+    }
+    LOG.info("Completed phase 1 of Semantic Analysis");
+    getMetaData(getQB(), true);
+    LOG.info("Completed getting MetaData in Semantic Analysis");

Review Comment:
   This part was copied from SemanticAnalyzer and now 2 copies exists. Could 
you please extract it to a method.



##########
ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java:
##########
@@ -233,15 +233,39 @@ public boolean isPrepareQuery() {
     return prepareQuery;
   }
 
-  static final class RowFormatParams {
+  public static final class RowFormatParams {
     String fieldDelim = null;
     String fieldEscape = null;
     String collItemDelim = null;
     String mapKeyDelim = null;
     String lineDelim = null;
     String nullFormat = null;

Review Comment:
   Can these be private?
   Maybe final too if the parse logic is extracted to a factory method
   ```
   public static final class RowFormatParams {
       
     public static RowFormatParams analyzeRowFormat(ASTNode child) {
       String fieldDelim = null;
       case HiveParser.TOK_TABLEROWFORMATFIELD:
               fieldDelim = unescapeSQLString(rowChild.getChild(0)
       ...
       return new RowFormatParams(fieldDelim ...)
     }
   
     private final String fieldDelim; 
     ...
     private RowFormatParams(String fieldDelim, ...) {
       this.fieldDelim = fieldDelim;
       ...
     }
   
     public String getFieldDelim() {
         return fieldDelim;
     }
   }
   ```
   
   I don't have a string opinion but since you have added getters to this class 
which i think is a good refactor we can go further and make it immutable.



##########
ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java:
##########
@@ -479,15 +460,13 @@ public class SemanticAnalyzer extends 
BaseSemanticAnalyzer {
   private static final CommonToken DOT_TOKEN =
       new ImmutableCommonToken(HiveParser.DOT, ".");
 
-  private static final String[] UPDATED_TBL_PROPS = {
-      hive_metastoreConstants.TABLE_IS_TRANSACTIONAL,
-      hive_metastoreConstants.TABLE_TRANSACTIONAL_PROPERTIES,
-      hive_metastoreConstants.TABLE_BUCKETING_VERSION
-  };
-
   private int subQueryExpressionAliasCounter = 0;
   private static final ObjectMapper JSON_OBJECT_MAPPER = new ObjectMapper();
-  static class Phase1Ctx {
+
+  protected static ObjectMapper getJsonObjectMapper(){
+    return JSON_OBJECT_MAPPER;
+  }

Review Comment:
   This might be unnecessary because JSON_OBJECT_MAPPER acts as a constant just 
make it protected.



##########
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/create/CreateTableAnalyzer.java:
##########
@@ -0,0 +1,829 @@
+/*
+ * 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.create;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.common.TableName;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.metastore.TransactionalValidationListener;
+import org.apache.hadoop.hive.metastore.Warehouse;
+import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.Order;
+import org.apache.hadoop.hive.metastore.api.SQLCheckConstraint;
+import org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint;
+import org.apache.hadoop.hive.metastore.api.SQLForeignKey;
+import org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint;
+import org.apache.hadoop.hive.metastore.api.SQLPrimaryKey;
+import org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint;
+import org.apache.hadoop.hive.metastore.api.hive_metastoreConstants;
+import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.QueryState;
+import org.apache.hadoop.hive.ql.ddl.DDLSemanticAnalyzerFactory.DDLType;
+import org.apache.hadoop.hive.ql.ddl.DDLWork;
+import org.apache.hadoop.hive.ql.ddl.misc.sortoder.SortFieldDesc;
+import org.apache.hadoop.hive.ql.ddl.misc.sortoder.SortFields;
+import org.apache.hadoop.hive.ql.ddl.table.constraint.ConstraintsUtils;
+import org.apache.hadoop.hive.ql.ddl.table.convert.AlterTableConvertOperation;
+import org.apache.hadoop.hive.ql.ddl.table.create.like.CreateTableLikeDesc;
+import org.apache.hadoop.hive.ql.ddl.table.storage.skewed.SkewedTableUtils;
+import org.apache.hadoop.hive.ql.exec.TaskFactory;
+import org.apache.hadoop.hive.ql.io.SchemaInferenceUtils;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.HiveStorageHandler;
+import org.apache.hadoop.hive.ql.metadata.HiveUtils;
+import org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.ASTNode;
+import org.apache.hadoop.hive.ql.parse.CalcitePlanner;
+import org.apache.hadoop.hive.ql.parse.EximUtil;
+import org.apache.hadoop.hive.ql.parse.HiveParser;
+import org.apache.hadoop.hive.ql.parse.PartitionTransform;
+import org.apache.hadoop.hive.ql.parse.QB;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+import org.apache.hadoop.hive.ql.parse.StorageFormat;
+import org.apache.hadoop.hive.ql.parse.TableMask;
+import org.apache.hadoop.hive.ql.plan.HiveOperation;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hadoop.hive.ql.session.SessionStateUtil;
+import org.apache.hadoop.hive.ql.util.NullOrdering;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.google.common.base.Strings;
+
+import static 
org.apache.hadoop.hive.conf.HiveConf.ConfVars.HIVE_DEFAULT_STORAGE_HANDLER;
+import static 
org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.DEFAULT_TABLE_TYPE;
+import static 
org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_LOCATION;
+import static 
org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_STORAGE;
+import static 
org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.TABLE_IS_CTAS;
+
+@DDLType(types = HiveParser.TOK_CREATETABLE)
+public class CreateTableAnalyzer extends CalcitePlanner {
+
+  public CreateTableAnalyzer(QueryState queryState)
+      throws SemanticException {
+    super(queryState);
+  }
+
+  private static final String[] UPDATED_TBL_PROPS =
+      {hive_metastoreConstants.TABLE_IS_TRANSACTIONAL, 
hive_metastoreConstants.TABLE_TRANSACTIONAL_PROPERTIES, 
hive_metastoreConstants.TABLE_BUCKETING_VERSION};
+
+  @Override
+  protected ASTNode handlePostCboRewriteContext(PreCboCtx cboCtx, ASTNode 
newAST)
+      throws SemanticException {
+    if (cboCtx.getType() == PreCboCtx.Type.CTAS) {
+      // CTAS
+      init(false);
+      setAST(newAST);
+      newAST = reAnalyzeCTASAfterCbo(newAST);
+    } else {
+      // All others
+      init(false);

Review Comment:
   If the "All others" branch needs to be improved in the future it must be 
done in two places in the code.
   How about calling `super.handlePostCboRewriteContext`? 



-- 
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.

To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to