-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ch] update test times #5663
[ch] update test times #5663
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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://"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to use something like https://docs.python.org/3/library/urllib.parse.html to get the hostname, scheme, and port number There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did some testing right now, and it doesn't seem to handle having vs not having https:// well I also found this in the docs |
||
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting, so |
||
json_row = {} | ||
for i, column in enumerate(res.column_names): | ||
json_row[column] = row[i] | ||
json_res.append(json_row) | ||
return json_res |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain why changing
python
topython3
is necessary?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched from python3 to python since I added the setup python step, which makes the default python the version that gets setup in the setup step