From 65077a3dc4ac414209538417bde57dd9e23e9aea Mon Sep 17 00:00:00 2001 From: timgl Date: Wed, 11 Dec 2024 13:19:38 +0000 Subject: [PATCH] fix(hogql): use correct toDecimal function (#26826) --- posthog/hogql/functions/mapping.py | 2 +- posthog/hogql/test/test_printer.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/posthog/hogql/functions/mapping.py b/posthog/hogql/functions/mapping.py index a422e16dc989c..43c9bb4e7c150 100644 --- a/posthog/hogql/functions/mapping.py +++ b/posthog/hogql/functions/mapping.py @@ -398,7 +398,7 @@ def compare_types(arg_types: list[ConstantType], sig_arg_types: tuple[ConstantTy "_toUInt64": HogQLFunctionMeta("toUInt64", 1, 1, signatures=[((UnknownType(),), IntegerType())]), "_toUInt128": HogQLFunctionMeta("toUInt128", 1, 1), "toFloat": HogQLFunctionMeta("accurateCastOrNull", 1, 1, suffix_args=[ast.Constant(value="Float64")]), - "toDecimal": HogQLFunctionMeta("accurateCastOrNull", 1, 1, suffix_args=[ast.Constant(value="Decimal64")]), + "toDecimal": HogQLFunctionMeta("toDecimal64OrNull", 2, 2), "toDate": HogQLFunctionMeta( "toDateOrNull", 1, diff --git a/posthog/hogql/test/test_printer.py b/posthog/hogql/test/test_printer.py index 4f2422263d0c8..dc5a1b3831e46 100644 --- a/posthog/hogql/test/test_printer.py +++ b/posthog/hogql/test/test_printer.py @@ -846,9 +846,7 @@ def test_functions(self): self._expr("toUUID('470f9b15-ff43-402a-af9f-2ed7c526a6cf')", context), "accurateCastOrNull(%(hogql_val_4)s, %(hogql_val_5)s)", ) - self.assertEqual( - self._expr("toDecimal('3.14')", context), "accurateCastOrNull(%(hogql_val_6)s, %(hogql_val_7)s)" - ) + self.assertEqual(self._expr("toDecimal('3.14', 2)", context), "toDecimal64OrNull(%(hogql_val_6)s, 2)") self.assertEqual(self._expr("quantile(0.95)( event )"), "quantile(0.95)(events.event)") def test_expr_parse_errors(self):