Skip to content

Commit

Permalink
Update docker entry point and make bigquery credential not required w…
Browse files Browse the repository at this point in the history
…hen starting
  • Loading branch information
dyang415 committed Sep 20, 2023
1 parent fa3f674 commit e056294
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ WORKDIR /app/backend
EXPOSE 5001

# Run Flask application
CMD . /opt/venv/bin/activate && exec flask run -h 0.0.0.0 -p 5001
CMD . /opt/venv/bin/activate && exec python run.py
17 changes: 11 additions & 6 deletions backend/app/data_source/bigquery/bigquery_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@

class BigquerySource:

def __init__(self) -> None:
self.client = bigquery.Client()
client: bigquery.Client = None

def get_client(self) -> bigquery.Client:
if self.client is None:
self.client = bigquery.Client()

return self.client

@staticmethod
def convert_field_type(bq_type: str) -> str:
pass

def get_schema(self, full_name: str) -> BigquerySchema:
table = self.client.get_table(full_name)
table = self.get_client().get_table(full_name)

selections = ','.join(
[f'APPROX_COUNT_DISTINCT({field.name}) as {field.name}' for field in table.schema if field.field_type != 'RECORD'])
Expand Down Expand Up @@ -59,7 +64,7 @@ def get_schema(self, full_name: str) -> BigquerySchema:
return schema

def list_dataset(self) -> list[Dataset]:
dataset_list_res = self.client.list_datasets()
dataset_list_res = self.get_client().list_datasets()

return [Dataset(
name=dataset.dataset_id,
Expand All @@ -68,7 +73,7 @@ def list_dataset(self) -> list[Dataset]:
for dataset in dataset_list_res]

def list_tables(self, dataset: Dataset = None) -> list[BigquerySchema]:
tables = self.client.list_tables(dataset)
tables = self.get_client().list_tables(dataset)
schemas = []
for row in tables:
schema = self.get_schema(row.full_table_id)
Expand All @@ -85,5 +90,5 @@ def run_queries_in_parallel(self, queries) -> list[RowIterator]:

def run_query(self, query) -> RowIterator:
# Run the query and return the results
query_job = self.client.query(query)
query_job = self.get_client().query(query)
return query_job.result()
4 changes: 4 additions & 0 deletions backend/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from app import app

if __name__ == '__main__':
app.run(debug=True, port=5001, host="::", threaded=False, processes=4)

0 comments on commit e056294

Please sign in to comment.