[tracker/subqueries] SPARQL: Fix type handling in select expressions
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/subqueries] SPARQL: Fix type handling in select expressions
- Date: Mon, 7 Dec 2009 16:07:00 +0000 (UTC)
commit 1431e1615c4bb6f95d131ca47e2c091cf93013e6
Author: Jürg Billeter <j bitron ch>
Date: Mon Dec 7 16:54:05 2009 +0100
SPARQL: Fix type handling in select expressions
Improves performance of COUNT.
src/libtracker-data/tracker-sparql-query.vala | 56 +++++++++----------------
1 files changed, 20 insertions(+), 36 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 82f6fd4..db3138f 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -612,44 +612,31 @@ public class Tracker.SparqlQuery : Object {
}
void translate_select_expression (StringBuilder sql, bool subquery) throws SparqlError {
- // FIXME: support AS ?var for all aggregation functions / expressions
+ 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.VAR);
- string variable_name = get_last_string ().substring (1);
- sql.append_printf (" AS %s", get_variable (variable_name).sql_expression);
- }
+ 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);
- }
+ convert_expression_to_string (sql, type, begin);
} 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);
@@ -659,20 +646,17 @@ 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 {
- if (subquery) {
- translate_expression (sql);
- } else {
- translate_expression_as_string (sql);
- }
- if (accept (SparqlTokenType.AS)) {
- expect (SparqlTokenType.VAR);
- string variable_name = get_last_string ().substring (1);
- sql.append_printf (" AS %s", get_variable (variable_name).sql_expression);
- }
+ type = translate_expression (sql);
+ }
+ if (!subquery) {
+ convert_expression_to_string (sql, type, begin);
+ }
+ if (accept (SparqlTokenType.AS)) {
+ expect (SparqlTokenType.VAR);
+ string variable_name = get_last_string ().substring (1);
+ sql.append_printf (" AS %s", get_variable (variable_name).sql_expression);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]