Commits

Olemis Lang  committed 0666121

GViz QL : Boolean expressions in where clause now work as expected

gvizql.py Total tests: 62 , Failures: 5 , Errors : 25

  • Participants
  • Parent commits 8d2a757
  • Branches gviz_ql

Comments (0)

Files changed (2)

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

       try:
         return row[schcols[colnm]]
       except KeyError:
-        raise GVizRuntimeError("Unknown column " + colnm)
+        raise GVizRuntimeError("Unknown column " + colnm + ".")
 
     return get_col_value
 
       try:
         return schema[schcols[colnm]]
       except KeyError:
-        raise GVizRuntimeError("Unknown column " + colnm)
+        raise GVizRuntimeError("Unknown column " + colnm + ".")
 
     return get_col_schema
 
     r"""Initialize SELECT clause handler with the sequence of expressions
     specified in input GViz QL statement.
     """
-    if not isinstance(seq, Sequence):
+    if seq == '*':
+      seq = None
+    elif not isinstance(seq, Sequence):
       seq = Sequence([seq])
-    self.cols_mapping = None if seq == '*' else seq
+    self.cols_mapping = seq
     logging.debug("Select list %s", seq)
     self.cols = [self._resolve_schema(c, lambda colnm: (colnm, None))[0] 
-        for c in self.cols_mapping or []]
+        for c in self.cols_mapping ] if seq is not None else None
 
   def transform(self, schema, data):
     r"""Arrange and transform values considering the given expressions list.
         return True, lambda *args: f(*values)
     else:
       return True, lambda *args: f(*(v(*args) if i in expand else v \
-              for i,v in enumerate(vals))),
+              for i,v in enumerate(values))),
 
 #------------------------------------------------------
 #   Global Testing
         expr = p.parse(expr)
       except GVizUnsupportedQueryOp :
         print '\nNotSupported  :(',
-      except GVizInvalidQuery, exc :
+      except (GVizInvalidQuery, GVizRuntimeError), exc :
         print 
         print unicode(exc)
       else:
             except IndexError :
               pass
           print 
-          for row in data :
-            print "= Row ="
-            for val, col in izip(row, iter_schema()):
-              print '  ', col[0], '=', val
+          try:
+            for row in data :
+              print "= Row ="
+              for val, col in izip(row, iter_schema()):
+                print '  ', col[0], '=', val
+          except (GVizInvalidQuery, GVizRuntimeError), exc :
+            print 
+            print exc.__class__.__name__, ' : ', unicode(exc)
+            
 
   l = MultiTestLoader([defaultTestLoader, \
                         DocTestLoader(

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

       *****
       * Result
       *****
-      GVizInvalidQuery  :  Unable to evaluate SELECT clause. Unknown column group.
+      GVizRuntimeError  :  Unknown column group.
 
       >>> parse("select dept, salary  ", 'cols')
       *****
       *****
       * Result
       *****
-      GVizInvalidQuery  :  Unable to evaluate SELECT clause. Unknown column email address.
+      GVizRuntimeError  :  Unknown column email address.
 
       >>> parse("select lunchTime , name", 'cols')
       *****
       *****
       * Parsing
       *****
-      NotSupported  :(
+      salary >= 600
+      *****
+      * Result
+      *****
+      = Columns =
+      name string
+      dept string
+      lunchTime timeofday
+      salary number
+      hireDate date
+      age number
+      isSenior boolean
+      seniorityStartTime datetime
+      = Row =
+         name = John
+         dept = Eng
+         lunchTime = 12:00:00
+         salary = 1000
+         hireDate = 2005-03-19
+         age = 35
+         isSenior = True
+         seniorityStartTime = 2007-12-02 15:56:00
+      = Row =
+         name = Sally
+         dept = Eng
+         lunchTime = 13:00:00
+         salary = 600
+         hireDate = 2005-10-10
+         age = 30
+         isSenior = False
+         seniorityStartTime = None
+      = Row =
+         name = Mike
+         dept = Marketing
+         lunchTime = 13:00:00
+         salary = 800
+         hireDate = 2005-01-10
+         age = 24
+         isSenior = True
+         seniorityStartTime = 2007-12-30 14:40:00
+
 
       >>> parse("where dept != 'Eng' and date '2005-01-21' < hireDate", \
       ...       'filter')
       *****
       * Parsing
       *****
-      NotSupported  :(
+      dept != 'Eng' and date '2005-01-21' < hireDate
+      *****
+      * Result
+      *****
+      = Columns =
+      name string
+      dept string
+      lunchTime timeofday
+      salary number
+      hireDate date
+      age number
+      isSenior boolean
+      seniorityStartTime datetime
+
+
+      >>> parse("where dept != 'Eng' and date '2005-01-01' < hireDate", \
+      ...       'filter')
+      ... 
+      *****
+      * Tokens
+      *****
+      Token.Keyword.Reserved where
+      Token.Name.Variable dept
+      Token.Operator.Comparison !=
+      Token.Literal.String.Single 'Eng'
+      Token.Operator.Word.Boolean and
+      Token.Literal.Date date '2005-01-01'
+      Token.Operator.Comparison <
+      Token.Name.Variable hireDate
+      *****
+      * Parsing
+      *****
+      dept != 'Eng' and date '2005-01-01' < hireDate
+      *****
+      * Result
+      *****
+      = Columns =
+      name string
+      dept string
+      lunchTime timeofday
+      salary number
+      hireDate date
+      age number
+      isSenior boolean
+      seniorityStartTime datetime
+      = Row =
+         name = Mike
+         dept = Marketing
+         lunchTime = 13:00:00
+         salary = 800
+         hireDate = 2005-01-10
+         age = 24
+         isSenior = True
+         seniorityStartTime = 2007-12-30 14:40:00
+
 
       >>> parse("where salary > 700", 'filter')
       *****
       *****
       * Parsing
       *****
-      NotSupported  :(
+      salary > 700
+      *****
+      * Result
+      *****
+      = Columns =
+      name string
+      dept string
+      lunchTime timeofday
+      salary number
+      hireDate date
+      age number
+      isSenior boolean
+      seniorityStartTime datetime
+      = Row =
+         name = John
+         dept = Eng
+         lunchTime = 12:00:00
+         salary = 1000
+         hireDate = 2005-03-19
+         age = 35
+         isSenior = True
+         seniorityStartTime = 2007-12-02 15:56:00
+      = Row =
+         name = Mike
+         dept = Marketing
+         lunchTime = 13:00:00
+         salary = 800
+         hireDate = 2005-01-10
+         age = 24
+         isSenior = True
+         seniorityStartTime = 2007-12-30 14:40:00
+
 
       >>> parse("where salary > 700.35", 'filter')
       *****
       *****
       * Parsing
       *****
-      NotSupported  :(
+      salary > 700.35
+      *****
+      * Result
+      *****
+      = Columns =
+      name string
+      dept string
+      lunchTime timeofday
+      salary number
+      hireDate date
+      age number
+      isSenior boolean
+      seniorityStartTime datetime
+      = Row =
+         name = John
+         dept = Eng
+         lunchTime = 12:00:00
+         salary = 1000
+         hireDate = 2005-03-19
+         age = 35
+         isSenior = True
+         seniorityStartTime = 2007-12-02 15:56:00
+      = Row =
+         name = Mike
+         dept = Marketing
+         lunchTime = 13:00:00
+         salary = 800
+         hireDate = 2005-01-10
+         age = 24
+         isSenior = True
+         seniorityStartTime = 2007-12-30 14:40:00
+
 
       >>> parse("select name where salary > 700", 'filter', 'cols')
       *****
       *****
       * Parsing
       *****
-      NotSupported  :(
+      salary > 700
+      [u'name']
+      *****
+      * Result
+      *****
+      = Columns =
+      name string
+      = Row =
+         name = John
+      = Row =
+         name = Mike
 
       """,
   'Parsing WHERE (complex)' : r"""
       *****
       * Parsing
       *****
-      NotSupported  :(
+      name contains 'John'
+      *****
+      * Result
+      *****
+      = Columns =
+      name string
+      dept string
+      lunchTime timeofday
+      salary number
+      hireDate date
+      age number
+      isSenior boolean
+      seniorityStartTime datetime
+      = Row =
+         name = John
+         dept = Eng
+         lunchTime = 12:00:00
+         salary = 1000
+         hireDate = 2005-03-19
+         age = 35
+         isSenior = True
+         seniorityStartTime = 2007-12-02 15:56:00
+
 
       >>> parse("where dept starts with 'engineering'", 'filter')
       ...
       *****
       * Parsing
       *****
-      NotSupported  :(
+      dept starts with 'engineering'
+      *****
+      * Result
+      *****
+      = Columns =
+      name string
+      dept string
+      lunchTime timeofday
+      salary number
+      hireDate date
+      age number
+      isSenior boolean
+      seniorityStartTime datetime
+
 
       >>> parse("where 'engineering' starts with dept", 'filter')
       ...
       *****
       * Parsing
       *****
-      NotSupported  :(
+      'engineering' starts with dept
+      *****
+      * Result
+      *****
+      = Columns =
+      name string
+      dept string
+      lunchTime timeofday
+      salary number
+      hireDate date
+      age number
+      isSenior boolean
+      seniorityStartTime datetime
+
 
       >>> parse("where 'cowboy' ends with suffix", 'filter')
       ...
       *****
       * Parsing
       *****
-      NotSupported  :(
+      'cowboy' ends with suffix
+      *****
+      * Result
+      *****
+      = Columns =
+      name string
+      dept string
+      lunchTime timeofday
+      salary number
+      hireDate date
+      age number
+      isSenior boolean
+      seniorityStartTime datetime
+      <BLANKLINE>
+      GVizRuntimeError  :  Unknown column suffix.
+
 
       >>> parse("where country matches '.*ia'", 'filter')
       ...
       *****
       * Parsing
       *****
-      NotSupported  :(
+      country matches '.*ia'
+      *****
+      * Result
+      *****
+      = Columns =
+      name string
+      dept string
+      lunchTime timeofday
+      salary number
+      hireDate date
+      age number
+      isSenior boolean
+      seniorityStartTime datetime
+      <BLANKLINE>
+      GVizRuntimeError  :  Unknown column country.
 
       >>> parse("where name like 'fre%'", 'filter')
       ...