Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id F3DC0200B3E for ; Wed, 7 Sep 2016 20:04:21 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id F25EF160AC1; Wed, 7 Sep 2016 18:04:21 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 45D5B160ABF for ; Wed, 7 Sep 2016 20:04:21 +0200 (CEST) Received: (qmail 28029 invoked by uid 500); 7 Sep 2016 18:04:20 -0000 Mailing-List: contact dev-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@drill.apache.org Delivered-To: mailing list dev@drill.apache.org Received: (qmail 27999 invoked by uid 99); 7 Sep 2016 18:04:20 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Sep 2016 18:04:20 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CAF56E009E; Wed, 7 Sep 2016 18:04:19 +0000 (UTC) From: paul-rogers To: dev@drill.apache.org Reply-To: dev@drill.apache.org References: In-Reply-To: Subject: [GitHub] drill pull request #574: DRILL-4726: Dynamic UDFs support Content-Type: text/plain Message-Id: <20160907180419.CAF56E009E@git1-us-west.apache.org> Date: Wed, 7 Sep 2016 18:04:19 +0000 (UTC) archived-at: Wed, 07 Sep 2016 18:04:22 -0000 Github user paul-rogers commented on a diff in the pull request: https://github.com/apache/drill/pull/574#discussion_r77874361 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/CreateFunctionHandler.java --- @@ -0,0 +1,195 @@ +/** + * 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.drill.exec.planner.sql.handlers; + +import com.google.common.collect.Lists; +import com.google.common.io.Files; +import org.apache.calcite.sql.SqlCharStringLiteral; +import org.apache.calcite.sql.SqlNode; +import org.apache.commons.io.FileUtils; +import org.apache.drill.common.exceptions.DrillRuntimeException; +import org.apache.drill.common.exceptions.UserException; +import org.apache.drill.exec.ExecConstants; +import org.apache.drill.exec.exception.FunctionValidationException; +import org.apache.drill.exec.exception.VersionMismatchException; +import org.apache.drill.exec.expr.fn.RemoteFunctionRegistry; +import org.apache.drill.exec.physical.PhysicalPlan; +import org.apache.drill.exec.planner.sql.DirectPlan; +import org.apache.drill.exec.planner.sql.parser.SqlCreateFunction; +import org.apache.drill.exec.proto.UserBitShared.Func; +import org.apache.drill.exec.proto.UserBitShared.Jar; +import org.apache.drill.exec.proto.UserBitShared.Registry; +import org.apache.drill.exec.store.sys.store.DataChangeVersion; +import org.apache.drill.exec.util.JarUtil; +import org.apache.drill.exec.work.foreman.ForemanSetupException; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.FileUtil; +import org.apache.hadoop.fs.Path; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.UUID; + +public class CreateFunctionHandler extends DefaultSqlHandler { + + private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CreateFunctionHandler.class); + + public CreateFunctionHandler(SqlHandlerConfig config) { + super(config); + } + + /** + * Creates UDFs dynamically. + * + * @return - Single row indicating list of registered UDFs, raise exception otherwise + */ + @Override + public PhysicalPlan getPlan(SqlNode sqlNode) throws ForemanSetupException, IOException { + if (context.getOption(ExecConstants.DYNAMIC_UDF_SUPPORT_ENABLED).bool_val) { + SqlCreateFunction node = unwrap(sqlNode, SqlCreateFunction.class); + String jarName = ((SqlCharStringLiteral) node.getJar()).toValue(); + String sourceName = JarUtil.getSourceName(jarName); --- End diff -- Actually, all these local variables and operations cry out for a nested class that does the work. * The local variables become member variables, available to all methods. * The blocks of code become methods, each of which is simple and clear --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---