[tracker/bug617515] SPARQL: Allow aggregate expressions as subexpressions
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/bug617515] SPARQL: Allow aggregate expressions as subexpressions
- Date: Tue, 11 May 2010 13:15:33 +0000 (UTC)
commit 70f5ac64c22773e220e190e2e2c8083430b108d4
Author: Jürg Billeter <j bitron ch>
Date: Tue May 11 15:08:30 2010 +0200
SPARQL: Allow aggregate expressions as subexpressions
Fixes GB#617515.
src/libtracker-data/tracker-sparql-expression.vala | 78 +++++++++++---------
1 files changed, 44 insertions(+), 34 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-expression.vala b/src/libtracker-data/tracker-sparql-expression.vala
index c1682b3..55c73d9 100644
--- a/src/libtracker-data/tracker-sparql-expression.vala
+++ b/src/libtracker-data/tracker-sparql-expression.vala
@@ -122,38 +122,7 @@ class Tracker.Sparql.Expression : Object {
long begin = sql.len;
var type = PropertyType.UNKNOWN;
- if (accept (SparqlTokenType.COUNT)) {
- sql.append ("COUNT(");
- translate_aggregate_expression (sql);
- sql.append (")");
- type = PropertyType.INTEGER;
- } else if (accept (SparqlTokenType.SUM)) {
- sql.append ("SUM(");
- type = translate_aggregate_expression (sql);
- sql.append (")");
- } else if (accept (SparqlTokenType.AVG)) {
- sql.append ("AVG(");
- type = translate_aggregate_expression (sql);
- sql.append (")");
- } else if (accept (SparqlTokenType.MIN)) {
- sql.append ("MIN(");
- type = translate_aggregate_expression (sql);
- sql.append (")");
- } else if (accept (SparqlTokenType.MAX)) {
- sql.append ("MAX(");
- type = translate_aggregate_expression (sql);
- sql.append (")");
- } else if (accept (SparqlTokenType.GROUP_CONCAT)) {
- sql.append ("GROUP_CONCAT(");
- expect (SparqlTokenType.OPEN_PARENS);
- translate_expression_as_string (sql);
- sql.append (", ");
- expect (SparqlTokenType.COMMA);
- sql.append (escape_sql_string_literal (parse_string_literal ()));
- sql.append (")");
- expect (SparqlTokenType.CLOSE_PARENS);
- type = PropertyType.STRING;
- } else if (current () == SparqlTokenType.VAR) {
+ if (current () == SparqlTokenType.VAR) {
type = translate_expression (sql);
// we need variable name in case of compositional subqueries
variable = context.get_variable (get_last_string ().substring (1));
@@ -818,6 +787,8 @@ class Tracker.Sparql.Expression : Object {
}
PropertyType translate_primary_expression (StringBuilder sql) throws SparqlError {
+ PropertyType type;
+
switch (current ()) {
case SparqlTokenType.OPEN_PARENS:
return translate_bracketted_expression (sql);
@@ -861,8 +832,6 @@ class Tracker.Sparql.Expression : Object {
case SparqlTokenType.STRING_LITERAL2:
case SparqlTokenType.STRING_LITERAL_LONG1:
case SparqlTokenType.STRING_LITERAL_LONG2:
- PropertyType type;
-
var binding = new LiteralBinding ();
binding.literal = parse_string_literal (out type);
query.bindings.append (binding);
@@ -944,6 +913,47 @@ class Tracker.Sparql.Expression : Object {
case SparqlTokenType.REGEX:
translate_regex (sql);
return PropertyType.BOOLEAN;
+ case SparqlTokenType.COUNT:
+ next ();
+ sql.append ("COUNT(");
+ translate_aggregate_expression (sql);
+ sql.append (")");
+ return PropertyType.INTEGER;
+ case SparqlTokenType.SUM:
+ next ();
+ sql.append ("SUM(");
+ type = translate_aggregate_expression (sql);
+ sql.append (")");
+ return type;
+ case SparqlTokenType.AVG:
+ next ();
+ sql.append ("AVG(");
+ type = translate_aggregate_expression (sql);
+ sql.append (")");
+ return type;
+ case SparqlTokenType.MIN:
+ next ();
+ sql.append ("MIN(");
+ type = translate_aggregate_expression (sql);
+ sql.append (")");
+ return type;
+ case SparqlTokenType.MAX:
+ next ();
+ sql.append ("MAX(");
+ type = translate_aggregate_expression (sql);
+ sql.append (")");
+ return type;
+ case SparqlTokenType.GROUP_CONCAT:
+ next ();
+ sql.append ("GROUP_CONCAT(");
+ expect (SparqlTokenType.OPEN_PARENS);
+ translate_expression_as_string (sql);
+ sql.append (", ");
+ expect (SparqlTokenType.COMMA);
+ sql.append (escape_sql_string_literal (parse_string_literal ()));
+ sql.append (")");
+ expect (SparqlTokenType.CLOSE_PARENS);
+ return PropertyType.STRING;
case SparqlTokenType.PN_PREFIX:
next ();
string ns = get_last_string ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]