You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2014/12/28 20:05:41 UTC

[2/4] jena git commit: JENA-803 : Bare framework for custom aggregates

JENA-803 : Bare framework for custom aggregates

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/addc1987
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/addc1987
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/addc1987

Branch: refs/heads/master
Commit: addc1987ee41505053686eb76c62e9045806fa5e
Parents: a1ee6e1
Author: Andy Seaborne <an...@apache.org>
Authored: Sun Dec 28 18:38:28 2014 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Sun Dec 28 18:38:28 2014 +0000

----------------------------------------------------------------------
 .../expr/aggregate/AccumulatorFactory.java      | 31 +++++++++
 .../expr/aggregate/AggregateRegistry.java       | 70 ++++++++++++++++++++
 2 files changed, 101 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/addc1987/jena-arq/src/main/java/com/hp/hpl/jena/sparql/expr/aggregate/AccumulatorFactory.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/expr/aggregate/AccumulatorFactory.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/expr/aggregate/AccumulatorFactory.java
new file mode 100644
index 0000000..e5ba9cc
--- /dev/null
+++ b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/expr/aggregate/AccumulatorFactory.java
@@ -0,0 +1,31 @@
+/**
+ * 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 com.hp.hpl.jena.sparql.expr.aggregate;
+
+/** Fatory to create accumulators. An Accumulator is
+ * processor for one group key for one execution.
+ */
+public interface AccumulatorFactory {
+    /**
+     * 
+     * @return Accumulator
+     */
+    public Accumulator createAccumulator(AggCustom agg) ;
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/addc1987/jena-arq/src/main/java/com/hp/hpl/jena/sparql/expr/aggregate/AggregateRegistry.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/expr/aggregate/AggregateRegistry.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/expr/aggregate/AggregateRegistry.java
new file mode 100644
index 0000000..b47ff81
--- /dev/null
+++ b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/expr/aggregate/AggregateRegistry.java
@@ -0,0 +1,70 @@
+/**
+ * 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 com.hp.hpl.jena.sparql.expr.aggregate;
+
+import java.util.HashMap ;
+import java.util.Map ;
+
+import com.hp.hpl.jena.graph.Node ;
+
+/** Registry of custom aggregates
+ * There is only a single global registry of aggregates - it affects parsing
+ * and parsing happens before Context or Execution makes sense.   
+ */
+public class AggregateRegistry {
+    
+    private static Map<String, AccumulatorFactory> registry = new HashMap<>() ;
+    private static Map<String, Node>               noGroupValues = new HashMap<>() ;
+    
+    /**
+     * Register a custom aggregate, with its associated factory for accumulators.
+     */
+    public static void register(String uri, AccumulatorFactory accFactory) {
+        register(uri, accFactory, null) ;
+    }
+
+    public static void register(String uri, AccumulatorFactory accFactory, Node noGroupValue) {
+        registry.put(uri, accFactory) ;
+        noGroupValues.put(uri, noGroupValue) ;
+    }
+
+    /**
+     * Remove a registration.
+     */
+    public static void unregister(String uri) {
+        registry.remove(uri) ;
+        noGroupValues.remove(uri) ;
+    }
+    
+    /** Return the AccumulatorFactory for a registered custom aggregate. */
+    public static AccumulatorFactory getAccumulatorFactory(String uri) {
+        return registry.get(uri) ;
+    }
+    
+    /** Return the AccumulatorFactory for a registered custom aggregate. */
+    public static Node getNoGroupValue(String uri) {
+        return noGroupValues.get(uri) ;
+    }
+
+    /** Return the AccumulatorFactory for a registered custom aggregate. */
+    public static boolean isRegistered(String uri) {
+        return registry.containsKey(uri) ;
+    }
+}
+