Skip to content

Commit

Permalink
revert: perf: use elements chain materialization (#23934)
Browse files Browse the repository at this point in the history
  • Loading branch information
timgl authored Jul 24, 2024
1 parent 9ee8309 commit 967eb55
Show file tree
Hide file tree
Showing 12 changed files with 285 additions and 1,133 deletions.
1 change: 0 additions & 1 deletion ee/clickhouse/materialized_columns/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def get_materialized_columns(
WHERE database = %(database)s
AND table = %(table)s
AND comment LIKE '%%column_materializer::%%'
AND comment not LIKE '%%column_materializer::elements_chain::%%'
""",
{"database": CLICKHOUSE_DATABASE, "table": table},
)
Expand Down
3 changes: 3 additions & 0 deletions mypy-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ posthog/models/property/util.py:0: error: Argument 1 to "append" of "list" has i
posthog/models/property/util.py:0: error: Argument 1 to "append" of "list" has incompatible type "str | int"; expected "str" [arg-type]
posthog/models/property/util.py:0: error: Argument 1 to "append" of "list" has incompatible type "str | int"; expected "str" [arg-type]
posthog/queries/trends/util.py:0: error: Argument 1 to "translate_hogql" has incompatible type "str | None"; expected "str" [arg-type]
posthog/hogql/property.py:0: error: Argument "chain" to "Field" has incompatible type "list[str]"; expected "list[str | int]" [arg-type]
posthog/hogql/property.py:0: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
posthog/hogql/property.py:0: note: Consider using "Sequence" instead, which is covariant
posthog/hogql/property.py:0: error: Incompatible type for lookup 'id': (got "str | int | list[str]", expected "str | int") [misc]
posthog/hogql/property.py:0: error: Incompatible type for lookup 'pk': (got "str | float", expected "str | int") [misc]
posthog/hogql/filters.py:0: error: Incompatible default for argument "team" (default has type "None", argument has type "Team") [assignment]
Expand Down
4 changes: 4 additions & 0 deletions posthog/api/test/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def test_update_action(self, patch_capture, *args):
action = Action.objects.create(
name="user signed up", team=self.team, steps_json=[{"event": "$autocapture", "text": "sign me up!"}]
)
action.refresh_bytecode()
action.save()
previous_bytecode = action.bytecode

response = self.client.patch(
f"/api/projects/{self.team.id}/actions/{action.pk}/",
Expand Down Expand Up @@ -196,6 +198,8 @@ def test_update_action(self, patch_capture, *args):
action.refresh_from_db()
assert action.name == "user signed up 2"

assert previous_bytecode != action.bytecode

# Assert analytics are sent
patch_capture.assert_called_with(
user,
Expand Down
20 changes: 8 additions & 12 deletions posthog/clickhouse/test/__snapshots__/test_schema.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,6 @@
, $group_4 VARCHAR COMMENT 'column_materializer::$group_4'
, $window_id VARCHAR COMMENT 'column_materializer::$window_id'
, $session_id VARCHAR COMMENT 'column_materializer::$session_id'
, elements_chain_href String COMMENT 'column_materializer::elements_chain::href'
, elements_chain_texts Array(String) COMMENT 'column_materializer::elements_chain::texts'
, elements_chain_ids Array(String) COMMENT 'column_materializer::elements_chain::ids'
, elements_chain_elements Array(Enum('a', 'button', 'form', 'input', 'select', 'textarea', 'label')) COMMENT 'column_materializer::elements_chain::elements'


, _timestamp DateTime
Expand Down Expand Up @@ -2177,17 +2173,17 @@
, $group_4 VARCHAR MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^"|"$', '') COMMENT 'column_materializer::$group_4'
, $window_id VARCHAR MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$window_id'), '^"|"$', '') COMMENT 'column_materializer::$window_id'
, $session_id VARCHAR MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^"|"$', '') COMMENT 'column_materializer::$session_id'
, elements_chain_href String MATERIALIZED extract(elements_chain, '(?::|")href="(.*?)"')
, elements_chain_texts Array(String) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?::|")text="(.*?)"'))
, elements_chain_ids Array(String) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?::|")attr_id="(.*?)"'))
, elements_chain_elements Array(Enum('a', 'button', 'form', 'input', 'select', 'textarea', 'label')) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?:^|;)(a|button|form|input|select|textarea|label)(?:\.|$|:)'))
, INDEX `minmax_$group_0` `$group_0` TYPE minmax GRANULARITY 1
, INDEX `minmax_$group_1` `$group_1` TYPE minmax GRANULARITY 1
, INDEX `minmax_$group_2` `$group_2` TYPE minmax GRANULARITY 1
, INDEX `minmax_$group_3` `$group_3` TYPE minmax GRANULARITY 1
, INDEX `minmax_$group_4` `$group_4` TYPE minmax GRANULARITY 1
, INDEX `minmax_$window_id` `$window_id` TYPE minmax GRANULARITY 1
, INDEX `minmax_$session_id` `$session_id` TYPE minmax GRANULARITY 1
, elements_chain_href String MATERIALIZED extract(elements_chain, '(?::|")href="(.*?)"')
, elements_chain_texts Array(String) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?::|")text="(.*?)"'))
, elements_chain_ids Array(String) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?::|")attr_id="(.*?)"'))
, elements_chain_elements Array(Enum('a', 'button', 'form', 'input', 'select', 'textarea', 'label')) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?:^|;)(a|button|form|input|select|textarea|label)(?:\.|$|:)'))


, _timestamp DateTime
Expand Down Expand Up @@ -3271,17 +3267,17 @@
, $group_4 VARCHAR MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$group_4'), '^"|"$', '') COMMENT 'column_materializer::$group_4'
, $window_id VARCHAR MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$window_id'), '^"|"$', '') COMMENT 'column_materializer::$window_id'
, $session_id VARCHAR MATERIALIZED replaceRegexpAll(JSONExtractRaw(properties, '$session_id'), '^"|"$', '') COMMENT 'column_materializer::$session_id'
, elements_chain_href String MATERIALIZED extract(elements_chain, '(?::|")href="(.*?)"')
, elements_chain_texts Array(String) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?::|")text="(.*?)"'))
, elements_chain_ids Array(String) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?::|")attr_id="(.*?)"'))
, elements_chain_elements Array(Enum('a', 'button', 'form', 'input', 'select', 'textarea', 'label')) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?:^|;)(a|button|form|input|select|textarea|label)(?:\.|$|:)'))
, INDEX `minmax_$group_0` `$group_0` TYPE minmax GRANULARITY 1
, INDEX `minmax_$group_1` `$group_1` TYPE minmax GRANULARITY 1
, INDEX `minmax_$group_2` `$group_2` TYPE minmax GRANULARITY 1
, INDEX `minmax_$group_3` `$group_3` TYPE minmax GRANULARITY 1
, INDEX `minmax_$group_4` `$group_4` TYPE minmax GRANULARITY 1
, INDEX `minmax_$window_id` `$window_id` TYPE minmax GRANULARITY 1
, INDEX `minmax_$session_id` `$session_id` TYPE minmax GRANULARITY 1
, elements_chain_href String MATERIALIZED extract(elements_chain, '(?::|")href="(.*?)"')
, elements_chain_texts Array(String) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?::|")text="(.*?)"'))
, elements_chain_ids Array(String) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?::|")attr_id="(.*?)"'))
, elements_chain_elements Array(Enum('a', 'button', 'form', 'input', 'select', 'textarea', 'label')) MATERIALIZED arrayDistinct(extractAll(elements_chain, '(?:^|;)(a|button|form|input|select|textarea|label)(?:\.|$|:)'))


, _timestamp DateTime
Expand Down
5 changes: 0 additions & 5 deletions posthog/hogql/database/schema/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
StringDatabaseField,
DateTimeDatabaseField,
StringJSONDatabaseField,
StringArrayDatabaseField,
IntegerDatabaseField,
Table,
LazyJoin,
Expand Down Expand Up @@ -115,10 +114,6 @@ class EventsTable(Table):
join_table=SessionsTableV1(),
join_function=join_events_table_to_sessions_table,
),
"elements_chain_href": StringDatabaseField(name="elements_chain_href"),
"elements_chain_texts": StringArrayDatabaseField(name="elements_chain_texts"),
"elements_chain_ids": StringArrayDatabaseField(name="elements_chain_ids"),
"elements_chain_elements": StringArrayDatabaseField(name="elements_chain_elements"),
}

def to_printed_clickhouse(self, context):
Expand Down
84 changes: 2 additions & 82 deletions posthog/hogql/database/test/__snapshots__/test_database.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -377,42 +377,6 @@
"schema_valid": true,
"table": "sessions",
"type": "lazy_table"
},
"elements_chain_href": {
"chain": null,
"fields": null,
"hogql_value": "elements_chain_href",
"name": "elements_chain_href",
"schema_valid": true,
"table": null,
"type": "string"
},
"elements_chain_texts": {
"chain": null,
"fields": null,
"hogql_value": "elements_chain_texts",
"name": "elements_chain_texts",
"schema_valid": true,
"table": null,
"type": "array"
},
"elements_chain_ids": {
"chain": null,
"fields": null,
"hogql_value": "elements_chain_ids",
"name": "elements_chain_ids",
"schema_valid": true,
"table": null,
"type": "array"
},
"elements_chain_elements": {
"chain": null,
"fields": null,
"hogql_value": "elements_chain_elements",
"name": "elements_chain_elements",
"schema_valid": true,
"table": null,
"type": "array"
}
},
"id": "events",
Expand Down Expand Up @@ -748,11 +712,7 @@
"group_3",
"$group_4",
"group_4",
"session",
"elements_chain_href",
"elements_chain_texts",
"elements_chain_ids",
"elements_chain_elements"
"session"
],
"hogql_value": "events",
"name": "events",
Expand Down Expand Up @@ -1734,42 +1694,6 @@
"schema_valid": true,
"table": "sessions",
"type": "lazy_table"
},
"elements_chain_href": {
"chain": null,
"fields": null,
"hogql_value": "elements_chain_href",
"name": "elements_chain_href",
"schema_valid": true,
"table": null,
"type": "string"
},
"elements_chain_texts": {
"chain": null,
"fields": null,
"hogql_value": "elements_chain_texts",
"name": "elements_chain_texts",
"schema_valid": true,
"table": null,
"type": "array"
},
"elements_chain_ids": {
"chain": null,
"fields": null,
"hogql_value": "elements_chain_ids",
"name": "elements_chain_ids",
"schema_valid": true,
"table": null,
"type": "array"
},
"elements_chain_elements": {
"chain": null,
"fields": null,
"hogql_value": "elements_chain_elements",
"name": "elements_chain_elements",
"schema_valid": true,
"table": null,
"type": "array"
}
},
"id": "events",
Expand Down Expand Up @@ -2105,11 +2029,7 @@
"group_3",
"$group_4",
"group_4",
"session",
"elements_chain_href",
"elements_chain_texts",
"elements_chain_ids",
"elements_chain_elements"
"session"
],
"hogql_value": "events",
"name": "events",
Expand Down
Loading

0 comments on commit 967eb55

Please sign in to comment.