[tracker/wip/carlosg/sparql1.1: 62/113] libtracker-data: Handle predicate paths properly both in and out of graph{}
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/sparql1.1: 62/113] libtracker-data: Handle predicate paths properly both in and out of graph{}
- Date: Sun, 21 Jul 2019 14:34:26 +0000 (UTC)
commit a5d176b7d973755c7550ffa6c459850b2821ced9
Author: Carlos Garnacho <carlosg gnome org>
Date: Tue Jul 2 15:01:27 2019 +0200
libtracker-data: Handle predicate paths properly both in and out of graph{}
We need to check the unionGraph* views in the graphless case, or the specific
database in the "graph {}" one.
src/libtracker-data/tracker-sparql-types.c | 7 ++++++
src/libtracker-data/tracker-sparql-types.h | 3 +++
src/libtracker-data/tracker-sparql.c | 39 +++++++++++++++++++++++++++---
3 files changed, 45 insertions(+), 4 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-types.c b/src/libtracker-data/tracker-sparql-types.c
index d1b92a980..254523238 100644
--- a/src/libtracker-data/tracker-sparql-types.c
+++ b/src/libtracker-data/tracker-sparql-types.c
@@ -62,6 +62,13 @@ tracker_data_table_set_predicate_variable (TrackerDataTable *table,
table->predicate_variable = is_variable;
}
+void
+tracker_data_table_set_predicate_path (TrackerDataTable *table,
+ gboolean is_path)
+{
+ table->predicate_path = is_path;
+}
+
static TrackerVariable *
tracker_variable_new (const gchar *sql_prefix,
const gchar *name)
diff --git a/src/libtracker-data/tracker-sparql-types.h b/src/libtracker-data/tracker-sparql-types.h
index c68f5f722..2580f6cdd 100644
--- a/src/libtracker-data/tracker-sparql-types.h
+++ b/src/libtracker-data/tracker-sparql-types.h
@@ -77,6 +77,7 @@ struct _TrackerDataTable {
gchar *sql_db_tablename; /* as in db schema */
gchar *sql_query_tablename; /* temp. name, generated */
gboolean predicate_variable;
+ gboolean predicate_path;
};
struct _TrackerBinding {
@@ -239,6 +240,8 @@ struct _TrackerTripleContextClass {
/* Data table */
void tracker_data_table_set_predicate_variable (TrackerDataTable *table,
gboolean is_variable);
+void tracker_data_table_set_predicate_path (TrackerDataTable *table,
+ gboolean is_path);
/* Binding */
GType tracker_binding_get_type (void) G_GNUC_CONST;
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index 0689f81e9..bfc4fe300 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -556,6 +556,7 @@ _prepend_path_element (TrackerSparql *sparql,
TrackerPathElement *path_elem)
{
TrackerStringBuilder *old;
+ gchar *table_name, *graph_column;
old = tracker_sparql_swap_builder (sparql, sparql->current_state.with_clauses);
@@ -567,13 +568,29 @@ _prepend_path_element (TrackerSparql *sparql,
switch (path_elem->op) {
case TRACKER_PATH_OPERATOR_NONE:
/* A simple property */
+ if (tracker_token_is_empty (&sparql->current_state.graph)) {
+ table_name = g_strdup_printf ("\"unionGraph_%s\"",
+ tracker_property_get_table_name
(path_elem->data.property));
+ graph_column = g_strdup ("graph");
+ } else {
+ const gchar *graph;
+
+ graph = tracker_token_get_idstring (&sparql->current_state.graph);
+ table_name = g_strdup_printf ("\"%s\".\"%s\"", graph,
+ tracker_property_get_table_name
(path_elem->data.property));
+ graph_column = g_strdup_printf ("%d",
+ tracker_data_manager_find_graph
(sparql->data_manager, graph));
+ }
+
_append_string_printf (sparql,
"\"%s\" (ID, value, graph) AS "
- "(SELECT ID, \"%s\", \"%s:graph\" FROM \"%s\") ",
+ "(SELECT ID, \"%s\", %s FROM %s) ",
path_elem->name,
tracker_property_get_name (path_elem->data.property),
- tracker_property_get_name (path_elem->data.property),
- tracker_property_get_table_name (path_elem->data.property));
+ graph_column);
+ table_name);
+ g_free (table_name);
+ g_free (graph_column);
break;
case TRACKER_PATH_OPERATOR_INVERSE:
_append_string_printf (sparql,
@@ -649,9 +666,20 @@ _prepend_path_element (TrackerSparql *sparql,
"\"%s\" (ID, value, graph) AS "
"(SELECT subject AS ID, object AS value, graph "
"FROM \"tracker_triples\" "
- "WHERE predicate != %d",
+ "WHERE predicate != %d ",
path_elem->name,
tracker_property_get_id (path_elem->data.property));
+
+ if (!tracker_token_is_empty (&sparql->current_state.graph)) {
+ const gchar *graph;
+
+ graph = tracker_token_get_idstring (&sparql->current_state.graph);
+ _append_string_printf (sparql,
+ "AND graph = %d",
+ tracker_data_manager_find_graph (sparql->data_manager, graph));
+ }
+
+ _append_string (sparql, ") ");
break;
case TRACKER_PATH_OPERATOR_INTERSECTION:
_append_string_printf (sparql,
@@ -1215,6 +1243,7 @@ _add_quad (TrackerSparql *sparql,
table = tracker_triple_context_add_table (triple_context,
graph_db,
tracker_token_get_idstring (predicate));
+ tracker_data_table_set_predicate_path (table, TRUE);
new_table = TRUE;
} else {
/* The parser disallows parameter predicates */
@@ -1605,6 +1634,8 @@ _end_triples_block (TrackerSparql *sparql,
_append_string (sparql,
"(SELECT subject AS ID, predicate, "
"object, graph FROM tracker_triples) ");
+ } else if (table->predicate_path) {
+ _append_string_printf (sparql, "\"%s\"", table->sql_db_tablename);
} else {
if (table->graph) {
_append_string_printf (sparql, "\"%s\".\"%s\"",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]