Skip to content

Commit

Permalink
fix(data-warehouse): Ensure we grab all closing brackets in regex for…
Browse files Browse the repository at this point in the history
… matching clickhouse … (#22426)

Ensure we grab all closing brackets in regex for matching clickhouse types
  • Loading branch information
Gilbert09 authored May 22, 2024
1 parent c5db2a5 commit 90155c4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion posthog/warehouse/models/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def clean_type(column_type: str) -> str:
if column_type.startswith("Array("):
column_type = remove_named_tuples(column_type)

column_type = re.sub(r"\(.+?\)", "", column_type)
column_type = re.sub(r"\(.+?\)+", "", column_type)

return column_type

Expand Down
17 changes: 17 additions & 0 deletions posthog/warehouse/models/test/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ def test_get_columns_with_nullable_and_args(self):
"id": {"clickhouse": "Nullable(DateTime(6, 'UTC'))", "hogql": "DateTimeDatabaseField", "valid": True}
}

def test_get_columns_with_complex_tuples(self):
credential = DataWarehouseCredential.objects.create(access_key="key", access_secret="secret", team=self.team)
table = DataWarehouseTable.objects.create(
name="test_table", url_pattern="", credential=credential, format="Parquet", team=self.team
)

with patch("posthog.warehouse.models.table.sync_execute") as sync_execute_results:
sync_execute_results.return_value = [["id", "Map(String, Map(String, Array(UInt64)))"]]
columns = table.get_columns()
assert columns == {
"id": {
"clickhouse": "Map(String, Map(String, Array(UInt64)))",
"hogql": "StringJSONDatabaseField",
"valid": True,
}
}

def test_hogql_definition_old_style(self):
credential = DataWarehouseCredential.objects.create(access_key="test", access_secret="test", team=self.team)
table = DataWarehouseTable.objects.create(
Expand Down

0 comments on commit 90155c4

Please sign in to comment.