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 A9173200B6B for ; Fri, 9 Sep 2016 15:16:42 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A7973160AC2; Fri, 9 Sep 2016 13:16:42 +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 F0DF7160AB6 for ; Fri, 9 Sep 2016 15:16:41 +0200 (CEST) Received: (qmail 9861 invoked by uid 500); 9 Sep 2016 13:16:41 -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 9849 invoked by uid 99); 9 Sep 2016 13:16:40 -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; Fri, 09 Sep 2016 13:16:40 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B3F52E025B; Fri, 9 Sep 2016 13:16:40 +0000 (UTC) From: arina-ielchiieva 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: <20160909131640.B3F52E025B@git1-us-west.apache.org> Date: Fri, 9 Sep 2016 13:16:40 +0000 (UTC) archived-at: Fri, 09 Sep 2016 13:16:42 -0000 Github user arina-ielchiieva commented on a diff in the pull request: https://github.com/apache/drill/pull/574#discussion_r78177586 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillFunctionRegistry.java --- @@ -218,4 +302,141 @@ private void registerOperatorsWithoutInference(DrillOperatorTable operatorTable) } } } + + /** + * Function registry holder. Stores function implementations by jar name, function name. + */ + private class GenericRegistryHolder { + private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); + private final AutoCloseableLock readLock = new AutoCloseableLock(readWriteLock.readLock()); + private final AutoCloseableLock writeLock = new AutoCloseableLock(readWriteLock.writeLock()); + + // jar name, Map + private final Map>> jars; + + // function name, Map + private final Map> functions; + + public GenericRegistryHolder() { + this.functions = Maps.newHashMap(); + this.jars = Maps.newHashMap(); + } + + public void addJar(T jName, Map> sNameMap) { + try (AutoCloseableLock lock = writeLock.open()) { + Map> map = jars.get(jName); + if (map != null) { + removeAllByJar(jName); + } + map = Maps.newHashMap(); + jars.put(jName, map); + + for (Entry> entry : sNameMap.entrySet()) { + T sName = entry.getKey(); + Pair pair = entry.getValue(); + addFunction(jName, pair.getKey(), sName, pair.getValue()); + } + } + } + + public void removeJar(T jName) { + try (AutoCloseableLock lock = writeLock.open()) { + removeAllByJar(jName); + } + } + + public List getAllJarNames() { + try (AutoCloseableLock lock = readLock.open()) { + return Lists.newArrayList(jars.keySet()); + } + } + + public List getAllFunctionNames(T jName) { + try (AutoCloseableLock lock = readLock.open()){ + Map> map = jars.get(jName); + return map == null ? Lists.newArrayList() : Lists.newArrayList(map.keySet()); + } + } + + public ListMultimap getAllFunctionsWithHolders() { + try (AutoCloseableLock lock = readLock.open()) { + ListMultimap multimap = ArrayListMultimap.create(); + for (Entry> entry : functions.entrySet()) { + multimap.putAll(entry.getKey(), Lists.newArrayList(entry.getValue().values())); + } + return multimap; + } + } + + public ListMultimap getAllFunctionsWithSignatures() { + try (AutoCloseableLock lock = readLock.open()) { + ListMultimap multimap = ArrayListMultimap.create(); + for (Entry> entry : functions.entrySet()) { + multimap.putAll(entry.getKey(), Lists.newArrayList(entry.getValue().keySet())); + } + return multimap; + } + } + + public List getHoldersByFunctionName(T fName) { + try (AutoCloseableLock lock = readLock.open()) { + Map map = functions.get(fName); + return map == null ? Lists.newArrayList() : Lists.newArrayList(map.values()); + } + } + + public boolean containsJar(T jName) { + try (AutoCloseableLock lock = readLock.open()) { + return jars.containsKey(jName); + } + } + + public int functionsSize() { + try (AutoCloseableLock lock = readLock.open()) { + return functions.size(); + } + } + + private void addFunction(T jName, T fName, T sName, U fHolder) { + Map> map = jars.get(jName); + + List list = map.get(fName); + if (list == null) { + list = Lists.newArrayList(); + map.put(fName, list); + } + + if (!list.contains(sName)) { + list.add(sName); + + Map sigsMap = functions.get(fName); + if (sigsMap == null) { + sigsMap = Maps.newHashMap(); + functions.put(fName, sigsMap); + } + + U u = sigsMap.get(sName); --- End diff -- You are right. Actually we don't expect any duplicates in jar, since we are adding jars only after validation. I'll remove unnecessary checks. --- 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. ---