Skip to content

Commit

Permalink
remove types
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra committed Nov 23, 2023
1 parent fff3448 commit eebb150
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 17 deletions.
6 changes: 1 addition & 5 deletions posthog/hogql/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions posthog/hogql/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"])

Expand Down
4 changes: 1 addition & 3 deletions posthog/hogql/database/models.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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):
Expand Down
9 changes: 2 additions & 7 deletions posthog/hogql/database/test/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit eebb150

Please sign in to comment.