-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
164 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import json | ||
import os | ||
from functools import lru_cache | ||
from typing import Any, Dict | ||
|
||
import clickhouse_connect | ||
from torchci.utils import REPO_ROOT | ||
|
||
|
||
@lru_cache(maxsize=1) | ||
def get_clickhouse_client() -> Any: | ||
endpoint = os.environ["CLICKHOUSE_ENDPOINT"] | ||
# I cannot figure out why these values aren't being handled automatically | ||
# when it is fine in the lambda | ||
if endpoint.startswith("https://"): | ||
endpoint = endpoint[len("https://") :] | ||
if endpoint.endswith(":8443"): | ||
endpoint = endpoint[: -len(":8443")] | ||
return clickhouse_connect.get_client( | ||
host=endpoint, | ||
user=os.environ["CLICKHOUSE_USERNAME"], | ||
password=os.environ["CLICKHOUSE_PASSWORD"], | ||
secure=True, | ||
interface="https", | ||
port=8443, | ||
) | ||
|
||
|
||
def query_clickhouse_saved(queryName: str, inputParams: Dict[str, Any]) -> Any: | ||
path = REPO_ROOT / "torchci" / "clickhouse_queries" / queryName | ||
with open(path / "query.sql") as f: | ||
queryText = f.read() | ||
with open(path / "params.json") as f: | ||
paramsText = json.load(f) | ||
|
||
queryParams = {name: inputParams[name] for name in paramsText} | ||
return query_clickhouse(queryText, queryParams) | ||
|
||
|
||
def query_clickhouse(query: str, params: Dict[str, Any]) -> Any: | ||
res = get_clickhouse_client().query(query, params) | ||
json_res = [] | ||
# convert to json | ||
for row in res.result_rows: | ||
json_row = {} | ||
for i, column in enumerate(res.column_names): | ||
json_row[column] = row[i] | ||
json_res.append(json_row) | ||
return json_res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ requests | |
rockset==1.0.3 | ||
boto3==1.19.12 | ||
pytest==7.2.0 | ||
clickhouse-connect==0.7.16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 28 additions & 20 deletions
48
torchci/clickhouse_queries/test_time_per_class_periodic_jobs/query.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.