[ https://issues.apache.org/jira/browse/HIVE-24278?focusedWorklogId=536034&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-536034 ]
ASF GitHub Bot logged work on HIVE-24278: ----------------------------------------- Author: ASF GitHub Bot Created on: 14/Jan/21 15:02 Start Date: 14/Jan/21 15:02 Worklog Time Spent: 10m Work Description: kgyrtkirk commented on a change in pull request #1817: URL: https://github.com/apache/hive/pull/1817#discussion_r557459883 ########## 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: I was thinking to add some notes about it to the `@Description` - I would look there first in an UDF ---------------------------------------------------------------- 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: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 536034) Time Spent: 40m (was: 0.5h) > Implement an UDF for throwing exception in arbitrary vertex > ----------------------------------------------------------- > > Key: HIVE-24278 > URL: https://issues.apache.org/jira/browse/HIVE-24278 > Project: Hive > Issue Type: Improvement > Reporter: László Bodor > Assignee: László Bodor > Priority: Major > Labels: pull-request-available > Time Spent: 40m > Remaining Estimate: 0h > > For testing purposes sometimes we need to make the query fail in a vertex, so > assuming that we already know the plan, it could be something like: > on mapper side > {code} > select a.col1, exception_in_vertex("Map 1") from a > join b on b.id = a.id > {code} > or on reducer side > {code} > select a.col1, exception_in_vertex("Reducer 2") from a > join b on b.id = a.id > {code} > more advanced configuration is possible, e.g we want to make Reducer 2's 50th > task's first (0th) attempt fail with an exception: > {code} > exception_in_vertex("Reducer 2", 50, 0) > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)