Skip to content
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

feat(queries): Set ClickHouse max execution time higher for async queries #18747

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions posthog/clickhouse/client/execute_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def enqueue_process_query_task(
query_json,
query_id=None,
refresh_requested=False,
in_export_context=False,
bypass_celery=False,
force=False,
):
Expand Down Expand Up @@ -115,12 +114,10 @@ def enqueue_process_query_task(

if bypass_celery:
# Call directly ( for testing )
process_query_task(
team_id, query_id, query_json, in_export_context=in_export_context, refresh_requested=refresh_requested
)
process_query_task(team_id, query_id, query_json, in_export_context=True, refresh_requested=refresh_requested)
else:
task = process_query_task.delay(
team_id, query_id, query_json, in_export_context=in_export_context, refresh_requested=refresh_requested
team_id, query_id, query_json, in_export_context=True, refresh_requested=refresh_requested
)
query_status.task_id = task.id
redis_client.set(key, query_status.model_dump_json(), ex=REDIS_STATUS_TTL_SECONDS)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# name: ClickhouseClientTestCase.test_async_query_client
'
SELECT plus(1, 1)
LIMIT 10000 SETTINGS readonly=2,
max_execution_time=600,
allow_experimental_object_type=1
'
---
3 changes: 2 additions & 1 deletion posthog/clickhouse/client/test/test_execute_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from posthog.client import sync_execute
from posthog.hogql.errors import HogQLException
from posthog.models import Organization, Team
from posthog.test.base import ClickhouseTestMixin
from posthog.test.base import ClickhouseTestMixin, snapshot_clickhouse_queries


def build_query(sql):
Expand All @@ -23,6 +23,7 @@ def setUp(self):
self.team = Team.objects.create(organization=self.organization)
self.team_id = self.team.pk

@snapshot_clickhouse_queries
def test_async_query_client(self):
query = build_query("SELECT 1+1")
team_id = self.team_id
Expand Down
9 changes: 9 additions & 0 deletions posthog/hogql/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def print_ast(
stack: Optional[List[ast.SelectQuery]] = None,
settings: Optional[HogQLGlobalSettings] = None,
pretty: bool = False,
timeout: Optional[int] = None,
) -> str:
prepared_ast = prepare_ast_for_printing(node=node, context=context, dialect=dialect, stack=stack, settings=settings)
return print_prepared_ast(
Expand All @@ -82,6 +83,7 @@ def print_ast(
stack=stack,
settings=settings,
pretty=pretty,
timeout=timeout,
)


Expand Down Expand Up @@ -125,6 +127,7 @@ def print_prepared_ast(
stack: Optional[List[ast.SelectQuery]] = None,
settings: Optional[HogQLGlobalSettings] = None,
pretty: bool = False,
timeout: Optional[int] = None,
) -> str:
with context.timings.measure("printer"):
# _Printer also adds a team_id guard if printing clickhouse
Expand All @@ -134,6 +137,7 @@ def print_prepared_ast(
stack=stack or [],
settings=settings,
pretty=pretty,
timeout=timeout,
).visit(node)


Expand All @@ -153,6 +157,7 @@ def __init__(
stack: Optional[List[AST]] = None,
settings: Optional[HogQLGlobalSettings] = None,
pretty: bool = False,
timeout: Optional[int] = None,
):
self.context = context
self.dialect = dialect
Expand All @@ -161,6 +166,7 @@ def __init__(
self.pretty = pretty
self._indent = -1
self.tab_size = 4
self.timeout = timeout

def indent(self, extra: int = 0):
return " " * self.tab_size * (self._indent + extra)
Expand Down Expand Up @@ -1102,6 +1108,9 @@ def _is_nullable(self, node: ast.Expr) -> bool:
return True

def _print_settings(self, settings):
if self.timeout:
settings.max_execution_time = self.timeout

pairs = []
for key, value in settings:
if value is None:
Expand Down
1 change: 1 addition & 0 deletions posthog/hogql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def execute_hogql_query(
context=clickhouse_context,
dialect="clickhouse",
settings=settings or HogQLGlobalSettings(),
timeout=600 if in_export_context else None,
webjunkie marked this conversation as resolved.
Show resolved Hide resolved
)

timings_dict = timings.to_dict()
Expand Down
Loading