|
| 1 | +from typing import Dict, List |
| 2 | +import pytest |
| 3 | + |
| 4 | +from dve.core_engine.backends.implementations.duckdb.utilities import ( |
| 5 | + expr_mapping_to_columns, |
| 6 | + expr_array_to_columns, |
| 7 | +) |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.parametrize( |
| 11 | + ["expressions", "expected"], |
| 12 | + [ |
| 13 | + ( |
| 14 | + {"size(array_field)": "field_length", "another_field": "rename_another_field"}, |
| 15 | + ["size(array_field) as field_length", "another_field as rename_another_field"], |
| 16 | + ), |
| 17 | + ], |
| 18 | +) |
| 19 | +def test_expr_mapping_to_columns(expressions: Dict[str, str], expected: list[str]): |
| 20 | + observed = expr_mapping_to_columns(expressions) |
| 21 | + assert observed == expected |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.parametrize( |
| 25 | + ["expressions", "expected"], |
| 26 | + [ |
| 27 | + ( |
| 28 | + [ |
| 29 | + "a_field", |
| 30 | + "another_field as renamed", |
| 31 | + "struct(a_field, another_field) as struct_field", |
| 32 | + ], |
| 33 | + [ |
| 34 | + "a_field", |
| 35 | + "another_field as renamed", |
| 36 | + "struct(a_field, another_field) as struct_field", |
| 37 | + ], |
| 38 | + ), |
| 39 | + ( |
| 40 | + [ |
| 41 | + "size(array_field)", |
| 42 | + "another_field as rename_another_field", |
| 43 | + "a_dynamic_field, another_dynamic_field", |
| 44 | + ], |
| 45 | + [ |
| 46 | + "size(array_field)", |
| 47 | + "another_field as rename_another_field", |
| 48 | + "a_dynamic_field", |
| 49 | + "another_dynamic_field", |
| 50 | + ], |
| 51 | + ), |
| 52 | + ], |
| 53 | +) |
| 54 | +def test_expr_array_to_columns(expressions: Dict[str, str], expected: list[str]): |
| 55 | + observed = expr_array_to_columns(expressions) |
| 56 | + assert observed == expected |
0 commit comments