marmotta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sschaff...@apache.org
Subject marmotta git commit: fix decimal handling for many queries
Date Tue, 11 Nov 2014 10:14:51 GMT
Repository: marmotta
Updated Branches:
  refs/heads/develop 488d4e6f8 -> 676607916


fix decimal handling for many queries


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

Branch: refs/heads/develop
Commit: 676607916bda0bfef763f7f02cf22d2768aad7aa
Parents: 488d4e6
Author: Sebastian Schaffert <sschaffert@apache.org>
Authored: Tue Nov 11 11:15:24 2014 +0100
Committer: Sebastian Schaffert <sschaffert@apache.org>
Committed: Tue Nov 11 11:15:33 2014 +0100

----------------------------------------------------------------------
 .../marmotta/kiwi/sparql/builder/SQLBuilder.java      |  1 +
 .../marmotta/kiwi/sparql/builder/ValueType.java       | 10 ++++++++--
 .../kiwi/sparql/builder/collect/OPTypeFinder.java     |  9 +++++----
 .../sparql/builder/eval/ValueExpressionEvaluator.java |  4 ++++
 .../sparql/evaluation/KiWiEvaluationStrategy.java     | 14 ++++++++++++++
 .../kiwi/sparql/function/cast/NDecimalCast.java       |  2 +-
 .../kiwi/sparql/function/datetime/NSeconds.java       |  2 +-
 7 files changed, 34 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/67660791/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 581e6ad..cebefdb 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
@@ -374,6 +374,7 @@ public class SQLBuilder {
                                 case INT:
                                     p.getConditions().add(sv.getExpressions().get(0) + "
= " + sv.getAlias() + ".ivalue");
                                     break;
+                                case DECIMAL:
                                 case DOUBLE:
                                     p.getConditions().add(sv.getExpressions().get(0) + "
= " + sv.getAlias() + ".dvalue");
                                     break;

http://git-wip-us.apache.org/repos/asf/marmotta/blob/67660791/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ValueType.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ValueType.java
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ValueType.java
index 4d1ed87..f33200c 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ValueType.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/ValueType.java
@@ -23,7 +23,8 @@ package org.apache.marmotta.kiwi.sparql.builder;
 * @author Sebastian Schaffert (sschaffert@apache.org)
 */
 public enum ValueType {
-    DOUBLE, // double, float or decimal value
+    DOUBLE, // double or float value
+    DECIMAL,// decimal value
     INT,    // long or integer value
     DATE,   // UTC date, dateTime or time
     TZDATE, // date, dateTime or time with timezone
@@ -33,5 +34,10 @@ public enum ValueType {
     TERM,   // value of constructed term
     URI,    // constructed URI
     BNODE,  // constructed BNODE
-    NONE    // not projected
+    NONE;    // not projected
+
+
+    public final boolean isNumeric() {
+        return this == DOUBLE || this == DECIMAL || this == INT;
+    }
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/67660791/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/collect/OPTypeFinder.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/collect/OPTypeFinder.java
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/collect/OPTypeFinder.java
index c09f384..d0bdd80 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/collect/OPTypeFinder.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/collect/OPTypeFinder.java
@@ -51,9 +51,10 @@ public class OPTypeFinder extends QueryModelVisitorBase<RuntimeException>
{
             String type = l.getDatatype() != null ? l.getDatatype().stringValue() : null;
 
             if(StringUtils.equals(Namespaces.NS_XSD + "double", type)
-                    || StringUtils.equals(Namespaces.NS_XSD + "float", type)
-                    || StringUtils.equals(Namespaces.NS_XSD + "decimal", type)) {
+                    || StringUtils.equals(Namespaces.NS_XSD + "float", type)) {
                 optypes.add(ValueType.DOUBLE);
+            } else if(StringUtils.equals(Namespaces.NS_XSD + "decimal", type)) {
+                optypes.add(ValueType.DECIMAL);
             } else if(StringUtils.equals(Namespaces.NS_XSD + "integer", type)
                     || StringUtils.equals(Namespaces.NS_XSD + "long", type)
                     || StringUtils.equals(Namespaces.NS_XSD + "int", type)
@@ -131,8 +132,8 @@ public class OPTypeFinder extends QueryModelVisitorBase<RuntimeException>
{
                 // keep left
             } else if(left == right) {
                 // keep left
-            } else if( (left == ValueType.INT && right == ValueType.DOUBLE) || (left
== ValueType.DOUBLE && right == ValueType.INT)) {
-                left = ValueType.DOUBLE;
+            } else if(left.isNumeric() && right.isNumeric()) {
+                left =  left.compareTo(right) < 0 ? left : right;
             } else if( (left == ValueType.STRING) || (right == ValueType.STRING)) {
                 left = ValueType.STRING;
             } else {

http://git-wip-us.apache.org/repos/asf/marmotta/blob/67660791/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/eval/ValueExpressionEvaluator.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/eval/ValueExpressionEvaluator.java
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/eval/ValueExpressionEvaluator.java
index 1bc0036..9bd943e 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/eval/ValueExpressionEvaluator.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/builder/eval/ValueExpressionEvaluator.java
@@ -592,6 +592,7 @@ public class ValueExpressionEvaluator extends QueryModelVisitorBase<RuntimeExcep
                         Preconditions.checkState(var != null, "no alias available for variable");
                         builder.append(var).append(".ivalue");
                         break;
+                    case DECIMAL:
                     case DOUBLE:
                         Preconditions.checkState(var != null, "no alias available for variable");
                         builder.append(var).append(".dvalue");
@@ -639,6 +640,7 @@ public class ValueExpressionEvaluator extends QueryModelVisitorBase<RuntimeExcep
                 case INT:
                     builder.append(Integer.parseInt(val));
                     break;
+                case DECIMAL:
                 case DOUBLE:
                     builder.append(Double.parseDouble(val));
                     break;
@@ -694,6 +696,8 @@ public class ValueExpressionEvaluator extends QueryModelVisitorBase<RuntimeExcep
         }
 
         switch (type) {
+            case DECIMAL:
+                return functionRegistry.get(XMLSchema.DECIMAL).getNative(parent.getDialect(),
arg);
             case DOUBLE:
                 return functionRegistry.get(XMLSchema.DOUBLE).getNative(parent.getDialect(),
arg);
             case INT:

http://git-wip-us.apache.org/repos/asf/marmotta/blob/67660791/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategy.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategy.java
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategy.java
index 3d4f314..be0f5df 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategy.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/evaluation/KiWiEvaluationStrategy.java
@@ -296,6 +296,20 @@ public class KiWiEvaluationStrategy extends EvaluationStrategyImpl{
                                             resultRow.addBinding(sv.getSparqlName(), new
LiteralImpl(svalue, type));
                                         }
                                         break;
+                                    case DECIMAL:
+                                        if(row.getObject(sv.getName()) != null) {
+                                            svalue = row.getBigDecimal(sv.getName()).toString();
+                                            URI type = XSD.Decimal;
+                                            try {
+                                                long typeId = row.getLong(sv.getName() +
"_TYPE");
+                                                if (typeId > 0)
+                                                    type = (URI) connection.loadNodeById(typeId);
+                                            } catch (SQLException ex) {
+                                            }
+
+                                            resultRow.addBinding(sv.getSparqlName(), new
LiteralImpl(svalue, type));
+                                        }
+                                        break;
                                     case BOOL:
                                         if(row.getObject(sv.getName()) != null) {
                                             svalue = Boolean.toString(row.getBoolean(sv.getName()));

http://git-wip-us.apache.org/repos/asf/marmotta/blob/67660791/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/cast/NDecimalCast.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/cast/NDecimalCast.java
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/cast/NDecimalCast.java
index 138eb02..990bd89 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/cast/NDecimalCast.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/cast/NDecimalCast.java
@@ -62,7 +62,7 @@ public class NDecimalCast extends DecimalCast implements NativeFunction
{
      */
     @Override
     public ValueType getReturnType() {
-        return ValueType.DOUBLE;
+        return ValueType.DECIMAL;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/marmotta/blob/67660791/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NSeconds.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NSeconds.java
b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NSeconds.java
index b358208..fd8ee92 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NSeconds.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/function/datetime/NSeconds.java
@@ -69,7 +69,7 @@ public class NSeconds extends Seconds implements NativeFunction {
      */
     @Override
     public ValueType getReturnType() {
-        return ValueType.DOUBLE;
+        return ValueType.DECIMAL;
     }
 
     /**


Mime
View raw message