You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2018/10/03 23:15:59 UTC

[GitHub] kkhatua commented on a change in pull request #1483: DRILL-3988: Expose Drill built-in functions & UDFs in a system table

kkhatua commented on a change in pull request #1483: DRILL-3988: Expose Drill built-in functions & UDFs  in a system table
URL: https://github.com/apache/drill/pull/1483#discussion_r222496506
 
 

 ##########
 File path: exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/FunctionsIterator.java
 ##########
 @@ -0,0 +1,167 @@
+/*
+ * 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.store.sys;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.drill.exec.expr.fn.DrillFuncHolder;
+import org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry;
+import org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry;
+import org.apache.drill.exec.ops.ExecutorFragmentContext;
+import org.apache.drill.exec.proto.UserBitShared.Jar;
+import org.apache.drill.exec.proto.UserBitShared.Registry;
+import org.apache.drill.exec.store.pojo.NonNullable;
+import org.apache.drill.exec.store.sys.store.DataChangeVersion;
+import org.apache.drill.shaded.guava.com.google.common.collect.ListMultimap;
+
+/**
+ * List functions as a System Table
+ */
+public class FunctionsIterator implements Iterator<Object> {
+  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(FunctionsIterator.class);
+
+  private LocalFunctionRegistry localFunctionRegistry;
+  private RemoteFunctionRegistry remoteFunctionRegistry;
+  private Iterator<FunctionInfo> sortedIterator;
+
+  public FunctionsIterator(ExecutorFragmentContext context) {
+    Map<String, FunctionInfo> functionMap = new HashMap<String, FunctionInfo>();
+
+    this.localFunctionRegistry = context.getLocalFunctionRegistry();
+    listLocalFunctionRegistry(functionMap);
+
+    this.remoteFunctionRegistry = context.getRemoteFunctionRegistry();
+    listRemoteFunctionRegistry(functionMap);
+
+    //Extract list & sort via comparator
+    List<FunctionInfo> functionList = new ArrayList<FunctionsIterator.FunctionInfo>(functionMap.values());
+    functionList.sort(initFunctionComparator());
+    sortedIterator = functionList.iterator();
+  }
+
+  //Provide a function comparator
+  private Comparator<FunctionInfo> initFunctionComparator() {
+    //Initialize the comparator
+    return new Comparator<FunctionInfo>() {
+      @Override
+      public int compare(FunctionInfo o1, FunctionInfo o2) {
+        int result = o1.name.compareTo(o2.name);
+        if (result == 0) {
+          result = o1.signature.compareTo(o2.signature);
+        }
+        if (result == 0) {
+          return o1.returnType.compareTo(o2.returnType);
+        }
+        return result;
+      }
+    };
+  }
+
+  //Loads local-registry functions into functionMap
+  private void listLocalFunctionRegistry(Map<String, FunctionInfo> functionMap) {
+    ListMultimap<String, DrillFuncHolder> builtInFuncHolderList = localFunctionRegistry.getRegistryHolder().getAllFunctionsWithHolders();
+    logger.debug("{} functions are currently initialized", builtInFuncHolderList.size());
+
+    Iterator<String> builtInFuncIter = builtInFuncHolderList.asMap().keySet().iterator();
+    while (builtInFuncIter.hasNext()) {
+      String s = builtInFuncIter.next();
+      for (DrillFuncHolder drillFuncHolder : builtInFuncHolderList.get(s)) {
+        String registeredNames[] = drillFuncHolder.getRegisteredNames();
+        String signature = drillFuncHolder.getInputParameters();
+        String returnType = drillFuncHolder.getReturnType().getMinorType().toString();
+        for (String name : registeredNames) {
+          FunctionInfo fnInfo = new FunctionInfo(name, signature, returnType, LocalFunctionRegistry.BUILT_IN);
+          functionMap.put(generateKey(name, signature), fnInfo);
+        }
+      }
+    }
+  }
+
+  //Loads remote-registry functions into functionMap (updates if
+  private void listRemoteFunctionRegistry(Map<String, FunctionInfo> functionMap) {
 
 Review comment:
   Thanks, @arina-ielchiieva . Modified the PR as per your suggestion.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services