[tracker/subqueries-for-master] SPARQL: Fix type handling in aggregate functions



commit 090d5bda86eb1df98e959b47660a98897eea3a00
Author: Jürg Billeter <j bitron ch>
Date:   Tue Dec 8 11:30:46 2009 +0100

    SPARQL: Fix type handling in aggregate functions
    
    Improves performance when aggregating over resources.

 src/libtracker-data/tracker-sparql-query.vala |   41 ++++++++++--------------
 1 files changed, 17 insertions(+), 24 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 3915577..abd6ffd 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -576,41 +576,30 @@ public class Tracker.SparqlQuery : Object {
 	}
 
 	void translate_select_expression (StringBuilder sql) throws SparqlError {
+		long begin = sql.len;
+		var type = PropertyType.UNKNOWN;
+
 		if (accept (SparqlTokenType.COUNT)) {
 			sql.append ("COUNT(");
-			translate_expression_as_string (sql);
+			translate_expression (sql);
 			sql.append (")");
-			if (accept (SparqlTokenType.AS)) {
-				expect (SparqlTokenType.PN_PREFIX);
-			}
+			type = PropertyType.INTEGER;
 		} else if (accept (SparqlTokenType.SUM)) {
 			sql.append ("SUM(");
-			translate_expression_as_string (sql);
+			type = translate_expression (sql);
 			sql.append (")");
-			if (accept (SparqlTokenType.AS)) {
-				expect (SparqlTokenType.PN_PREFIX);
-			}
 		} else if (accept (SparqlTokenType.AVG)) {
 			sql.append ("AVG(");
-			translate_expression_as_string (sql);
+			type = translate_expression (sql);
 			sql.append (")");
-			if (accept (SparqlTokenType.AS)) {
-				expect (SparqlTokenType.PN_PREFIX);
-			}
 		} else if (accept (SparqlTokenType.MIN)) {
 			sql.append ("MIN(");
-			translate_expression_as_string (sql);
+			type = translate_expression (sql);
 			sql.append (")");
-			if (accept (SparqlTokenType.AS)) {
-				expect (SparqlTokenType.PN_PREFIX);
-			}
 		} else if (accept (SparqlTokenType.MAX)) {
 			sql.append ("MAX(");
-			translate_expression_as_string (sql);
+			type = translate_expression (sql);
 			sql.append (")");
-			if (accept (SparqlTokenType.AS)) {
-				expect (SparqlTokenType.PN_PREFIX);
-			}
 		} else if (accept (SparqlTokenType.GROUP_CONCAT)) {
 			sql.append ("GROUP_CONCAT(");
 			expect (SparqlTokenType.OPEN_PARENS);
@@ -620,11 +609,15 @@ public class Tracker.SparqlQuery : Object {
 			sql.append (escape_sql_string_literal (parse_string_literal ()));
 			sql.append (")");
 			expect (SparqlTokenType.CLOSE_PARENS);
-			if (accept (SparqlTokenType.AS)) {
-				expect (SparqlTokenType.PN_PREFIX);
-			}
+			type = PropertyType.STRING;
 		} else {
-			translate_expression_as_string (sql);
+			type = translate_expression (sql);
+		}
+
+		convert_expression_to_string (sql, type, begin);
+
+		if (accept (SparqlTokenType.AS)) {
+			expect (SparqlTokenType.PN_PREFIX);
 		}
 	}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]