Commits

Olemis Lang committed a87c1b5 Merge

TracGViz : Incorporating enhancements for calculated column labels

  • Participants
  • Parent commits c5c11a5, 5328a22

Comments (0)

Files changed (3)

File trac-dev/gviz/TODO

 - Find the root cause for missing changes in revisions `1`, `3` and 
   `8` (e.g. lack of support in `TracMercurial` for `copy` events?)
 
+X GViz API QL: Support arithmetic expressions in label and format clauses
+
 - Add `limit` parameter for history methods in VersionControlRPC.
 
 - Implement data source provider for Ticket->Query
 
 - Put exception types in a separate module.
 
+- GViz API QL: Incremental production definition for operator precedence 
+  grammar parser
+
+- GViz API QL: Add test cases for complex GROUP BY statements
+
 - Allow to provide documentation to describe dynamic columns (i.e. 
   those columns that appear in data tables only when some run-time 
   conditions are met e.g. ticket custom fields in 

File trac-dev/gviz/tracgviz/gvizql.py

             (r'(?=date\s)', Whitespace, 'date'),
             (r'(?=timeofday\s)', Whitespace, 'tod'),
             (r'(?=(?:datetime|timestamp)\s)', Whitespace, 'dt'),
-            (r'`(?:\w|\s)+`', Name.Variable),
+            (r'`(?:[^`])+`', Name.Variable),
             (r'`.*`', Generic.Error),
             (r'`[^`]*(?=$)', Generic.Error),
             (r'\d*\.\d+(?=[^a-zA-Z_])', Number),
     return orderdef
 
   def handle_lblexpr(self, colnm, label):
-    return (str(colnm[1]), literal_eval(label[1]))
+    colnm = colnm[1]
+    if colnm.startswith('`'):
+      colnm = colnm[1:-1]
+    return (str(colnm), literal_eval(label[1]))
 
   def handle_lblseq(self, labels, _, label_expr):
     labels = labels[1]

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

       GVizUnsupportedQueryOp  :  Unable to evaluate GROUP BY clause. Either the whole clause or an specific feature is not supported yet.
 
       """,
-  'Parsing LABEL' : r"""
+  'Parsing LABEL (simple)' : r"""
       >>> parse("select name label name 'Employee Id' ", 'labels', 'cols')
       ... 
       *****
          isSenior = True
          seniorityStartTime = 2007-12-30 14:40:00
       """,
+  'Parsing LABEL (complex)' : r"""
+      >>> parse("select    max(salary) label `max(salary)` 'Better paid'",
+      ...       'cols', 'labels')
+      ...
+      *****
+      * Tokens
+      *****
+      Token.Keyword.Reserved select
+      Token.Name.Builtin max
+      Token.Punctuation (
+      Token.Name.Variable salary
+      Token.Punctuation )
+      Token.Keyword.Reserved label
+      Token.Name.Variable `max(salary)`
+      Token.Literal.String.Single 'Better paid'
+      *****
+      * Parsing
+      *****
+      ['max(salary)']
+      [('max(salary)', 'Better paid')]
+      *****
+      * Result
+      *****
+      = Columns =
+      max(salary) number Better paid
+      <BLANKLINE>
+      NotImplementedError  :  Feature not supported ... yet
+
+      >>> parse(r'''select lower(name) + '@example.com', upper(dept) 
+      ...       label `lower(name) + '@example.com'` 'E-mail', 
+      ...       `upper(dept)` "DEPT" ''',
+      ...       'cols', 'labels')
+      ...
+      *****
+      * Tokens
+      *****
+      Token.Keyword.Reserved select
+      Token.Name.Function lower
+      Token.Punctuation (
+      Token.Name.Variable name
+      Token.Punctuation )
+      Token.Operator.Arithmetic +
+      Token.Literal.String.Single '@example.com'
+      Token.Punctuation ,
+      Token.Name.Function upper
+      Token.Punctuation (
+      Token.Name.Variable dept
+      Token.Punctuation )
+      Token.Keyword.Reserved label
+      Token.Name.Variable `lower(name) + '@example.com'`
+      Token.Literal.String.Single 'E-mail'
+      Token.Punctuation ,
+      Token.Name.Variable `upper(dept)`
+      Token.Literal.String.Double "DEPT"
+      *****
+      * Parsing
+      *****
+      ["lower(name) + '@example.com'", 'upper(dept)']
+      [("lower(name) + '@example.com'", 'E-mail'), ('upper(dept)', 'DEPT')]
+      *****
+      * Result
+      *****
+      = Columns =
+      lower(name) + '@example.com' number E-mail
+      upper(dept) string DEPT
+      = Row =
+         lower(name) + '@example.com' = john@example.com
+         upper(dept) = ENG
+      = Row =
+         lower(name) + '@example.com' = dave@example.com
+         upper(dept) = ENG
+      = Row =
+         lower(name) + '@example.com' = sally@example.com
+         upper(dept) = ENG
+      = Row =
+         lower(name) + '@example.com' = ben@example.com
+         upper(dept) = SALES
+      = Row =
+         lower(name) + '@example.com' = dana@example.com
+         upper(dept) = SALES
+      = Row =
+         lower(name) + '@example.com' = mike@example.com
+         upper(dept) = MARKETING
+
+      """,
   'Parsing FORMAT' : r"""
       >>> parse("  format  salary   '#,##0.00' ", 'fmt')
       *****