TobikoData / sqlmesh

Efficient data transformation and modeling framework that is backwards compatible with dbt.
https://sqlmesh.com
Apache License 2.0
1.78k stars 156 forks source link

Support array of nested data in tests' YAML #3115

Closed giovannipcarvalho closed 1 month ago

giovannipcarvalho commented 1 month ago

Hi!

I am aware that support for nested data/dictionaries was added in #2264.

I have a model in which a column is an array of structs, and currently this seems to be unsupported. Are there plans to support it? Happy to contribute a patch, but would need some guidance.

Here's a failing test case to demonstrate the scenario:

def test_array_of_nested_data() -> None:
    _check_successful_or_raise(
        _create_test(
            body=load_yaml(
                """
test_foo:
  model: foo
  inputs:
    ext:
      columns:
        col: "ARRAY<STRUCT<k VARCHAR, v STRUCT<v_str VARCHAR, v_int INT>>>"
      rows:
        - col: [{'k': 'hello', 'v': {'v_str': 'there', 'v_int': 10}}]
  outputs:
    query:
      rows:
        - col: [{'k': 'hello', 'v': {'v_str': 'there', 'v_int': 10}}]
                """
            ),
            test_name="test_foo",
            model=_create_model("SELECT col FROM ext"),
            context=Context(config=Config(model_defaults=ModelDefaultsConfig(dialect="duckdb"))),
        ).run()
    )
λ pytest tests/core/test_test.py::test_array_of_nested_data
[...]
E               duckdb.duckdb.ConversionException: Conversion Error: Type VARCHAR with value 'hello' can't be cast to the destination type MAP

If you remove the ARRAY<> annotation, and the [] from the test data, then the test passes -- which is what the previous patch (#2264) is supposed to cover, I believe.

λ pytest tests/core/test_test.py::test_array_of_nested_data -q
[...]
1 passed, 124 warnings in 0.06s
izeigerman commented 1 month ago

@georgesittas can you please confirm whether this is expected

georgesittas commented 1 month ago

This certainly doesn't seem expected - I think I know what's up. I'll take a stab at fixing it!