fix python error when no rows in query
Scott Baker [Mon, 21 Apr 2014 07:27:56 +0000 (00:27 -0700)]
planetstack/hpc_wizard/planetstack_analytics.py

index 8fee0dc..7e0d1b6 100644 (file)
@@ -311,18 +311,19 @@ class PlanetStackAnalytics(BigQueryAnalytics):
             table = {}
             table["cols"] = self.schema_to_cols(bq_result["schema"])
             rows = []
-            for row in bq_result["rows"]:
-                rowcols = []
-                for (colnum,col) in enumerate(row["f"]):
-                    if (colnum==0):
-                        dt = datetime.datetime.fromtimestamp(float(col["v"]))
-                        rowcols.append({"v": 'new Date("%s")' % dt.isoformat()})
-                    else:
-                        try:
-                            rowcols.append({"v": float(col["v"])})
-                        except:
-                            rowcols.append({"v": col["v"]})
-                rows.append({"c": rowcols})
+            if "rows" in bq_result:
+                for row in bq_result["rows"]:
+                    rowcols = []
+                    for (colnum,col) in enumerate(row["f"]):
+                        if (colnum==0):
+                            dt = datetime.datetime.fromtimestamp(float(col["v"]))
+                            rowcols.append({"v": 'new Date("%s")' % dt.isoformat()})
+                        else:
+                            try:
+                                rowcols.append({"v": float(col["v"])})
+                            except:
+                                rowcols.append({"v": col["v"]})
+                    rows.append({"c": rowcols})
             table["rows"] = rows
 
             if tqx: