Commits

Olemis Lang committed 233a8bb

GViz QL [ refs dataviz-302 ] : Do not fail if unknown columns specified in OPTION format_syntax ... ok

Related regex and code has been modified to fix a minor bug.

  • Participants
  • Parent commits ba3fbfa

Comments (0)

Files changed (2)

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

     self.no_values = self.no_format = False
     self.format_syntax = {}
 
-  RE_OPTION_FORMAT_SYNTAX = compile('(?:([^`][^:`]*?)|(?:`([^`]+)`))'
+  RE_OPTION_FORMAT_SYNTAX = compile('(?:([^`,][^:`,]*?)|(?:`([^`]+)`))'
                                     ':([^,]+?)(?:,|$)')
 
   def configure(self, options):
       i = 0
       for m in matches:
         if m.start() == i:
-          i = m.end() + 1
+          i = m.end()
           name, quoted, value = m.groups()
           self.format_syntax[(name or quoted).strip()] = value.strip()
         else:

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

          age = (None, 'twenty-four')
          isSenior = (None, 'true')
 
+
+      >>> parse("  select dayOfWeek(hireDate) "
+      ...       "format `dayOfWeek(hireDate)` 'Error;Sun;Mon;Tue;Wed;Thu;Fri;Sat;Error'"
+      ...       "  options    format_syntax:'`dayOfWeek(hireDate)`:NumberRule,x:XXX,y:NumberRule' ", 
+      ...       'opts', 'cols', 'fmt')
+      *****
+      * Tokens
+      *****
+      Token.Keyword.Reserved select
+      Token.Name.Function dayOfWeek
+      Token.Punctuation (
+      Token.Name.Variable hireDate
+      Token.Punctuation )
+      Token.Keyword.Reserved format
+      Token.Name.Variable `dayOfWeek(hireDate)`
+      Token.Literal.String.Single 'Error;Sun;Mon;Tue;Wed;Thu;Fri;Sat;Error'
+      Token.Keyword.Reserved options
+      Token.Name.Variable format_syntax
+      Token.Punctuation :
+      Token.Literal.String.Single '`dayOfWeek(hireDate)`:NumberRule,x:XXX,y:NumberRule'
+      *****
+      * Parsing
+      *****
+      [(u'format_syntax', '`dayOfWeek(hireDate)`:NumberRule,x:XXX,y:NumberRule')]
+      ['dayOfWeek(hireDate)']
+      [('dayOfWeek(hireDate)', 'Error;Sun;Mon;Tue;Wed;Thu;Fri;Sat;Error')]
+      *****
+      * Result
+      *****
+      = Columns =
+      dayOfWeek(hireDate) number
+      = Row =
+         dayOfWeek(hireDate) = (7, 'Sat')
+      = Row =
+         dayOfWeek(hireDate) = (4, 'Wed')
+      = Row =
+         dayOfWeek(hireDate) = (2, 'Mon')
+      = Row =
+         dayOfWeek(hireDate) = (5, 'Thu')
+      = Row =
+         dayOfWeek(hireDate) = (4, 'Wed')
+      = Row =
+         dayOfWeek(hireDate) = (2, 'Mon')
+
+
       """,
   'Parsing OPTIONS errors' : r"""
       >>> parse("select * options no_values, format_syntax:'salary:PredefinedNumberRule,:,' "
       *****
       * Result
       *****
-      GVizIllegalPattern  :  Bad syntax in format_syntax option at 29
+      GVizIllegalPattern  :  Bad syntax in format_syntax option at 28
 
 
       >>> parse("select * options no_values, format_syntax:'age:PredefinedNumberRule,:,"
       *****
       * Result
       *****
-      GVizIllegalPattern  :  Bad syntax in format_syntax option at 26
+      GVizIllegalPattern  :  Bad syntax in format_syntax option at 25
 
 
       >>> parse("select * options no_values, format_syntax:'salary:XXX' "