marmotta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sschaff...@apache.org
Subject git commit: some more aggregation functions
Date Tue, 16 Sep 2014 16:43:59 GMT
Repository: marmotta
Updated Branches:
  refs/heads/develop 4e63ca961 -> 9ead232e1


some more aggregation functions


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

Branch: refs/heads/develop
Commit: 9ead232e199c6fa6aa5a50d726cec48efd51151c
Parents: 4e63ca9
Author: Sebastian Schaffert <sschaffert@apache.org>
Authored: Tue Sep 16 18:44:17 2014 +0200
Committer: Sebastian Schaffert <sschaffert@apache.org>
Committed: Tue Sep 16 18:44:17 2014 +0200

----------------------------------------------------------------------
 .../marmotta/kiwi/sparql/builder/SQLBuilder.java     |  7 +++++++
 .../evaluation/KiWiEvaluationStrategyImpl.java       |  2 ++
 .../kiwi/persistence/pgsql/PostgreSQLDialect.java    | 15 +++++++++++++++
 .../apache/marmotta/kiwi/vocabulary/FN_MARMOTTA.java |  8 ++++++++
 4 files changed, 32 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/9ead232e/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
index 942c0f5..20cfcc5 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/SQLBuilder.java
@@ -100,6 +100,8 @@ public class SQLBuilder {
         functionParameterTypes.put(FN_MARMOTTA.SHA384, OPTypes.STRING);
         functionParameterTypes.put(FN_MARMOTTA.SHA512, OPTypes.STRING);
 
+        functionParameterTypes.put(FN_MARMOTTA.STDDEV, OPTypes.DOUBLE);
+        functionParameterTypes.put(FN_MARMOTTA.VARIANCE, OPTypes.DOUBLE);
     }
 
     /**
@@ -142,6 +144,9 @@ public class SQLBuilder {
         functionReturnTypes.put(FN_MARMOTTA.SHA256, OPTypes.STRING);
         functionReturnTypes.put(FN_MARMOTTA.SHA384, OPTypes.STRING);
         functionReturnTypes.put(FN_MARMOTTA.SHA512, OPTypes.STRING);
+
+        functionReturnTypes.put(FN_MARMOTTA.STDDEV, OPTypes.DOUBLE);
+        functionReturnTypes.put(FN_MARMOTTA.VARIANCE, OPTypes.DOUBLE);
     }
 
 
@@ -966,6 +971,8 @@ public class SQLBuilder {
             return "MIN(" + evaluateExpression(((Min) expr).getArg(), OPTypes.DOUBLE) + ")";
         } else if(expr instanceof Max) {
             return "MAX(" + evaluateExpression(((Max) expr).getArg(), OPTypes.DOUBLE) + ")";
+        } else if(expr instanceof Sum) {
+            return "SUM(" + evaluateExpression(((Max) expr).getArg(), OPTypes.DOUBLE) + ")";
         } else if(expr instanceof FunctionCall) {
             FunctionCall fc = (FunctionCall)expr;
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/9ead232e/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategyImpl.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategyImpl.java
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategyImpl.java
index cb2f23d..67f3d84 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategyImpl.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategyImpl.java
@@ -354,6 +354,8 @@ public class KiWiEvaluationStrategyImpl extends EvaluationStrategyImpl{
             return isSupported(((Min) expr).getArg());
         } else if(expr instanceof Max) {
             return isSupported(((Max) expr).getArg());
+        } else if(expr instanceof Sum) {
+            return isSupported(((Sum) expr).getArg());
         } else if(expr instanceof Compare) {
             return isSupported(((Compare) expr).getLeftArg()) && isSupported(((Compare)
expr).getRightArg());
         } else if(expr instanceof MathExpr) {

http://git-wip-us.apache.org/repos/asf/marmotta/blob/9ead232e/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/pgsql/PostgreSQLDialect.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/pgsql/PostgreSQLDialect.java
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/pgsql/PostgreSQLDialect.java
index b7d1fea..fc74898 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/pgsql/PostgreSQLDialect.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/pgsql/PostgreSQLDialect.java
@@ -83,6 +83,9 @@ public class PostgreSQLDialect extends KiWiDialect {
         supportedFunctions.put(FN_MARMOTTA.SHA256);
         supportedFunctions.put(FN_MARMOTTA.SHA384);
         supportedFunctions.put(FN_MARMOTTA.SHA512);
+
+        supportedFunctions.put(FN_MARMOTTA.STDDEV);
+        supportedFunctions.put(FN_MARMOTTA.VARIANCE);
     }
 
     /**
@@ -363,6 +366,18 @@ public class PostgreSQLDialect extends KiWiDialect {
             } else {
                 throw new IllegalArgumentException("SECONDS() takes exactly 1 argument");
             }
+        } else if(FN_MARMOTTA.STDDEV.equals(fnUri)) {
+            if(args.length == 1) {
+                return String.format("stddev(%s)", args[0]);
+            } else {
+                throw new IllegalArgumentException("STDDEV() takes exactly 1 argument");
+            }
+        } else if(FN_MARMOTTA.VARIANCE.equals(fnUri)) {
+            if(args.length == 1) {
+                return String.format("variance(%s)", args[0]);
+            } else {
+                throw new IllegalArgumentException("VARIANCE() takes exactly 1 argument");
+            }
         }
         throw new UnsupportedOperationException("operation "+fnUri+" not supported");
     }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/9ead232e/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/vocabulary/FN_MARMOTTA.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/vocabulary/FN_MARMOTTA.java
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/vocabulary/FN_MARMOTTA.java
index 89f2b41..d8fd2da 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/vocabulary/FN_MARMOTTA.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/vocabulary/FN_MARMOTTA.java
@@ -68,6 +68,11 @@ public class FN_MARMOTTA {
     public static final URI SHA512;
 
 
+    // statistics functions (supported by e.g. PostgreSQL)
+    public static final URI STDDEV;
+    public static final URI VARIANCE;
+
+
     static {
         ValueFactory f = new ValueFactoryImpl();
 
@@ -91,5 +96,8 @@ public class FN_MARMOTTA {
         SHA256    = f.createURI(NAMESPACE,"sha256");
         SHA384    = f.createURI(NAMESPACE,"sha384");
         SHA512    = f.createURI(NAMESPACE,"sha512");
+
+        STDDEV    = f.createURI(NAMESPACE,"stddev");
+        VARIANCE  = f.createURI(NAMESPACE,"variance");
     }
 }


Mime
View raw message