kgyrtkirk commented on a change in pull request #543: HIVE-21292: Break up 
DDLTask 1 - extract Database related operations
URL: https://github.com/apache/hive/pull/543#discussion_r259287150
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/exec/ddl/DDLTask2.java
 ##########
 @@ -0,0 +1,107 @@
+/*
+ * 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.exec.ddl;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.hadoop.hive.ql.CompilationOpContext;
+import org.apache.hadoop.hive.ql.DriverContext;
+import org.apache.hadoop.hive.ql.QueryPlan;
+import org.apache.hadoop.hive.ql.QueryState;
+import org.apache.hadoop.hive.ql.exec.Task;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.parse.ExplainConfiguration.AnalyzeState;
+import org.apache.hadoop.hive.ql.plan.api.StageType;
+
+/**
+ * DDLTask implementation.
+**/
+public class DDLTask2 extends Task<DDLWork2> implements Serializable {
+  private static final long serialVersionUID = 1L;
+
+  private static final Map<Class<? extends DDLDesc>, Class<? extends 
DDLOperation<?>>> DESC_TO_OPARATION =
+      new HashMap<>();
+  public static void registerOperator(Class<? extends DDLDesc> descClass,
+      Class<? extends DDLOperation<?>> operationClass) {
+    DESC_TO_OPARATION.put(descClass, operationClass);
+  }
+
+  @Override
+  public boolean requireLock() {
+    return this.work != null && this.work.getNeedLock();
+  }
+
+  @Override
+  public void initialize(QueryState queryState, QueryPlan queryPlan, 
DriverContext ctx,
+      CompilationOpContext opContext) {
+    super.initialize(queryState, queryPlan, ctx, opContext);
+  }
+
+  @Override
+  public int execute(DriverContext driverContext) {
+    if (driverContext.getCtx().getExplainAnalyze() == AnalyzeState.RUNNING) {
+      return 0;
+    }
+
+    try {
+      Hive db = Hive.get(conf);
+      DDLDesc ddlDesc = work.getDDLDesc();
+
+      if (DESC_TO_OPARATION.containsKey(ddlDesc.getClass())) {
+        DDLOperation<?> ddlOperation = 
DESC_TO_OPARATION.get(ddlDesc.getClass()).newInstance();
+        ddlOperation.init(db, conf, driverContext, ddlDesc);
+        return ddlOperation.execute();
+      } else {
+        throw new IllegalArgumentException("Unknown DDL request: " + 
ddlDesc.getClass());
+      }
+    } catch (Throwable e) {
+      failed(e);
+      return 1;
 
 Review comment:
   all ddl errors are translated to error code 1; I'm not sure if that we want 
that...
   
   * we declare some exception which could haul the errorcode; and then 
unpack/log it here
   * not sure about the contracts this class has - but catching throwable 
includes all kind of crap (like OOM) - are we really want to do that?
   
   

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


With regards,
Apache Git Services

Reply via email to