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 2021/02/19 13:53:18 UTC

[GitHub] [hive] kgyrtkirk commented on a change in pull request #1929: HIVE-24704: Ensure that all Operator column expressions refer to a column in the RowSchema

kgyrtkirk commented on a change in pull request #1929:
URL: https://github.com/apache/hive/pull/1929#discussion_r579200496



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/hooks/OperatorHealthCheckerHook.java
##########
@@ -0,0 +1,211 @@
+/*
+ * 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.hooks;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.Stack;
+
+import com.google.common.collect.Lists;
+
+import com.google.common.collect.Sets;
+import org.apache.hadoop.hive.ql.exec.ColumnInfo;
+import org.apache.hadoop.hive.ql.exec.Operator;
+import org.apache.hadoop.hive.ql.exec.ReduceSinkOperator;
+import org.apache.hadoop.hive.ql.exec.RowSchema;
+import org.apache.hadoop.hive.ql.exec.ScriptOperator;
+import org.apache.hadoop.hive.ql.exec.SelectOperator;
+import org.apache.hadoop.hive.ql.exec.TableScanOperator;
+import org.apache.hadoop.hive.ql.exec.Task;
+import org.apache.hadoop.hive.ql.lib.DefaultGraphWalker;
+import org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher;
+import org.apache.hadoop.hive.ql.lib.SemanticDispatcher;
+import org.apache.hadoop.hive.ql.lib.SemanticGraphWalker;
+import org.apache.hadoop.hive.ql.lib.Node;
+import org.apache.hadoop.hive.ql.lib.SemanticNodeProcessor;
+import org.apache.hadoop.hive.ql.lib.NodeProcessorCtx;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+import org.apache.hadoop.hive.ql.plan.BaseWork;
+import org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
+import org.apache.hadoop.hive.ql.plan.GroupByDesc;
+import org.apache.hadoop.hive.ql.plan.MapWork;
+import org.apache.hadoop.hive.ql.plan.MapredWork;
+import org.apache.hadoop.hive.ql.plan.OperatorDesc;
+import org.apache.hadoop.hive.ql.plan.ReduceWork;
+import org.apache.hadoop.hive.ql.plan.SelectDesc;
+import org.apache.hadoop.hive.ql.plan.TezWork;
+
+/**
+ * Checks some operator quality rules.
+ *
+ * Checks whenever operator ids are not reused.
+ * Checks some level of expression/schema consistency
+ * Some sanity checks on SelectOperators
+ */
+public class OperatorHealthCheckerHook implements ExecuteWithHookContext {
+
+  static class UniqueOpIdChecker implements SemanticNodeProcessor {
+
+    Map<String, Operator<?>> opMap = new HashMap<>();
+
+    @Override
+    public Object process(Node nd, Stack<Node> stack, NodeProcessorCtx procCtx, Object... nodeOutputs)
+        throws SemanticException {
+
+      Operator<?> op = (Operator<?>) nd;
+      checkOperator(op);
+      String opKey = op.getOperatorId();
+      Operator<?> found = opMap.get(opKey);
+      if (found != null) {
+        throw new RuntimeException("operator id reuse found: " + opKey);
+      }
+      opMap.put(opKey, op);
+      return null;
+    }
+  }
+
+  public static void checkOperator(Operator<?> op) {
+    OperatorDesc conf = op.getConf();
+    Map<String, ExprNodeDesc> exprMap = conf.getColumnExprMap();
+    RowSchema schema = op.getSchema();
+
+    chceckSchema(schema);
+    if (op instanceof SelectOperator) {
+      checkSelectOperator((SelectOperator) op);
+    }
+    if (schema != null && exprMap != null) {
+      for (Entry<String, ExprNodeDesc> c : exprMap.entrySet()) {
+        if (c.getValue() instanceof ExprNodeConstantDesc) {
+          continue;
+        }
+        ColumnInfo ci = schema.getColumnInfo(c.getKey());
+        if (c.getKey().startsWith("KEY.reducesinkkey")) {

Review comment:
       actually - this if is still here because in case of MJ the RS rowschema is so bad that I kinda give up fixing it ; it needs to be taken care of separately...




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



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