Commits

Olemis Lang committed d327f0a

GViz QL : Detect columns potentially missing in GROUP BY clause and emit an informative message ... (failures=1)

Comments (0)

Files changed (1)

trac-dev/gviz/tracgviz/gvizql.py

       try:
         return row[schcols[colnm]]
       except KeyError:
-        raise GVizRuntimeError("Unknown column " + colnm + ".")
+        if isinstance(row, Tuple) and \
+            any(c[0] == colnm for c in getattr(row, '__schema__', [])):
+          # Selecting column in original schema but not in GROUP BY clause
+          raise GVizRuntimeError("Column [%s] should be added to GROUP BY, "
+              "removed from SELECT, or aggregated in SELECT." % (colnm,) )
+        else:
+          raise GVizRuntimeError("Unknown column " + colnm + ".")
 
     return get_col_value
 
       try:
         return schema[schcols[colnm]]
       except KeyError:
-        raise GVizRuntimeError("Unknown column " + colnm + ".")
+        if isinstance(schema, Sequence) and \
+            any(c[0] == colnm for c in getattr(schema, '__schema__', [])):
+          # Selecting column in original schema but not in GROUP BY clause
+          raise GVizRuntimeError("Column [%s] should be added to GROUP BY, "
+              "removed from SELECT, or aggregated in SELECT." % (colnm,) )
+        else:
+          raise GVizRuntimeError("Unknown column " + colnm + ".")
 
     return get_col_schema
 
     """
     get_col_value = self._column_accessor(schema)
     get_col_schema = self._schema_accessor(schema)
-    new_schema = [self._resolve_schema(c, get_col_schema) \
-        for c in self.groups_def]
+    new_schema = Sequence(self._resolve_schema(c, get_col_schema) \
+        for c in self.groups_def)
+    new_schema.__schema__ = schema
     groups = groupby(data, 
         key=lambda row: Tuple(self._eval_expr(row, c, get_col_value) \
             for c in self.groups_def)