[tracker/wip/carlosg/sparql-parser-ng: 33/56] libtracker-data: Accept comma as GROUP_CONCAT separator
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/sparql-parser-ng: 33/56] libtracker-data: Accept comma as GROUP_CONCAT separator
- Date: Tue, 13 Nov 2018 10:22:39 +0000 (UTC)
commit 8828814cdc08dbb7c31746e59dc13d2f3cd249cc
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Sep 22 22:39:06 2018 +0200
libtracker-data: Accept comma as GROUP_CONCAT separator
This is a tracker extension present in previous SPARQL parser.
src/libtracker-data/tracker-sparql-grammar.h | 9 ++++++++-
src/libtracker-data/tracker-sparql.c | 26 +++++++++++++++++++++++++-
2 files changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-grammar.h b/src/libtracker-data/tracker-sparql-grammar.h
index 88592d106..c74eb4401 100644
--- a/src/libtracker-data/tracker-sparql-grammar.h
+++ b/src/libtracker-data/tracker-sparql-grammar.h
@@ -589,6 +589,11 @@ static const TrackerGrammarRule rule_RDFLiteral[] = { R(String), OPT(helper_RDFL
* | 'AVG' '(' 'DISTINCT'? Expression ')'
* | 'SAMPLE' '(' 'DISTINCT'? Expression ')'
* | 'GROUP_CONCAT' '(' 'DISTINCT'? Expression ( ';' 'SEPARATOR' '=' String )? ')'
+ *
+ * TRACKER EXTENSION:
+ *
+ * GROUP_CONCAT accepts a comma separator, so effectively:
+ * 'GROUP_CONCAT' '(' 'DISTINCT'? Expression ( ( ';' 'SEPARATOR' '=' | ',') String )? ')'
*/
static const TrackerGrammarRule helper_Aggregate_opt_1[] = { L(DISTINCT), NIL };
static const TrackerGrammarRule helper_Aggregate_or_1[] = { L(GLOB), R(Expression), NIL };
@@ -598,7 +603,9 @@ static const TrackerGrammarRule helper_Aggregate_seq_3[] = { L(MIN), L(OPEN_PARE
static const TrackerGrammarRule helper_Aggregate_seq_4[] = { L(MAX), L(OPEN_PARENS),
OPT(helper_Aggregate_opt_1), R(Expression), L(CLOSE_PARENS), NIL };
static const TrackerGrammarRule helper_Aggregate_seq_5[] = { L(AVG), L(OPEN_PARENS),
OPT(helper_Aggregate_opt_1), R(Expression), L(CLOSE_PARENS), NIL };
static const TrackerGrammarRule helper_Aggregate_seq_6[] = { L(SAMPLE), L(OPEN_PARENS),
OPT(helper_Aggregate_opt_1), R(Expression), L(CLOSE_PARENS), NIL };
-static const TrackerGrammarRule helper_Aggregate_seq_in_opt[] = { L(SEMICOLON), L(SEPARATOR), L(OP_EQ),
R(String), NIL };
+static const TrackerGrammarRule helper_Aggregate_seq_8[] = { L(SEMICOLON), L(SEPARATOR), L(OP_EQ), NIL };
+static const TrackerGrammarRule helper_Aggregate_or_3[] = { S(helper_Aggregate_seq_8), L(COMMA), NIL };
+static const TrackerGrammarRule helper_Aggregate_seq_in_opt[] = { OR(helper_Aggregate_or_3), R(String), NIL
};
static const TrackerGrammarRule helper_Aggregate_opt_2[] = { S(helper_Aggregate_seq_in_opt), NIL };
static const TrackerGrammarRule helper_Aggregate_seq_7[] = { L(GROUP_CONCAT), L(OPEN_PARENS),
OPT(helper_Aggregate_opt_1), R(Expression), OPT(helper_Aggregate_opt_2), L(CLOSE_PARENS), NIL };
static const TrackerGrammarRule helper_Aggregate_or_2[] = { S(helper_Aggregate_seq_1),
S(helper_Aggregate_seq_2), S(helper_Aggregate_seq_3), S(helper_Aggregate_seq_4), S(helper_Aggregate_seq_5),
S(helper_Aggregate_seq_6), S(helper_Aggregate_seq_7), NIL };
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index 72a601b95..34c2188a7 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -5678,20 +5678,44 @@ translate_Aggregate (TrackerSparql *sparql,
sparql->current_state.expression_type = TRACKER_PROPERTY_TYPE_INTEGER;
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_GROUP_CONCAT)) {
+ TrackerStringBuilder *str, *old;
+ gboolean separator = FALSE;
+
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
_append_string (sparql, "GROUP_CONCAT(");
if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_DISTINCT))
_append_string (sparql, "DISTINCT ");
+ str = _append_placeholder (sparql);
+ old = tracker_sparql_swap_builder (sparql, str);
+
_call_rule (sparql, NAMED_RULE_Expression, error);
+ if (sparql->current_state.expression_type == TRACKER_PROPERTY_TYPE_RESOURCE)
+ convert_expression_to_string (sparql, sparql->current_state.expression_type);
+
+ tracker_sparql_swap_builder (sparql, old);
+
if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_SEMICOLON)) {
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_SEPARATOR);
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_OP_EQ);
- _append_string (sparql, ", ");
+ separator = TRUE;
+ } else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_COMMA)) {
+ separator = TRUE;
+ }
+
+ if (separator) {
+ TrackerBinding *binding;
+ _append_string (sparql, ", ");
_call_rule (sparql, NAMED_RULE_String, error);
+
+ binding = _convert_terminal (sparql);
+ tracker_select_context_add_literal_binding (TRACKER_SELECT_CONTEXT (sparql->context),
+ TRACKER_LITERAL_BINDING (binding));
+ _append_literal_sql (sparql, TRACKER_LITERAL_BINDING (binding));
+ g_object_unref (binding);
}
_expect (sparql, RULE_TYPE_LITERAL, LITERAL_CLOSE_PARENS);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]