Commits

Olemis Lang committed cd375aa

GViz QL : Implement 'max' and 'min' aggregation functions ... [ok]

Comments (0)

Files changed (2)

trac-dev/gviz/tracgviz/gvizql.py

     r"""Functor returning a callable providing access to columns schema 
     by column name.
     """
+    if schema is None:
+      return lambda colnm: (str(colnm), None)
+
     schcols = dict([col[0], i] for i, col in enumerate(schema))
 
     def get_col_schema(colnm):
 
     if not return_type:
       def agg_schema(get_col_schema):
-        schema = get_col_schema.__schema__
-        if not isinstance(row, self.Sequence):
-          raise GVizRuntimeError("%s invoked without GROUP BY, PIVOT" % (funcnm,))
-        else:
-          get_group_col_schema = GVizQLClauseHandler._schema_accessor(
-              schema.__schema__)
+        schema = getattr(get_col_schema, '__schema__', None)
+        if isinstance(schema, self.Sequence):
+          # In case of aggregate function with GROUP BY, PIVOT use base schema
+          # Otherwise avoid failing to expose schema even if statement is wrong
+          schema = getattr(schema, '__schema__', None)
+        get_group_col_schema = GVizQLClauseHandler._schema_accessor(schema)
+            
         try:
           return (func_label, get_group_col_schema(col_schema[0])[1])
         except GVizRuntimeError:

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

       *****
       * Result
       *****
-      NotImplementedError  :  Feature not supported ... yet
+      = Columns =
+      dept string
+      max(salary) number
+      = Row =
+         dept = Eng
+         max(salary) = 1000
+      = Row =
+         dept = Sales
+         max(salary) = 400
+      = Row =
+         dept = Marketing
+         max(salary) = 800
 
       >>> parse("select lunchTime, avg(salary), count(age) " \
       ...       "group by    isSenior,lunchTime", \
       *****
       * Result
       *****
+      = Columns =
+      isSenior boolean
+      max(salary) number
+      = Row =
+         isSenior = False
+         max(salary) = 600
+      = Row =
+         isSenior = True
+         max(salary) = 1000
 
       >>> parse("select dept, avg(salary) group by dept",
       ...       'aggregate', 'cols')
       *****
       * Result
       *****
+      = Columns =
+      isSenior boolean
+      min(salary) number
+      = Row =
+         isSenior = False
+         min(salary) = 350
+      = Row =
+         isSenior = True
+         min(salary) = 400
 
       """,
   'Parsing GROUP BY (failures)' : r"""
       *****
       * Result
       *****
-      NotImplementedError  :  Feature not supported ... yet
-
+      = Columns =
+      dept string
+      max(salary) number
+      = Row =
+         dept = Sales
+         max(salary) = 400
+      = Row =
+         dept = Marketing
+         max(salary) = 800
+      = Row =
+         dept = Eng
+         max(salary) = 1000
 
       >>> parse("  select dept , min(lunchTime)   group by dept "
       ...       "   order by max(salary)", 'sort', 'aggregate', 'cols')
       *****
       * Result
       *****
-      NotImplementedError  :  Feature not supported ... yet
+      = Columns =
+      dept string
+      min(lunchTime) timeofday
+      = Row =
+         dept = Sales
+         min(lunchTime) = 12:00:00
+      = Row =
+         dept = Marketing
+         min(lunchTime) = 13:00:00
+      = Row =
+         dept = Eng
+         min(lunchTime) = 12:00:00
 
       """,
   'Parsing LIMIT' : r"""