[tracker/wip/carlosg/portal: 10/36] libtracker-data: Implement DEFAULT/ALL in CONSTRAINT declaration
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/portal: 10/36] libtracker-data: Implement DEFAULT/ALL in CONSTRAINT declaration
- Date: Fri, 17 Jul 2020 11:42:00 +0000 (UTC)
commit 643866ef8e86437caad275a2fad9214d6d6f78f0
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Jan 24 12:14:59 2020 +0100
libtracker-data: Implement DEFAULT/ALL in CONSTRAINT declaration
Make it easy to include all graphs (no constraints as per this clause)
or the default unnamed graph (as it's otherwise non referenceable here).
src/libtracker-data/tracker-sparql-grammar.h | 7 +++--
src/libtracker-data/tracker-sparql.c | 42 +++++++++++++++++++++-------
2 files changed, 36 insertions(+), 13 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-grammar.h b/src/libtracker-data/tracker-sparql-grammar.h
index 1073d2fdd..b659abde5 100644
--- a/src/libtracker-data/tracker-sparql-grammar.h
+++ b/src/libtracker-data/tracker-sparql-grammar.h
@@ -1509,14 +1509,15 @@ static const TrackerGrammarRule rule_SelectQuery[] = { R(SelectClause), GTE0(hel
*/
static const TrackerGrammarRule rule_PrefixDecl[] = { L(PREFIX), T(PNAME_NS), T(IRIREF), NIL };
-/* ConstraintDecl ::= 'CONSTRAINT' ( 'GRAPH' | 'SERVICE' ) ( IRIREF (',' IRIREF)* )?
+/* ConstraintDecl ::= 'CONSTRAINT' ( 'GRAPH' | 'SERVICE' ) ( ( IRIREF | 'DEFAULT' | 'ALL' ) ( ',' ( IRIREF |
'DEFAULT' | 'ALL' ) )* )?
*
* TRACKER EXTENSION
*/
static const TrackerGrammarRule helper_ConstraintDecl_or_1[] = { L(GRAPH), L(SERVICE), NIL };
-static const TrackerGrammarRule helper_ConstraintDecl_seq_1[] = { L(COMMA), T(IRIREF), NIL };
+static const TrackerGrammarRule helper_ConstraintDecl_or_2[] = { T(IRIREF), L(DEFAULT), L(ALL), NIL };
+static const TrackerGrammarRule helper_ConstraintDecl_seq_1[] = { L(COMMA), OR(helper_ConstraintDecl_or_2),
NIL };
static const TrackerGrammarRule helper_ConstraintDecl_gte0_1[] = { S(helper_ConstraintDecl_seq_1), NIL };
-static const TrackerGrammarRule helper_ConstraintDecl_opt_1[] = { T(IRIREF),
GTE0(helper_ConstraintDecl_gte0_1), NIL };
+static const TrackerGrammarRule helper_ConstraintDecl_opt_1[] = { OR(helper_ConstraintDecl_or_2),
GTE0(helper_ConstraintDecl_gte0_1), NIL };
static const TrackerGrammarRule rule_ConstraintDecl[] = { L(CONSTRAINT), OR(helper_ConstraintDecl_or_1),
OPT(helper_ConstraintDecl_opt_1), NIL };
/* BaseDecl ::= 'BASE' IRIREF
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index 5ea8770c7..f807d5c70 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -148,6 +148,7 @@ struct _TrackerSparql
GPtrArray *graphs;
GPtrArray *services;
GHashTable *filtered_graphs;
+ gboolean filter_unnamed_graph;
} policy;
struct {
@@ -705,7 +706,7 @@ _append_union_graph_with_clause (TrackerSparql *sparql,
_append_string_printf (sparql, "\"unionGraph_%s\"(ID, %s graph) AS (",
table_name, properties);
- if (g_hash_table_size (graphs) > 0) {
+ if (!sparql->policy.filter_unnamed_graph) {
_append_string_printf (sparql,
"SELECT ID, %s 0 AS graph FROM \"main\".\"%s\" ",
properties, table_name);
@@ -2781,8 +2782,10 @@ translate_ConstraintDecl (TrackerSparql *sparql,
GError **error)
{
GPtrArray **previous_set, *set;
+ gboolean graph = FALSE;
+ gboolean filter_unnamed_graph = TRUE;
- /* ConstraintDecl ::= 'CONSTRAINT' ( 'GRAPH' | 'SERVICE' ) ( IRIREF (',' IRIREF)* )?
+ /* ConstraintDecl ::= 'CONSTRAINT' ( 'GRAPH' | 'SERVICE' ) ( ( IRIREF | 'DEFAULT' | 'ALL' ) ( ',' (
IRIREF | 'DEFAULT' | 'ALL' ) )* )?
*
* TRACKER EXTENSION
*/
@@ -2790,6 +2793,7 @@ translate_ConstraintDecl (TrackerSparql *sparql,
if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_GRAPH)) {
previous_set = &sparql->policy.graphs;
+ graph = TRUE;
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_SERVICE)) {
previous_set = &sparql->policy.services;
} else {
@@ -2798,23 +2802,41 @@ translate_ConstraintDecl (TrackerSparql *sparql,
set = g_ptr_array_new_with_free_func (g_free);
- while (_accept (sparql, RULE_TYPE_TERMINAL, TERMINAL_TYPE_IRIREF)) {
+ do {
gchar *elem;
- elem = _dup_last_string (sparql);
- g_ptr_array_add (set, elem);
-
- if (!_accept (sparql, RULE_TYPE_LITERAL, LITERAL_COMMA))
+ if (_accept (sparql, RULE_TYPE_TERMINAL, TERMINAL_TYPE_IRIREF)) {
+ if (set) {
+ elem = _dup_last_string (sparql);
+ g_ptr_array_add (set, elem);
+ }
+ } else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_DEFAULT)) {
+ if (graph)
+ filter_unnamed_graph = FALSE;
+ } else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_ALL)) {
+ if (graph)
+ filter_unnamed_graph = FALSE;
+ g_clear_pointer (&set, g_ptr_array_unref);
+ } else {
break;
- }
+ }
+ } while (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_COMMA));
if (*previous_set) {
- intersect_set (*previous_set, set);
- g_ptr_array_unref (set);
+ if (set) {
+ intersect_set (*previous_set, set);
+ g_ptr_array_unref (set);
+ }
} else {
*previous_set = set;
}
+ if (graph) {
+ sparql->policy.filter_unnamed_graph |= filter_unnamed_graph;
+ g_clear_pointer (&sparql->policy.filtered_graphs,
+ g_hash_table_unref);
+ }
+
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]