Skip to content

Commit

Permalink
chore(hogql): Use the C++ parser in local dev (#18112)
Browse files Browse the repository at this point in the history
* chore(hogql): Use the C++ parser in local dev

* Update all the parsing functions, not just `parse_select`
  • Loading branch information
Twixes authored Oct 20, 2023
1 parent 930db7f commit 85a0d3d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions posthog/hogql/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"):
Expand All @@ -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}"):
Expand All @@ -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}"):
Expand Down

0 comments on commit 85a0d3d

Please sign in to comment.