[tracker/subqueries-for-master: 14/14] SPARQL: Only export selected variables from subqueries
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/subqueries-for-master: 14/14] SPARQL: Only export selected variables from subqueries
- Date: Wed, 9 Dec 2009 14:42:24 +0000 (UTC)
commit 30eabf1540ccbf91aab3bd5eb77f4167118e87c4
Author: Jürg Billeter <j bitron ch>
Date: Wed Dec 9 14:57:53 2009 +0100
SPARQL: Only export selected variables from subqueries
src/libtracker-data/tracker-sparql-query.vala | 24 +++++++++++++++++++++---
1 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index be34b1e..95de18f 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -272,6 +272,8 @@ public class Tracker.SparqlQuery : Object {
// All SPARQL variables within a subgraph pattern (used by UNION)
HashTable<Variable,int> subgraph_var_set;
+ // All selected SPARQL variables (used by compositional subqueries)
+ HashTable<Variable,int> select_var_set;
// Variables used as predicates
HashTable<Variable,PredicateVariable> predicate_variable_map;
@@ -292,6 +294,7 @@ public class Tracker.SparqlQuery : Object {
tokens = new TokenInfo[BUFFER_SIZE];
prefix_map = new HashTable<string,string>.full (str_hash, str_equal, g_free, g_free);
subgraph_var_set = new HashTable<Variable,int>.full (direct_hash, direct_equal, g_object_unref, null);
+ select_var_set = new HashTable<Variable,int>.full (direct_hash, direct_equal, g_object_unref, null);
base_uuid = new uchar[16];
uuid_generate (base_uuid);
@@ -613,6 +616,8 @@ public class Tracker.SparqlQuery : Object {
}
void translate_select_expression (StringBuilder sql, bool subquery) throws SparqlError {
+ string variable_name = null;
+
long begin = sql.len;
var type = PropertyType.UNKNOWN;
if (accept (SparqlTokenType.COUNT)) {
@@ -646,6 +651,10 @@ public class Tracker.SparqlQuery : Object {
sql.append (")");
expect (SparqlTokenType.CLOSE_PARENS);
type = PropertyType.STRING;
+ } else if (current () == SparqlTokenType.VAR) {
+ type = translate_expression (sql);
+ // we need variable name in case of compositional subqueries
+ variable_name = get_last_string ().substring (1);
} else {
type = translate_expression (sql);
}
@@ -655,7 +664,6 @@ public class Tracker.SparqlQuery : Object {
}
if (accept (SparqlTokenType.AS)) {
- string variable_name;
if (accept (SparqlTokenType.PN_PREFIX)) {
// deprecated but supported for backward compatibility
// (...) AS foo
@@ -668,6 +676,14 @@ public class Tracker.SparqlQuery : Object {
}
sql.append_printf (" AS %s", get_variable (variable_name).sql_expression);
}
+
+ if (variable_name != null) {
+ int state = subgraph_var_set.lookup (get_variable (variable_name));
+ if (state == 0) {
+ state = VariableState.BOUND;
+ }
+ select_var_set.insert (get_variable (variable_name), state);
+ }
}
void begin_query () {
@@ -2285,10 +2301,12 @@ public class Tracker.SparqlQuery : Object {
expect (SparqlTokenType.OPEN_BRACE);
if (current () == SparqlTokenType.SELECT) {
- // FIXME ensure that inner variables are only exported if selected
-
translate_select (sql, true);
+ // only export selected variables
+ subgraph_var_set = select_var_set;
+ select_var_set = select_var_set = new HashTable<Variable,int>.full (direct_hash, direct_equal, g_object_unref, null);
+
expect (SparqlTokenType.CLOSE_BRACE);
return;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]