Commits

Olemis Lang  committed a388ecd

GViz QL : Use str instead of unicode in transformed schema

  • Participants
  • Parent commits 3497004
  • Branches gviz_ql

Comments (0)

Files changed (2)

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

       seq = Sequence([seq])
     self.cols_mapping = seq
     logging.debug("Select list %s", seq)
-    self.cols = [self._resolve_schema(c, lambda colnm: (colnm, None))[0] 
+    self.cols = [self._resolve_schema(c, lambda colnm: (str(colnm), None))[0] 
         for c in self.cols_mapping ] if seq is not None else None
 
   def transform(self, schema, data):
 
     FROM clause is deprecated and has been removed from the language.
     """
-    self.basetable = name['schema'](lambda colnm: (colnm, None))[0]
+    self.basetable = name['schema'](lambda colnm: (str(colnm), None))[0]
 
   def transform(self, schema, data):
     r"""Notify that base table has not been processed by data source. 
           (" Got %s" % (expr['schema'][1])) if not expr['is_schema_callable']
               else '')
     self.expr = expr
-    self.filter = self._resolve_schema(expr, lambda colnm: (colnm, None))[0]
+    self.filter = self._resolve_schema(expr, lambda colnm: (str(colnm), None))[0]
 
   def transform(self, schema, data):
     r"""Filter rows that do not satisfy target predicate.
     if not isinstance(seq, Sequence):
       seq = Sequence([seq])
     self.groups_def = seq
-    self.aggregate = [self._resolve_schema(c, lambda colnm: (colnm, None))[0] 
+    self.aggregate = [self._resolve_schema(c, lambda colnm: (str(colnm), None))[0] 
         for c in self.groups_def ]
 
   def transform(self, schema, data):
     if not isinstance(seq, Sequence):
       seq = Sequence([seq])
     self.pivot_def = seq
-    self.pivot = [self._resolve_schema(c, lambda colnm: (colnm, None))[0] 
+    self.pivot = [self._resolve_schema(c, lambda colnm: (str(colnm), None))[0] 
         for c in self.pivot_def ]
 
   def transform(self, schema, data):
     elif isinstance(seq, dict):
       seq = Sequence([(seq, True)])
     self.order_def = [c if isinstance(c, tuple) else (c, True) for c in seq]
-    self.sort = [(self._resolve_schema(c, lambda colnm: (colnm, None))[0], is_asc) 
+    self.sort = [
+        (self._resolve_schema(c, lambda colnm: (str(colnm), None))[0], is_asc) 
         for c, is_asc in self.order_def ]
 
   def transform(self, schema, data):
     r"""Initialize this clause with a list of option names.
     """
     if not isinstance(seq, Sequence):
-      get_col_schema = lambda _colnm: (_colnm, None)
+      get_col_schema = lambda _colnm: (str(_colnm), None)
       seq = seq['schema'](get_col_schema)[0]
       seq = Sequence([seq])
     self.opts = seq
       _value = float(value[1])
     return dict(
         eval=_value, 
-        schema=(value[1], 'number'), 
+        schema=(str(value[1]), 'number'), 
         is_eval_callable=False,
         is_schema_callable=False
       )
   def handle_str(self, value):
     return dict(
         eval=literal_eval(value[1]), 
-        schema=(value[1], 'string'),
+        schema=(str(value[1]), 'string'),
         is_eval_callable=False,
         is_schema_callable=False)
 
     raise NotImplementedError('Feature not supported ... yet')
 
   def handle_bfunc(self, funcnm, _, colnm, __):
-    funcnm = funcnm[1]
+    funcnm = str(funcnm[1])
     colnm = colnm[1]
-    col_schema = colnm['schema'](lambda colnm: (colnm, None) )
+    col_schema = colnm['schema'](lambda colnm: (str(colnm), None) )
     try:
       f = self.agg_funcs[funcnm]
     except KeyError:
       )
 
   def handle_func(self, funcnm, _, __):
-    funcnm = funcnm[1]
+    funcnm = str(funcnm[1])
     try:
       f = self.scalar_funcs[funcnm]
       return_type = r.return_type
           funcnm)
     if funcnm == 'now':
       # Unique time measurement
+      # FIXME: Maybe this belongs somewhere else
       if self.now is None:
         self.now = f()
       return dict(
         )
 
   def handle_funcargs(self, funcnm, _, seq, __):
-    funcnm = funcnm[1]
+    funcnm = str(funcnm[1])
     seq = seq[1]
     if not isinstance(seq, self.Sequence):
       seq = self.Sequence([seq])
   handle_boolpar = handle_par
 
   def _handle_binary_op(self, lexpr, op, rexpr):
-    op = op[1]
+    op = str(op[1])
     lexpr = lexpr[1]
     rexpr = rexpr[1]
 
     is_eval_callable, eval_func = self._eval_expr(f, [lexpr, rexpr])
     return_type = 'number' if op in '-+*/' else 'boolean'
     if lexpr['is_schema_callable']:
-      lschema = lexpr['schema'](lambda colnm : (colnm, None))
+      lschema = lexpr['schema'](lambda colnm : (str(colnm), None))
     else:
       lschema = lexpr['schema']
     if rexpr['is_schema_callable']:
-      rschema = rexpr['schema'](lambda colnm : (colnm, None))
+      rschema = rexpr['schema'](lambda colnm : (str(colnm), None))
     else:
       rschema = rexpr['schema']
     return dict(
     return orderdef
 
   def handle_lblexpr(self, colnm, label):
-    return (colnm[1], literal_eval(label[1]))
+    return (str(colnm[1]), literal_eval(label[1]))
 
   def handle_lblseq(self, labels, _, label_expr):
     labels = labels[1]
     return labels
 
   def handle_column(self, colnm):
-    return colnm[1]['schema'](lambda _colnm: (_colnm, None))[0]
+    return colnm[1]['schema'](lambda _colnm: (str(_colnm), None))[0]
 
   def handle_colseq(self, colseq, _, colnm):
     colseq = colseq[1]
     colnm = colnm[1]
-    get_col_schema = lambda _colnm: (_colnm, None)
+    get_col_schema = lambda _colnm: (str(_colnm), None)
     if isinstance(colseq, self.Sequence):
       colnm = colnm['schema'](get_col_schema)[0]
       colseq.append(colnm)
   def _function_label(self, funcnm, seq):
     return '%s(%s)' % (funcnm, 
         ', '.join(x['schema'][0] if not x['is_schema_callable'] \
-            else x['schema'](lambda colnm: (colnm, None))[0] \
+            else x['schema'](lambda colnm: (str(colnm), None))[0] \
             for x in seq))
 
   def _eval_expr(self, f, seq, deterministic=True):

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

       *****
       * Parsing
       *****
-      [u'group', u'selectme']
+      ['group', 'selectme']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'dept', u'salary']
+      ['dept', 'salary']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'email address', u'name', u'date']
+      ['email address', 'name', 'date']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'lunchTime', u'name']
+      ['lunchTime', 'name']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'name']
+      ['name']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'max(salary)']
+      ['max(salary)']
       *****
       * Result
       *****
       * Parsing
       *****
       emp_data
-      [u'dept', u'salary']
+      ['dept', 'salary']
       *****
       * Result
       *****
       * Parsing
       *****
       salary > 700
-      [u'name']
+      ['name']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'dept']
-      [u'dept']
+      ['dept']
+      ['dept']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'dept']
-      [u'dept', u'max(salary)']
+      ['dept']
+      ['dept', 'max(salary)']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'isSenior', u'lunchTime']
-      [u'lunchTime', u'avg(salary)', u'count(age)']
+      ['isSenior', 'lunchTime']
+      ['lunchTime', 'avg(salary)', 'count(age)']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'dept', u'salary', u'lunchTime']
-      [u'dept']
+      ['dept', 'salary', 'lunchTime']
+      ['dept']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'dept']
-      [u'dept']
+      ['dept']
+      ['dept']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'dept']
-      [u'sum(salary)']
+      ['dept']
+      ['sum(salary)']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'dept', u'lunchTime']
-      [u'sum(salary)']
+      ['dept', 'lunchTime']
+      ['sum(salary)']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'dept']
-      [u'sum(salary)', u'max(lunchTime)']
+      ['dept']
+      ['sum(salary)', 'max(lunchTime)']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'lunchTime']
-      [u'dept', u'sum(salary)']
-      [u'dept']
+      ['lunchTime']
+      ['dept', 'sum(salary)']
+      ['dept']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'dept']
-      [u'lunchTime', u'sum(salary)']
-      [u'lunchTime']
+      ['dept']
+      ['lunchTime', 'sum(salary)']
+      ['lunchTime']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [(u'dept', True), (u'salary', False)]
+      [('dept', True), ('salary', False)]
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [(u'dept', True)]
-      [u'dept']
-      [u'dept', u'lunchTime']
+      [('dept', True)]
+      ['dept']
+      ['dept', 'lunchTime']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [(u'max(salary)', True)]
-      [u'dept']
-      [u'dept', u'max(salary)']
+      [('max(salary)', True)]
+      ['dept']
+      ['dept', 'max(salary)']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [(u'max(salary)', True)]
-      [u'dept']
-      [u'dept', u'min(lunchTime)']
+      [('max(salary)', True)]
+      ['dept']
+      ['dept', 'min(lunchTime)']
       *****
       * Result
       *****
       * Parsing
       *****
       2
-      [u'name']
+      ['name']
       *****
       * Result
       *****
       * Parsing
       *****
       100
-      [u'dept', u'lunchTime']
-      [u'dept']
-      [(u'dept', True)]
+      ['dept', 'lunchTime']
+      ['dept']
+      [('dept', True)]
       *****
       * Result
       *****
       * Parsing
       *****
       100
-      [u'dept', u'lunchTime']
-      [u'dept']
+      ['dept', 'lunchTime']
+      ['dept']
       25
-      [(u'dept', True)]
+      [('dept', True)]
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [(u'name', 'Employee Id')]
-      [u'name']
+      [('name', 'Employee Id')]
+      ['name']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [(u'dept', 'Department'), (u'name', 'Employee Id')]
-      [u'name']
+      [('dept', 'Department'), ('name', 'Employee Id')]
+      ['name']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [(u'dept', 'Department'), (u'name', 'Employee Id')]
+      [('dept', 'Department'), ('name', 'Employee Id')]
       None
       *****
       * Result
       *****
       * Parsing
       *****
-      [(u'dept', 'Department'), (u'name', 'Employee Name'), 
-          (u'location', 'Employee Location')]
+      [('dept', 'Department'), ('name', 'Employee Name'), 
+          ('location', 'Employee Location')]
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [(u'salary', '#,##0.00')]
+      [('salary', '#,##0.00')]
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [(u'salary', '#,##0.00'), (u'hireDate', 'dd-MMM-yyyy'), (u'isSenior', 'not yet:of course!')]
+      [('salary', '#,##0.00'), ('hireDate', 'dd-MMM-yyyy'), ('isSenior', 'not yet:of course!')]
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [(u'salary', '#,##0.00'), (u'hireDate', 'dd-MMM-yyyy'), (u'isSenior', 'Yes!:Not yet')]
+      [('salary', '#,##0.00'), ('hireDate', 'dd-MMM-yyyy'), ('isSenior', 'Yes!:Not yet')]
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [(u'salary', '#,##0.00'), (u'hireDate', 'dd-MMM-yyyy'), (u'isSenior', 'Yes!:Not yet')]
-      [u'salary', u'hireDate', u'isSenior', u'lunchTime']
+      [('salary', '#,##0.00'), ('hireDate', 'dd-MMM-yyyy'), ('isSenior', 'Yes!:Not yet')]
+      ['salary', 'hireDate', 'isSenior', 'lunchTime']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'no_format']
+      ['no_format']
       None
       *****
       * Result
       *****
       * Parsing
       *****
-      [u'no_values']
-      [u'dept', u'salary']
+      ['no_values']
+      ['dept', 'salary']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'no_values']
-      [u'email address', u'name', u'date']
+      ['no_values']
+      ['email address', 'name', 'date']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'year(hireDate)', u'month(hireDate)', u'day(hireDate)', u'year(seniorityStartTime)', u'month(seniorityStartTime)', u'day(seniorityStartTime)', u'hour(seniorityStartTime)', u'minute(seniorityStartTime)', u'second(seniorityStartTime)']
+      ['year(hireDate)', 'month(hireDate)', 'day(hireDate)', 'year(seniorityStartTime)', 'month(seniorityStartTime)', 'day(seniorityStartTime)', 'hour(seniorityStartTime)', 'minute(seniorityStartTime)', 'second(seniorityStartTime)']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'quarter(hireDate)', u'dayOfWeek(hireDate)', u'quarter(seniorityStartTime)', u'dayOfWeek(seniorityStartTime)']
+      ['quarter(hireDate)', 'dayOfWeek(hireDate)', 'quarter(seniorityStartTime)', 'dayOfWeek(seniorityStartTime)']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'toDate(seniorityStartTime)']
+      ['toDate(seniorityStartTime)']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u"lower(name) + '@example.com'", u'upper(dept)']
+      ["lower(name) + '@example.com'", 'upper(dept)']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'empSalary - empTax']
+      ['empSalary - empTax']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'2 * (max(empSalary) / max(empTax))']
+      ['2 * (max(empSalary) / max(empTax))']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'12 * (year(seniorityStartTime) - year(hireDate)) + month(seniorityStartTime) - month(hireDate)']
+      ['12 * (year(seniorityStartTime) - year(hireDate)) + month(seniorityStartTime) - month(hireDate)']
       *****
       * Result
       *****
       *****
       * Parsing
       *****
-      [u'salary / (age - 24)']
+      ['salary / (age - 24)']
       *****
       * Result
       *****