Skip to content

Commit

Permalink
Add the option to run the queries sync
Browse files Browse the repository at this point in the history
  • Loading branch information
shahargl committed Sep 26, 2021
1 parent c2d292c commit 00648b7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,7 @@ dmypy.json
.pyre/

# visual studio code
.vscode
.vscode

# PyCharm
.idea
6 changes: 5 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
def main():
load_dotenv() # only on local run
queries_list = os.environ['INPUT_QUERIES'].split(';')
sync = os.environ.get("INPUT_SYNC", False)
warehouse = os.environ['INPUT_SNOWFLAKE_WAREHOUSE']
snowflake_account = os.environ['INPUT_SNOWFLAKE_ACCOUNT']
snowflake_username = os.environ['INPUT_SNOWFLAKE_USERNAME']
Expand All @@ -33,7 +34,10 @@ def main():
print(f"[!] Query id - {query_result.query_id}")
print(f"[!] Running query ### - {query}")

json_results = asyncio.run(utils.gather_all_results(query_results))
if not sync:
json_results = asyncio.run(utils.gather_all_results(query_results))
else:
json_results = utils.gather_all_results_sync(query_results)

utils.set_github_action_output('queries_results', json.dumps(json_results))

Expand Down
6 changes: 5 additions & 1 deletion snowflake_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ async def fetch_results(self):
while self.is_query_running():
await asyncio.sleep(0.1)

return self._fetch_results()
return self._fetch_results()

def fetch_results_sync(self):
self.cursor.get_results_from_sfqid(self.query_id)
return self.cursor.fetchall()
15 changes: 15 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,19 @@ async def gather_all_results(query_result_list: List[QueryResult]) -> dict:
print(row)
json_total_results[done_task.get_name()].append(str(row))

return json_total_results


def gather_all_results_sync(query_results_list: List[QueryResult]) -> dict:
"""
Args:
query_results_list:
Returns:
"""
json_total_results = {}
for query in query_results_list:
json_total_results[query.query_id] = query.fetch_results_sync()
return json_total_results

0 comments on commit 00648b7

Please sign in to comment.