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/01/14 14:58:31 UTC

[GitHub] [hive] abstractdog commented on a change in pull request #1817: HIVE-24278: Implement an UDF for throwing exception in arbitrary vertex

abstractdog commented on a change in pull request #1817:
URL: https://github.com/apache/hive/pull/1817#discussion_r557456537



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFExceptionInVertex.java
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.udf.generic;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.MapredContext;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.ql.exec.tez.TezProcessor;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantStringObjectInspector;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class implements the UDF which can throw an exception in arbitrary vertex (typically mapper)
+ * / task / task attempt. For throwing exception in reducer side, where most probably
+ * GroupByOperator codepath applies, GenericUDAFExceptionInVertex is used.
+ */
+@Description(name = "exception_in_vertex_udf", value = "_FUNC_(vertexName, taskNumberExpression, taskAttemptNumberExpression)")
+public class GenericUDFExceptionInVertex extends GenericUDF {
+  private static final Logger LOG = LoggerFactory.getLogger(GenericUDFExceptionInVertex.class);
+
+  private String vertexName;
+  private String taskNumberExpr;
+  private String taskAttemptNumberExpr;
+  private String currentVertexName;
+  private int currentTaskNumber;
+  private int currentTaskAttemptNumber;
+  private boolean alreadyCheckedAndPassed;
+
+  @Override
+  public ObjectInspector initialize(ObjectInspector[] parameters) throws UDFArgumentException {
+    if (parameters.length < 2) {
+      throw new UDFArgumentTypeException(-1,
+          "At least two argument is expected (fake column ref, vertex name)");
+    }
+
+    this.vertexName = getVertexName(parameters, 1);
+    this.taskNumberExpr = getTaskNumber(parameters, 2);
+    this.taskAttemptNumberExpr = getTaskAttemptNumber(parameters, 3);

Review comment:
       thanks for taking a look @kgyrtkirk! there are examples in exception_in_vertex_udf.q, do you think it's enough to mention it here?




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