Skip to content

Commit 62fd255

Browse files
authored
fix: ignore constraints in dbt seed column types (#5535)
1 parent 2dd01a4 commit 62fd255

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies = [
2424
"requests",
2525
"rich[jupyter]",
2626
"ruamel.yaml",
27-
"sqlglot[rs]~=27.24.2",
27+
"sqlglot[rs]~=27.27.0",
2828
"tenacity",
2929
"time-machine",
3030
"json-stream"

sqlmesh/dbt/column.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import typing as t
4+
import logging
45

56
from sqlglot import exp, parse_one
67
from sqlglot.helper import ensure_list
@@ -9,6 +10,8 @@
910
from sqlmesh.utils.conversions import ensure_bool
1011
from sqlmesh.utils.pydantic import field_validator
1112

13+
logger = logging.getLogger(__name__)
14+
1215

1316
def yaml_to_columns(
1417
yaml: t.Dict[str, ColumnConfig] | t.List[t.Dict[str, ColumnConfig]],
@@ -31,11 +34,20 @@ def column_types_to_sqlmesh(
3134
Returns:
3235
A dict of column name to exp.DataType
3336
"""
34-
return {
35-
name: parse_one(column.data_type, into=exp.DataType, dialect=dialect or "")
36-
for name, column in columns.items()
37-
if column.enabled and column.data_type
38-
}
37+
col_types_to_sqlmesh: t.Dict[str, exp.DataType] = {}
38+
for name, column in columns.items():
39+
if column.enabled and column.data_type:
40+
column_def = parse_one(
41+
f"{name} {column.data_type}", into=exp.ColumnDef, dialect=dialect or ""
42+
)
43+
if column_def.args.get("constraints"):
44+
logger.warning(
45+
f"Ignoring unsupported constraints for column '{name}' with definition '{column.data_type}'. Please refer to github.com/TobikoData/sqlmesh/issues/4717 for more information."
46+
)
47+
kind = column_def.kind
48+
if kind:
49+
col_types_to_sqlmesh[name] = kind
50+
return col_types_to_sqlmesh
3951

4052

4153
def column_descriptions_to_sqlmesh(columns: t.Dict[str, ColumnConfig]) -> t.Dict[str, str]:

tests/dbt/test_transformation.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,28 @@ def test_seed_column_types():
841841
sqlmesh_seed = seed.to_sqlmesh(context)
842842
assert sqlmesh_seed.columns_to_types == expected_column_types
843843

844+
seed = SeedConfig(
845+
name="foo",
846+
package="package",
847+
path=Path("examples/sushi_dbt/seeds/waiter_names.csv"),
848+
column_types={
849+
"id": "TEXT",
850+
"name": "TEXT NOT NULL",
851+
},
852+
quote_columns=True,
853+
)
854+
855+
expected_column_types = {
856+
"id": exp.DataType.build("text"),
857+
"name": exp.DataType.build("text"),
858+
}
859+
860+
logger = logging.getLogger("sqlmesh.dbt.column")
861+
with patch.object(logger, "warning") as mock_logger:
862+
sqlmesh_seed = seed.to_sqlmesh(context)
863+
assert "Ignoring unsupported constraints" in mock_logger.call_args[0][0]
864+
assert sqlmesh_seed.columns_to_types == expected_column_types
865+
844866

845867
def test_seed_column_inference(tmp_path):
846868
seed_csv = tmp_path / "seed.csv"

0 commit comments

Comments
 (0)