[tracker/wip/carlosg/fix-minus] libtracker-data: Fix MINUS support
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/fix-minus] libtracker-data: Fix MINUS support
- Date: Fri, 6 Mar 2020 19:12:26 +0000 (UTC)
commit 2d66ff08f26baaff79791c0e04dbff71459e8bca
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Mar 6 19:59:41 2020 +0100
libtracker-data: Fix MINUS support
We implement MINUS through sqlite's EXCEPT, which requires SELECTS on
both sides of the operation to have the same variables in the same
order. Ensure this is what happens.
One thing to note is that we do not bother checking whether new
variables are created on the right hand, as per MINUS semantics those
cannot count in the result set.
Closes: https://gitlab.gnome.org/GNOME/tracker/issues/190
src/libtracker-data/tracker-sparql.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
---
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index bcdcd52e7..9a688a6bc 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -5009,12 +5009,32 @@ static gboolean
translate_MinusGraphPattern (TrackerSparql *sparql,
GError **error)
{
+ TrackerStringBuilder *str, *cur;
+ TrackerContext *context;
+ GList *vars;
+
+ context = sparql->current_state.context;
+ vars = g_hash_table_get_keys (context->variable_set);
+
/* MinusGraphPattern ::= 'MINUS' GroupGraphPattern
*/
+
+ /* We are required to have the same variables in the same
+ * order on both sides of EXCEPT. Wrap the query (so far)
+ * with SELECT ... FROM () so we ensure this happens.
+ */
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_MINUS);
- _prepend_string (sparql, "SELECT * FROM (");
+ str = _prepend_placeholder (sparql);
+ cur = tracker_sparql_swap_builder (sparql, str);
+ append_subquery_select_vars (sparql, context, vars);
+ tracker_sparql_swap_builder (sparql, cur);
+
_append_string (sparql, ") EXCEPT ");
+ append_subquery_select_vars (sparql, context, vars);
+ g_list_free (vars);
+
_call_rule (sparql, NAMED_RULE_GroupGraphPattern, error);
+ _append_string (sparql, ")");
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]