Strabon

changeset 782:b9cde09d417d DiffDateTime

NOT WORKING but TupleExpr with diffDateTime is produces correctly.
author George Garbis <ggarbis@di.uoa.gr>
date Wed Dec 05 16:17:45 2012 +0200 (2012-12-05)
parents 69837cd17fb5
children 971584294be1
files evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/datetime/stsparql/metric/DiffDateTime.java generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBConnection.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/BinaryGeneralDBOperator.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java
line diff
     1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/datetime/stsparql/metric/DiffDateTime.java	Tue Dec 04 21:05:12 2012 +0200
     1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/datetime/stsparql/metric/DiffDateTime.java	Wed Dec 05 16:17:45 2012 +0200
     1.3 @@ -9,6 +9,13 @@
     1.4   */
     1.5  package org.openrdf.query.algebra.evaluation.function.datetime.stsparql.metric;
     1.6  
     1.7 +import java.text.SimpleDateFormat;
     1.8 +import java.util.Calendar;
     1.9 +import java.util.GregorianCalendar;
    1.10 +
    1.11 +import org.openrdf.model.Value;
    1.12 +import org.openrdf.model.ValueFactory;
    1.13 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    1.14  import org.openrdf.query.algebra.evaluation.function.spatial.DateTimeMetricFunc;
    1.15  import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants;
    1.16  
    1.17 @@ -24,4 +31,39 @@
    1.18  	public String getURI() {
    1.19  		return GeoConstants.diffDateTime;
    1.20  	}
    1.21 +	
    1.22 +//	@Override
    1.23 +//	public Value evaluate(ValueFactory valueFactory, Value... args)
    1.24 +//            throws ValueExprEvaluationException {
    1.25 +//        if (args.length != 2) {
    1.26 +//            throw new ValueExprEvaluationException(this.getURI()
    1.27 +//                    + " requires exactly 2 arguments, got " + args.length);
    1.28 +//        }
    1.29 +//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD'T'hh:mm:ss"); //the format of xsd:Datetime
    1.30 +//		
    1.31 +//		long diff = 0;
    1.32 +//    	try {
    1.33 +//    	    String date1 = args[0].toString();
    1.34 +//    	    date1 = date1.replace("^^<http://www.w3.org/2001/XMLSchema#dateTime>", "");
    1.35 +//    	    date1 = date1.replace("\"", "");
    1.36 +//    	    Calendar cal1 = new GregorianCalendar();
    1.37 +//    		cal1.setTime(sdf.parse(date1));
    1.38 +//    		
    1.39 +//    		String date2 = args[1].toString();
    1.40 +//    		date2 = date2.replace("^^<http://www.w3.org/2001/XMLSchema#dateTime>", "");
    1.41 +//    	    date2 = date2.replace("\"", "");
    1.42 +//    	    Calendar cal2 = new GregorianCalendar();
    1.43 +//    		cal2.setTime(sdf.parse(date2));
    1.44 +//    		
    1.45 +//    		diff = cal2.getTimeInMillis() - cal1.getTimeInMillis();
    1.46 +//    		
    1.47 +//    	} catch (java.text.ParseException e) {
    1.48 +//			// TODO Auto-generated catch block
    1.49 +//			e.printStackTrace();
    1.50 +//		}
    1.51 +//		
    1.52 +//		
    1.53 +//        return valueFactory.createLiteral(diff);
    1.54 +//    }
    1.55 +
    1.56  }
     2.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBConnection.java	Tue Dec 04 21:05:12 2012 +0200
     2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBConnection.java	Wed Dec 05 16:17:45 2012 +0200
     2.3 @@ -211,6 +211,7 @@
     2.4  			EvaluationStrategy strategy;
     2.5  			strategy = factory.createRdbmsEvaluation(dataset);
     2.6  			tupleExpr = optimizer.optimize(expr, dataset, bindings, strategy);
     2.7 +			// Mexri edw to GeneralDBSqlDiffDateTime ftanei kanonika
     2.8  			return strategy.evaluate(tupleExpr, EmptyBindingSet.getInstance());
     2.9  		}
    2.10  		catch (QueryEvaluationException e) {
     3.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/BinaryGeneralDBOperator.java	Tue Dec 04 21:05:12 2012 +0200
     3.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/BinaryGeneralDBOperator.java	Wed Dec 05 16:17:45 2012 +0200
     3.3 @@ -27,7 +27,7 @@
     3.4  	}
     3.5  
     3.6  	public BinaryGeneralDBOperator(GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg) {
     3.7 -		super();
     3.8 +		super(); // Edw to this(distance) exei ginei GeneralDBSqlGeoDistance
     3.9  		setLeftArg(leftArg);
    3.10  		setRightArg(rightArg);
    3.11  	}
     4.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java	Tue Dec 04 21:05:12 2012 +0200
     4.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java	Wed Dec 05 16:17:45 2012 +0200
     4.3 @@ -106,7 +106,7 @@
     4.4  	@Override
     4.5  	public void meet(Compare compare)
     4.6  			throws UnsupportedRdbmsOperatorException
     4.7 -			{
     4.8 +	{
     4.9  		ValueExpr left = compare.getLeftArg();
    4.10  		ValueExpr right = compare.getRightArg();
    4.11  		CompareOp op = compare.getOperator();
    4.12 @@ -115,17 +115,19 @@
    4.13  		 * 
    4.14  		 */
    4.15  		boolean leftIsSpatial = false;
    4.16 +		boolean leftIsDateTime = false;
    4.17  		boolean rightIsSpatial = false;
    4.18 +		boolean rightIsDateTime = false;
    4.19  		GeneralDBSqlExpr leftSql = null;
    4.20  		GeneralDBSqlExpr rightSql = null;
    4.21  
    4.22  		if(left instanceof FunctionCall)
    4.23  		{
    4.24  			Function function = FunctionRegistry.getInstance().get(((FunctionCall)left).getURI());
    4.25 -			leftIsSpatial = true;
    4.26  			if(function instanceof SpatialMetricFunc)
    4.27  			{
    4.28  				leftSql = spatialMetricFunction((FunctionCall) left, function);
    4.29 +				leftIsSpatial = true;
    4.30  			}
    4.31  			/**
    4.32  			 * Addition for datetime metric functions
    4.33 @@ -134,13 +136,15 @@
    4.34  			 * 
    4.35  			 */
    4.36  			else if (function instanceof DateTimeMetricFunc){
    4.37 +				// Edw prepei na epistrafei ena GenearalDBSqlDiffDateTime me parent=null
    4.38  				leftSql = dateTimeMetricFunction((FunctionCall)left, function);
    4.39 -				leftIsSpatial = false;
    4.40 +				leftIsDateTime = true;
    4.41  			}
    4.42  			/***/
    4.43  			else //spatial property
    4.44  			{
    4.45  				leftSql = spatialPropertyFunction((FunctionCall) left, function);
    4.46 +				leftIsSpatial = true;
    4.47  			}
    4.48  		}
    4.49  		else if(left instanceof MathExpr)
    4.50 @@ -155,30 +159,35 @@
    4.51  
    4.52  		if(right instanceof FunctionCall)
    4.53  		{
    4.54 -			System.out.println("FUNCTION:"+right.toString());
    4.55  			Function function = FunctionRegistry.getInstance().get(((FunctionCall)right).getURI());
    4.56  			if(function instanceof SpatialMetricFunc)
    4.57  			{
    4.58  				rightSql = spatialMetricFunction((FunctionCall) right, function);
    4.59 +				rightIsSpatial = true;
    4.60  			}
    4.61 -			else if(((FunctionCall) right).getURI().toString().equalsIgnoreCase("http://example.org/custom-function/addDatetime"))
    4.62 -			{
    4.63 -				System.out.println("ADD DATE TIME FUNC!");
    4.64 -				FunctionRegistry fr =  FunctionRegistry.getInstance();
    4.65 -				Function f = fr.get("http://example.org/custom-function/addDatetime");
    4.66 -				if (f == null){System.out.println("COULD NOT GET DA FUNCTION!");}
    4.67 +			/**
    4.68 +			 * Addition for datetime metric functions
    4.69 +			 * 
    4.70 +			 * @author George Garbis <ggarbis@di.uoa.gr>
    4.71 +			 * 
    4.72 +			 */
    4.73 +			else if (function instanceof DateTimeMetricFunc){
    4.74 +				// Edw prepei na epistrafei ena GenearalDBSqlDiffDateTime me parent=null
    4.75 +				rightSql = dateTimeMetricFunction((FunctionCall)right, function);
    4.76 +				rightIsDateTime = true;
    4.77  			}
    4.78 +			/***/
    4.79  			else //spatial property
    4.80  			{
    4.81  				System.out.println("SPATIAL PROPERTY!!!");
    4.82  				rightSql = spatialPropertyFunction((FunctionCall) right, function);
    4.83 +				rightIsSpatial = true;
    4.84  			}
    4.85 -			rightIsSpatial = true;
    4.86  		}
    4.87  		else if(right instanceof MathExpr)
    4.88  		{
    4.89  			//some recursive function plainly to find out whether there is some nested metric
    4.90 -			rightIsSpatial = containsMetric((MathExpr)left);
    4.91 +			rightIsSpatial = containsMetric((MathExpr)right);
    4.92  			if(rightIsSpatial)
    4.93  			{
    4.94  				rightSql = numeric(right);
    4.95 @@ -191,7 +200,7 @@
    4.96  
    4.97  		switch (op) {
    4.98  		case EQ:
    4.99 -			if(!rightIsSpatial&&!leftIsSpatial)
   4.100 +			if( (!rightIsSpatial && !rightIsDateTime) && (!leftIsSpatial && !leftIsDateTime) )
   4.101  			{
   4.102  				//default cases
   4.103  				if (isTerm(left) && isTerm(right)) {
   4.104 @@ -205,12 +214,12 @@
   4.105  			else
   4.106  			{
   4.107  				//more complicated cases
   4.108 -				if(!rightIsSpatial)
   4.109 +				if(!rightIsSpatial && !rightIsDateTime)
   4.110  				{
   4.111  					rightSql = numeric(right);
   4.112  				}
   4.113  
   4.114 -				if(!leftIsSpatial)
   4.115 +				if(!leftIsSpatial && !leftIsDateTime)
   4.116  				{
   4.117  					leftSql = numeric(right);
   4.118  				}
   4.119 @@ -218,7 +227,7 @@
   4.120  			}
   4.121  			break;
   4.122  		case NE:
   4.123 -			if(!rightIsSpatial&&!leftIsSpatial)
   4.124 +			if( (!rightIsSpatial && !rightIsDateTime) && (!leftIsSpatial && !leftIsDateTime) )
   4.125  			{
   4.126  				//default cases
   4.127  				if (isTerm(left) && isTerm(right)) {
   4.128 @@ -232,12 +241,12 @@
   4.129  			else
   4.130  			{
   4.131  				//more complicated cases
   4.132 -				if(!rightIsSpatial)
   4.133 +				if(!rightIsSpatial && !rightIsDateTime)
   4.134  				{
   4.135  					rightSql = numeric(right);
   4.136  				}
   4.137  
   4.138 -				if(!leftIsSpatial)
   4.139 +				if(!leftIsSpatial && !leftIsSpatial)
   4.140  				{
   4.141  					leftSql = numeric(right);
   4.142  				}
   4.143 @@ -249,7 +258,7 @@
   4.144  		case LE:
   4.145  		case LT:
   4.146  
   4.147 -			if(!rightIsSpatial&&!leftIsSpatial)
   4.148 +			if( (!rightIsSpatial && !rightIsDateTime) && (!leftIsSpatial && !leftIsDateTime) )
   4.149  			{
   4.150  				//default cases
   4.151  				GeneralDBSqlExpr simple = and(simple(type(left)), simple(type(right)));
   4.152 @@ -269,12 +278,12 @@
   4.153  			else
   4.154  			{
   4.155  				//more complicated cases
   4.156 -				if(!rightIsSpatial)
   4.157 +				if(!rightIsSpatial && !rightIsDateTime)
   4.158  				{
   4.159  					rightSql = numeric(right);
   4.160  				}
   4.161  
   4.162 -				if(!leftIsSpatial)
   4.163 +				if(!leftIsSpatial && !leftIsSpatial)
   4.164  				{
   4.165  					leftSql = numeric(right);
   4.166  				}
   4.167 @@ -283,7 +292,7 @@
   4.168  
   4.169  			break;
   4.170  		}
   4.171 -			}
   4.172 +	}
   4.173  
   4.174  	@Override
   4.175  	public void meet(IsBNode node)
     5.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java	Tue Dec 04 21:05:12 2012 +0200
     5.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java	Wed Dec 05 16:17:45 2012 +0200
     5.3 @@ -879,6 +879,7 @@
     5.4  			throws RuntimeException
     5.5  			{
     5.6  		super.meet(node);
     5.7 +		// Edw ftanei to Filter GeneralDBSqlDiffDateTime!
     5.8  		if (node.getArg() instanceof GeneralDBSelectQuery) {
     5.9  			GeneralDBSelectQuery query = (GeneralDBSelectQuery)node.getArg();
    5.10