Olemis Lang avatar Olemis Lang committed b244f16

GViz QL: Binary string matching operators

Comments (0)

Files changed (2)

trac-dev/gviz/tracgviz/gvizql.py

   """
   GVIZ_QL_KEYWS = [k for ct in GVizQLClauseType.iterparse() \
                         for k in ct.KEYWORDS]
-  GVIZ_QL_OPS = 'and or is not'.split()
+  GVIZ_QL_OPS = 'and,or,is,not,contains,starts with,ends with,matches,' \
+        'like'.split(',')
   GVIZ_QL_FUNCS = 'max min count avg sum'.split()
   GVIZ_QL_CPREF = 'date datetime timeofday timestamp'.split()
   GVIZ_QL_CONST = 'true false null'.split()
                             extraglobs=dict(parse=parse),
                             optionflags=ELLIPSIS \
                                         | NORMALIZE_WHITESPACE \
-#                                        | REPORT_UDIFF \
+                                        | REPORT_UDIFF \
                           )])
   return l.loadTestsFromModule(sys.modules[__name__])
 

trac-dev/gviz/tracgviz/testing/test_gvizql.py

       ...           for a in ['KEYWS', 'OPS', 'FUNCS', 'CONST', 'CPREF'])
       ...
       >>> kwds = sum(kwds, [])
-      >>> print ' '.join(sorted(set(kwds)))
+      >>> print ' '.join('(%s)' % k for k in sorted(set(kwds)))
       ...                             #doctest: +NORMALIZE_WHITESPACE 
       ... 
-      and asc avg by count date datetime desc false 
-      format from group is label limit max min not null 
-      offset options or order pivot select sum timeofday 
-      timestamp true where
+      (and) (asc) (avg) (by) (contains) (count) (date) (datetime) (desc) 
+      (ends with) (false) (format) (from) (group) (is) (label) (like) (limit) 
+      (matches) (max) (min) (not) (null) (offset) (options) (or) (order) 
+      (pivot) (select) (starts with) (sum) (timeofday) (timestamp) (true)
+      (where)
       """,
   'Parsing SELECT (simple)' : r"""
       >>> parse("  select *  ", 'cols')
          age = 24
          isSenior = True
          seniorityStartTime = 2007-12-30 14:40:00
-      
+
       >>> parse("  select `group`, selectme ", 'cols')
       *****
       * Tokens
       * Result
       *****
       GVizInvalidQuery  :  Unable to evaluate SELECT clause. Unknown column group.
-      
+
       >>> parse("select dept, salary  ", 'cols')
       *****
       * Tokens
       = Row =
          dept = Marketing
          salary = 800
-      
+
       >>> parse("select `email address`, name, `date`", 'cols')
       *****
       * Tokens
       * Result
       *****
       GVizInvalidQuery  :  Unable to evaluate SELECT clause. Unknown column email address.
-      
+
       >>> parse("select lunchTime , name", 'cols')
       *****
       * Tokens
       *****
       GVizInvalidQuery  :  Unable to evaluate FROM clause. 
                     Data source doesn't contain base table employees.
-     
+
       >>> parse("from `employees`", 'basetable')
       *****
       * Tokens
       *****
       GVizInvalidQuery  :  Unable to evaluate FROM clause. 
                     Data source doesn't contain base table employees.
-      
+
       >>> parse("select dept , salary from emp_data", 'basetable', 'cols')
       *****
       * Tokens
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("where dept != 'Eng' and date '2005-01-21' < hireDate", \
       ...       'filter')
       ... 
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("where salary > 700", 'filter')
       *****
       * Tokens
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("where salary > 700.35", 'filter')
       *****
       * Tokens
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("select name where salary > 700", 'filter', 'cols')
       *****
       * Tokens
       * Parsing
       *****
       NotSupported  :(
-      
+
       """,
   'Parsing WHERE (complex)' : r"""
       >>> parse("where (dept<>'Eng' and isSenior=true) or " \
       * Parsing
       *****
       NotSupported  :(
-      
+
+      """,
+  'Parsing WHERE (string matching)' : r"""
+      >>> parse("where name contains 'John'", 'filter')
+      ...
+      *****
+      * Tokens
+      *****
+      Token.Keyword.Reserved where
+      Token.Name.Variable name
+      Token.Operator.Word contains
+      Token.Literal.String.Single 'John'
+      *****
+      * Parsing
+      *****
+      NotSupported  :(
+
+      >>> parse("where dept starts with 'engineering'", 'filter')
+      ...
+      *****
+      * Tokens
+      *****
+      Token.Keyword.Reserved where
+      Token.Name.Variable dept
+      Token.Operator.Word starts with
+      Token.Literal.String.Single 'engineering'
+      *****
+      * Parsing
+      *****
+      NotSupported  :(
+
+      >>> parse("where 'engineering' starts with dept", 'filter')
+      ...
+      *****
+      * Tokens
+      *****
+      Token.Keyword.Reserved where
+      Token.Literal.String.Single 'engineering'
+      Token.Operator.Word starts with
+      Token.Name.Variable dept
+      *****
+      * Parsing
+      *****
+      NotSupported  :(
+
+      >>> parse("where 'cowboy' ends with suffix", 'filter')
+      ...
+      *****
+      * Tokens
+      *****
+      Token.Keyword.Reserved where
+      Token.Literal.String.Single 'cowboy'
+      Token.Operator.Word ends with
+      Token.Name.Variable suffix
+      *****
+      * Parsing
+      *****
+      NotSupported  :(
+
+      >>> parse("where country matches '.*ia'", 'filter')
+      ...
+      *****
+      * Tokens
+      *****
+      Token.Keyword.Reserved where
+      Token.Name.Variable country
+      Token.Operator.Word matches
+      Token.Literal.String.Single '.*ia'
+      *****
+      * Parsing
+      *****
+      NotSupported  :(
+
+      >>> parse("where name like 'fre%'", 'filter')
+      ...
+      *****
+      * Tokens
+      *****
+      Token.Keyword.Reserved where
+      Token.Name.Variable name
+      Token.Operator.Word like
+      Token.Literal.String.Single 'fre%'
+      *****
+      * Parsing
+      *****
+      NotSupported  :(
+
       """,
   'Parsing GROUP BY (simple)' : r"""
       >>> parse("select dept  group by   dept", 'aggregate', 'cols')
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("select dept, max(salary) group by   dept   ", \
       ...           'aggregate', 'cols')
       ... 
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("select lunchTime, avg(salary), count(age) " \
       ...       "group by    isSenior,lunchTime", \
       ...           'aggregate', 'cols')
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("select dept  pivot    dept   ", 'pivot', 'cols')
       *****
       * Tokens
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("select sum(salary) pivot dept", 'pivot', 'cols')
       *****
       * Tokens
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("select sum(salary), max(lunchTime) pivot dept", \
       ...           'pivot', 'cols')
       ...
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("select dept, sum(salary) group by dept pivot lunchTime", \
       ...           'pivot', 'cols', 'aggregate')
       ...
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("select lunchTime, sum(salary) group by lunchTime " \
       ...       "pivot dept", 'pivot', 'cols', 'aggregate')
       ...
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("  select dept , lunchTime   group by dept "
       ...       "   order by dept", 'sort', 'aggregate', 'cols')
       ... 
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("  select dept , min(lunchTime)   group by dept "
       ...       "   order by max(salary)", 'sort', 'aggregate', 'cols')
       ... 
          age = 32
          isSenior = True
          seniorityStartTime = 2005-03-09 12:30:00
-      
+
       >>> parse(" select `name`    limit   2  ", 'cnt', 'cols')
       *****
       * Tokens
          name = John
       = Row =
          name = Dave
-      
+
       >>> parse("  select dept , lunchTime   group by dept "
       ...       "   order by dept limit 100", 'cnt', 'cols', 'aggregate')
       ... 
          age = 24
          isSenior = True
          seniorityStartTime = 2007-12-30 14:40:00
-      
+
       >>> parse(" select *    limit 2 offset   3  ", 'skip', 'cnt', 'cols')
       *****
       * Tokens
          age = 25
          isSenior = False
          seniorityStartTime = None
-      
+
       >>> parse("  select dept , lunchTime   group by dept "
       ...       " order by dept limit 25  offset 100 ", 'skip', 'cols', \
       ...           'aggregate', 'cnt', 'sort')
          name = Dana
       = Row =
          name = Mike
-      
+
       >>> parse("select *  label    dept 'Department'  , " \
       ...       "name    'Employee Id'      ", 'labels', 'cols')
       ... 
          age = 24
          isSenior = True
          seniorityStartTime = 2007-12-30 14:40:00
-      
+
       >>> parse(r'''label dept 'Department', ''' \
       ...         '''name "Employee Name", ''' \
       ...         '''location 'Employee Location' ''', 'labels')
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("  format  salary   '#,##0.00' ," \
       ...       "hireDate 'dd-MMM-yyyy',      " \
       ...       "isSenior     'not yet:of course!'    ", 'fmt')
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("format salary '#,##0.00', hireDate 'dd-MMM-yyyy', "
       ...       "isSenior 'Yes!:Not yet'", 'fmt')
       ... 
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("select salary, hireDate, isSenior   , lunchTime "
       ...       "format salary '#,##0.00', hireDate 'dd-MMM-yyyy', "
       ...       "isSenior 'Yes!:Not yet'", 'fmt', 'cols')
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("select dept , salary options no_values", 'opts', 'cols')
       *****
       * Tokens
       * Parsing
       *****
       NotSupported  :(
-      
+
       >>> parse("select `email address`, name, `date` options no_values", \
       ...           'opts', 'cols')
       ... 
       * Parsing
       *****
       Syntax error or unsupported feature. Unexpected token <EOL>.
-      
+
       >>> parse("  select 7group ", 'cols', fail=True)
       *****
       * Tokens
       * Parsing
       *****
       Syntax error or unsupported feature. Unexpected token 7group.
-      
+
       >>> parse("  select $group ", 'cols', fail=True)
       *****
       * Tokens
       * Parsing
       *****
       Syntax error or unsupported feature. Unexpected token $.
-      
+
       >>> parse("  select group ", 'cols', fail=True)
       *****
       * Tokens
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.