From 85a0d3dbb20e5f4ad59fbf53b183934d2af46164 Mon Sep 17 00:00:00 2001 From: Michael Matloka Date: Fri, 20 Oct 2023 11:44:51 +0200 Subject: [PATCH] chore(hogql): Use the C++ parser in local dev (#18112) * chore(hogql): Use the C++ parser in local dev * Update all the parsing functions, not just `parse_select` --- posthog/hogql/parser.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/posthog/hogql/parser.py b/posthog/hogql/parser.py index 132755d01026c..cacae5eefec95 100644 --- a/posthog/hogql/parser.py +++ b/posthog/hogql/parser.py @@ -2,6 +2,7 @@ from antlr4 import CommonTokenStream, InputStream, ParseTreeVisitor, ParserRuleContext from antlr4.error.ErrorListener import ErrorListener +from django.conf import settings from posthog.hogql import ast from posthog.hogql.base import AST @@ -38,8 +39,11 @@ def parse_expr( start: Optional[int] = 0, timings: Optional[HogQLTimings] = None, *, - backend: Literal["python", "cpp"] = "python", + backend: Optional[Literal["python", "cpp"]] = None, ) -> ast.Expr: + if not backend: + # TODO: Switch over to C++ in production once we are confident there are no issues + backend = "cpp" if settings.DEBUG else "python" if timings is None: timings = HogQLTimings() with timings.measure(f"parse_expr_{backend}"): @@ -55,8 +59,11 @@ def parse_order_expr( placeholders: Optional[Dict[str, ast.Expr]] = None, timings: Optional[HogQLTimings] = None, *, - backend: Literal["python", "cpp"] = "python", + backend: Optional[Literal["python", "cpp"]] = None, ) -> ast.Expr: + if not backend: + # TODO: Switch over to C++ in production once we are confident there are no issues + backend = "cpp" if settings.DEBUG else "python" if timings is None: timings = HogQLTimings() with timings.measure(f"parse_order_expr_{backend}"): @@ -72,8 +79,11 @@ def parse_select( placeholders: Optional[Dict[str, ast.Expr]] = None, timings: Optional[HogQLTimings] = None, *, - backend: Literal["python", "cpp"] = "python", + backend: Optional[Literal["python", "cpp"]] = None, ) -> ast.SelectQuery | ast.SelectUnionQuery: + if not backend: + # TODO: Switch over to C++ in production once we are confident there are no issues + backend = "cpp" if settings.DEBUG else "python" if timings is None: timings = HogQLTimings() with timings.measure(f"parse_select_{backend}"):