[tracker/wip/garnacho/sparql1.1: 18/23] libtracker-data: Add support for YEAR/.../SECONDS builtin functions



commit f5a09f2db0d5b3e2fd869299750a953eb9fb4b97
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jul 29 23:26:02 2015 +0200

    libtracker-data: Add support for YEAR/.../SECONDS builtin functions
    
    These functions are defined in Sparql 1.1 query language recommendation,
    http://www.w3.org/TR/sparql11-query/#func-year
    http://www.w3.org/TR/sparql11-query/#func-month
    http://www.w3.org/TR/sparql11-query/#func-day
    http://www.w3.org/TR/sparql11-query/#func-hours
    http://www.w3.org/TR/sparql11-query/#func-minutes
    http://www.w3.org/TR/sparql11-query/#func-seconds

 src/libtracker-data/tracker-sparql-expression.vala |   36 ++++++++++++++++
 src/libtracker-data/tracker-sparql-scanner.vala    |   45 +++++++++++++++++++-
 2 files changed, 79 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-expression.vala 
b/src/libtracker-data/tracker-sparql-expression.vala
index 2da4b1f..a645802 100644
--- a/src/libtracker-data/tracker-sparql-expression.vala
+++ b/src/libtracker-data/tracker-sparql-expression.vala
@@ -1352,6 +1352,42 @@ class Tracker.Sparql.Expression : Object {
                        expect (SparqlTokenType.CLOSE_PARENS);
                        sql.append ("strftime('%s', 'now')");
                        return PropertyType.DATETIME;
+               case SparqlTokenType.SECONDS:
+                       next ();
+                       expect (SparqlTokenType.OPEN_PARENS);
+                       var result = translate_function (sql, FN_NS + "seconds-from-dateTime");
+                       expect (SparqlTokenType.CLOSE_PARENS);
+                       return result;
+               case SparqlTokenType.MINUTES:
+                       next ();
+                       expect (SparqlTokenType.OPEN_PARENS);
+                       var result = translate_function (sql, FN_NS + "minutes-from-dateTime");
+                       expect (SparqlTokenType.CLOSE_PARENS);
+                       return result;
+               case SparqlTokenType.HOURS:
+                       next ();
+                       expect (SparqlTokenType.OPEN_PARENS);
+                       var result = translate_function (sql, FN_NS + "hours-from-dateTime");
+                       expect (SparqlTokenType.CLOSE_PARENS);
+                       return result;
+               case SparqlTokenType.DAY:
+                       next ();
+                       expect (SparqlTokenType.OPEN_PARENS);
+                       var result = translate_function (sql, FN_NS + "day-from-dateTime");
+                       expect (SparqlTokenType.CLOSE_PARENS);
+                       return result;
+               case SparqlTokenType.MONTH:
+                       next ();
+                       expect (SparqlTokenType.OPEN_PARENS);
+                       var result = translate_function (sql, FN_NS + "month-from-dateTime");
+                       expect (SparqlTokenType.CLOSE_PARENS);
+                       return result;
+               case SparqlTokenType.YEAR:
+                       next ();
+                       expect (SparqlTokenType.OPEN_PARENS);
+                       var result = translate_function (sql, FN_NS + "year-from-dateTime");
+                       expect (SparqlTokenType.CLOSE_PARENS);
+                       return result;
                case SparqlTokenType.GROUP_CONCAT:
                        next ();
                        sql.append ("GROUP_CONCAT(");
diff --git a/src/libtracker-data/tracker-sparql-scanner.vala b/src/libtracker-data/tracker-sparql-scanner.vala
index 0e73fba..3a1c126 100644
--- a/src/libtracker-data/tracker-sparql-scanner.vala
+++ b/src/libtracker-data/tracker-sparql-scanner.vala
@@ -106,6 +106,10 @@ public class Tracker.SparqlScanner : Object {
                                        break;
                                }
                                break;
+                       case 'D':
+                       case 'd':
+                               if (matches (begin, "DAY")) return SparqlTokenType.DAY;
+                               break;
                        case 'M':
                        case 'm':
                                switch (begin[1]) {
@@ -202,6 +206,10 @@ public class Tracker.SparqlScanner : Object {
                        case 'w':
                                if (matches (begin, "WITH")) return SparqlTokenType.WITH;
                                break;
+                       case 'Y':
+                       case 'y':
+                               if (matches (begin, "YEAR")) return SparqlTokenType.YEAR;
+                               break;
                        }
                        break;
                case 5:
@@ -227,6 +235,10 @@ public class Tracker.SparqlScanner : Object {
                                        break;
                                }
                                break;
+                       case 'H':
+                       case 'h':
+                               if (matches (begin, "HOURS")) return SparqlTokenType.HOURS;
+                               break;
                        case 'L':
                        case 'l':
                                switch (begin[1]) {
@@ -240,6 +252,10 @@ public class Tracker.SparqlScanner : Object {
                                        break;
                                }
                                break;
+                       case 'M':
+                       case 'm':
+                               if (matches (begin, "MONTH")) return SparqlTokenType.MONTH;
+                               break;
                        case 'N':
                        case 'n':
                                if (matches (begin, "NAMED")) return SparqlTokenType.NAMED;
@@ -370,6 +386,10 @@ public class Tracker.SparqlScanner : Object {
                        break;
                case 7:
                        switch (begin[0]) {
+                       case 'M':
+                       case 'm':
+                               if (matches (begin, "MINUTES")) return SparqlTokenType.MINUTES;
+                               break;
                        case 'R':
                        case 'r':
                                switch (begin[2]) {
@@ -385,7 +405,16 @@ public class Tracker.SparqlScanner : Object {
                                break;
                        case 'S':
                        case 's':
-                               if (matches (begin, "STRENDS")) return SparqlTokenType.STRENDS;
+                               switch (begin[1]) {
+                               case 'E':
+                               case 'e':
+                                       if (matches (begin, "SECONDS")) return SparqlTokenType.SECONDS;
+                                       break;
+                               case 'T':
+                               case 't':
+                                       if (matches (begin, "STRENDS")) return SparqlTokenType.STRENDS;
+                                       break;
+                               }
                                break;
                        case 'I':
                        case 'i':
@@ -988,6 +1017,7 @@ public enum Tracker.SparqlTokenType {
        COUNT,
        DATA,
        DATATYPE,
+       DAY,
        DECIMAL,
        DELETE,
        DESC,
@@ -1009,6 +1039,7 @@ public enum Tracker.SparqlTokenType {
        GROUP,
        GROUP_CONCAT,
        HAVING,
+       HOURS,
        IF,
        INSERT,
        INTEGER,
@@ -1025,6 +1056,8 @@ public enum Tracker.SparqlTokenType {
        MAX,
        MIN,
        MINUS,
+       MINUTES,
+       MONTH,
        NAMED,
        NOT,
        NOW,
@@ -1055,6 +1088,7 @@ public enum Tracker.SparqlTokenType {
        REPLACE,
        ROUND,
        SAMETERM,
+       SECONDS,
        SELECT,
        SEMICOLON,
        SILENT,
@@ -1076,7 +1110,8 @@ public enum Tracker.SparqlTokenType {
        UNION,
        VAR,
        WHERE,
-       WITH;
+       WITH,
+       YEAR;
 
        public unowned string to_string () {
                switch (this) {
@@ -1104,6 +1139,7 @@ public enum Tracker.SparqlTokenType {
                case CONSTRUCT: return "`CONSTRUCT'";
                case COUNT: return "`COUNT'";
                case DATATYPE: return "`DATATYPE'";
+               case DAY: return "`DAY'";
                case DECIMAL: return "`DECIMAL'";
                case DELETE: return "`DELETE'";
                case DESC: return "`DESC'";
@@ -1123,6 +1159,7 @@ public enum Tracker.SparqlTokenType {
                case GROUP: return "`GROUP'";
                case GROUP_CONCAT: return "`GROUP_CONCAT'";
                case HAVING: return "`HAVING'";
+               case HOURS: return "`HOURS'";
                case IF: return "`IF'";
                case INSERT: return "`INSERT'";
                case INTEGER: return "`INTEGER'";
@@ -1139,6 +1176,8 @@ public enum Tracker.SparqlTokenType {
                case MAX: return "`MAX'";
                case MIN: return "`MIN'";
                case MINUS: return "`-'";
+               case MINUTES: return "`MINUTES'";
+               case MONTH: return "`MONTH'";
                case NAMED: return "`NAMED'";
                case NOT: return "`NOT'";
                case NOW: return "`NOW'";
@@ -1168,6 +1207,7 @@ public enum Tracker.SparqlTokenType {
                case REPLACE: return "`REPLACE'";
                case ROUND: return "`ROUND'";
                case SAMETERM: return "`SAMETERM'";
+               case SECONDS: return "`SECONDS'";
                case SELECT: return "`SELECT'";
                case SEMICOLON: return "`;'";
                case SILENT: return "`SILENT'";
@@ -1190,6 +1230,7 @@ public enum Tracker.SparqlTokenType {
                case VAR: return "variable";
                case WHERE: return "`WHERE'";
                case WITH: return "`WITH'";
+               case YEAR: return "`YEAR'";
                default: return "unknown token";
                }
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]