From eebb15038371bde9405d37879e4f7bf51ded2519 Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Thu, 23 Nov 2023 15:18:42 +0100 Subject: [PATCH] remove types --- posthog/hogql/ast.py | 6 +----- posthog/hogql/database/database.py | 2 -- posthog/hogql/database/models.py | 4 +--- posthog/hogql/database/test/test_database.py | 9 ++------- 4 files changed, 4 insertions(+), 17 deletions(-) diff --git a/posthog/hogql/ast.py b/posthog/hogql/ast.py index 99bf5083fd6c3..f0dd85a127db5 100644 --- a/posthog/hogql/ast.py +++ b/posthog/hogql/ast.py @@ -70,7 +70,7 @@ def get_child(self, name: str) -> Type: if isinstance(field, VirtualTable): return VirtualTableType(table_type=self, field=name, virtual_table=field) if isinstance(field, ExpressionField): - return ExpressionFieldType(table_type=self, name=name, expr=field.expr, return_type=field.return_type) + return ExpressionFieldType(table_type=self, name=name, expr=field.expr) return FieldType(name=name, table_type=self) raise HogQLException(f"Field not found: {name}") @@ -290,10 +290,6 @@ class ExpressionFieldType(Type): name: str expr: Expr table_type: TableOrSelectType - return_type: Optional[ConstantType] - - def resolve_constant_type(self) -> Optional["ConstantType"]: - return self.return_type or super().resolve_constant_type() @dataclass(kw_only=True) diff --git a/posthog/hogql/database/database.py b/posthog/hogql/database/database.py index a7a21e91279c8..18dee90dd1928 100644 --- a/posthog/hogql/database/database.py +++ b/posthog/hogql/database/database.py @@ -123,7 +123,6 @@ def add_warehouse_tables(self, **field_definitions: Any): def create_hogql_database(team_id: int, modifiers: Optional[HogQLQueryModifiers] = None) -> Database: from posthog.models import Team from posthog.hogql.query import create_default_modifiers_for_team - from posthog.hogql.ast import UUIDType from posthog.warehouse.models import ( DataWarehouseTable, DataWarehouseSavedQuery, @@ -161,7 +160,6 @@ def create_hogql_database(team_id: int, modifiers: Optional[HogQLQueryModifiers] database.events.fields["person_id"] = ExpressionField( name="person_id", expr=parse_expr("ifNull(override.override_person_id, event_person_id)", start=None), - return_type=UUIDType(), ) database.events.fields["person"] = FieldTraverser(chain=["poe"]) diff --git a/posthog/hogql/database/models.py b/posthog/hogql/database/models.py index 3e7c0cf048e97..b669a279b5975 100644 --- a/posthog/hogql/database/models.py +++ b/posthog/hogql/database/models.py @@ -1,7 +1,7 @@ from typing import Any, Callable, Dict, List, Optional, TYPE_CHECKING from pydantic import ConfigDict, BaseModel -from posthog.hogql.base import Expr, ConstantType +from posthog.hogql.base import Expr from posthog.hogql.errors import HogQLException, NotImplementedException from posthog.schema import HogQLQueryModifiers @@ -60,8 +60,6 @@ class BooleanDatabaseField(DatabaseField): class ExpressionField(DatabaseField): expr: Expr - # we should calculate this automatically, eventually... for now we need to help the compiler - return_type: Optional[ConstantType] = None class FieldTraverser(FieldOrTable): diff --git a/posthog/hogql/database/test/test_database.py b/posthog/hogql/database/test/test_database.py index 93063b1485850..c14d39fbe54bc 100644 --- a/posthog/hogql/database/test/test_database.py +++ b/posthog/hogql/database/test/test_database.py @@ -6,7 +6,6 @@ from django.test import override_settings from parameterized import parameterized -from posthog.hogql.ast import IntegerType from posthog.hogql.database.database import create_hogql_database, serialize_database from posthog.hogql.database.models import FieldTraverser, StringDatabaseField, ExpressionField from posthog.hogql.modifiers import create_default_modifiers_for_team @@ -88,12 +87,8 @@ def test_database_group_type_mappings_overwrite(self): def test_database_expression_fields(self): db = create_hogql_database(team_id=self.team.pk) - db.numbers.fields["expression"] = ExpressionField( - name="expression", expr=parse_expr("1 + 1"), return_type=IntegerType() - ) - db.numbers.fields["double"] = ExpressionField( - name="double", expr=parse_expr("number * 2"), return_type=IntegerType() - ) + db.numbers.fields["expression"] = ExpressionField(name="expression", expr=parse_expr("1 + 1")) + db.numbers.fields["double"] = ExpressionField(name="double", expr=parse_expr("number * 2")) context = HogQLContext( team_id=self.team.pk, enable_select_queries=True,