import httplib2
import threading
import os
+import sys
import time
import traceback
try:
FLOW = flow_from_clientsecrets('/opt/planetstack/hpc_wizard/client_secrets.json',
scope='https://www.googleapis.com/auth/bigquery')
+ BIGQUERY_AVAILABLE = True
except:
- print "exception while initializing bigquery flow"
+ print >> sys.stderr, "exception while initializing bigquery flow"
traceback.print_exc()
FLOW = None
+ BIGQUERY_AVAILABLE = False
MINUTE_MS = 60*1000
HOUR_MS = 60*60*1000
credentials = storage.get()
if credentials is None or credentials.invalid:
- credentials = run(FLOW, storage)
+ credentials = run(FLOW, storage)
http = httplib2.Http()
http = credentials.authorize(http)
field["name"] = reverse_mappings[self.tableName].get(field["name"], field["name"])
def run_query(self, query):
+ if not BIGQUERY_AVAILABLE:
+ print >> sys.stderr, "bigquery_analytics: bigquery flow is not available. returning empty result."
+ return []
+
response = self.run_query_raw(query)
fieldNames = []
avg = [x.replace("%","") for x in avg]
computed = [x.replace("%","") for x in computed]
maxi = [x.replace("%","") for x in maxi]
+ groupBy = [x.replace("%","") for x in groupBy]
for (k,v) in filter.items():
rows = self.filter_results(rows, k, v)
(computedFieldNames, rows) = self.do_computed_fields(rows, computed)
sum = sum + computedFieldNames
- rows = self.groupby_results(rows, groupBy, sum, count, avg, maxi)
+ if groupBy:
+ rows = self.groupby_results(rows, groupBy, sum, count, avg, maxi)
return rows
def remap(self, match):