pan3793 commented on code in PR #50232: URL: https://github.com/apache/spark/pull/50232#discussion_r1988688097
########## sql/hive/src/main/java/org/apache/hadoop/hive/ql/exec/SparkDefaultUDFMethodResolver.java: ########## @@ -0,0 +1,341 @@ +/* + * 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; + +import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils.PrimitiveGrouping; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils; +import org.apache.hadoop.hive.serde2.typeinfo.*; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.spark.internal.SparkLogger; +import org.apache.spark.internal.SparkLoggerFactory; + +/** + * A equivalent implementation of {@link DefaultUDFMethodResolver}, but eliminate calls + * of {@link org.apache.hadoop.hive.ql.exec.FunctionRegistry} to avoid initializing Hive + * built-in UDFs. + */ +public class SparkDefaultUDFMethodResolver implements UDFMethodResolver { + + public static final SparkLogger LOG = + SparkLoggerFactory.getLogger(SparkDefaultUDFMethodResolver.class); + + /** + * The class of the UDF. + */ + private final Class<? extends UDF> udfClass; + + /** + * Constructor. This constructor extract udfClass from {@link DefaultUDFMethodResolver} + */ + @SuppressWarnings("unchecked") + public SparkDefaultUDFMethodResolver( + DefaultUDFMethodResolver wrapped) throws ReflectiveOperationException { + Field udfClassField = wrapped.getClass().getDeclaredField("udfClass"); + udfClassField.setAccessible(true); + this.udfClass = (Class<? extends UDF>) udfClassField.get(wrapped); + } + + /** + * Gets the evaluate method for the UDF given the parameter types. + * + * @param argClasses + * The list of the argument types that need to matched with the + * evaluate function signature. + */ + @Override + public Method getEvalMethod(List<TypeInfo> argClasses) throws UDFArgumentException { + return getMethodInternal(udfClass, "evaluate", false, argClasses); + } + + // Below methods are copied from Hive 2.3.10 o.a.h.hive.ql.exec.FunctionRegistry Review Comment: above is wrapper code, below is copied code. -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org