Commits

Olemis Lang  committed 3497004

GViz QL : Building sequence for single label expression

  • Participants
  • Parent commits 6fbe10c
  • Branches gviz_ql

Comments (0)

Files changed (2)

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

 from re import compile
 from weakref import proxy
 
+from tracgviz.api import DataTable
 from tracgviz.util.parsing import OperatorPrecedenceParser,  \
     InvalidParserConfiguration
 
   def __init__(self, seq):
     r"""Initialize this clause with a sequence of formatting expressions
     """
-    self.labels = list(seq)
+    if not isinstance(seq, Sequence):
+      seq = Sequence([seq])
+    self.labels = seq
 
   def transform(self, schema, data):
     r"""(Add | modify) the schema in order to (include | update) 
   sch = provider.get_data_schema.im_func.func_code
   sch_args = (sch.co_argcount > 1) and (req,) or ()
   if not tq:
+    sch = provider.get_data_schema(*sch_args)
     data = provider.get_data(req, None, **params)
-    return (provider.get_data_schema(*sch_args), data)
+    return (sch, data)
   else:
     tq = GVizQLParser().parse(tq)
+    sch = provider.get_data_schema(*sch_args)
     data = provider.get_data(req, tq, **params)
-    sch = provider.get_data_schema(*sch_args)
-    return tq.transform(sch, data)
+    table = DataTable(sch)
+    # FIXME : Optimize memory
+    table.LoadData(data)
+    sch = [(col['id'], col['type']) + \
+        ( (col['label'],) if col.get('label') else () ) \
+        for col in table.columns]
+    data_seq = ( tuple(row.get(col['id']) for col in table.columns) \
+        for row in table._PreparedData() )
+        
+    return tq.transform(sch, data_seq)
 
 class Sequence(list):
   pass

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

 
       """,
   'Parsing LABEL' : r"""
+      >>> parse("select name label name 'Employee Id' ", 'labels', 'cols')
+      ... 
+      *****
+      * Tokens
+      *****
+      Token.Keyword.Reserved select
+      Token.Name.Variable name
+      Token.Keyword.Reserved label
+      Token.Name.Variable name
+      Token.Literal.String.Single 'Employee Id'
+      *****
+      * Parsing
+      *****
+      [(u'name', 'Employee Id')]
+      [u'name']
+      *****
+      * Result
+      *****
+      = Columns =
+      name string Employee Id
+      = Row =
+         name = John
+      = Row =
+         name = Dave
+      = Row =
+         name = Sally
+      = Row =
+         name = Ben
+      = Row =
+         name = Dana
+      = Row =
+         name = Mike
+
+
       >>> parse("select name label    dept 'Department' , " \
       ...           "name 'Employee Id' ", 'labels', 'cols')
       ...