|
1 | 1 | import pytest |
2 | 2 |
|
| 3 | +from pyathena.arrow.converter import DefaultArrowUnloadTypeConverter |
3 | 4 | from pyathena.converter import ( |
4 | 5 | DefaultTypeConverter, |
5 | 6 | _to_array, |
6 | 7 | _to_map, |
7 | 8 | _to_struct, |
8 | 9 | ) |
| 10 | +from pyathena.pandas.converter import DefaultPandasTypeConverter, DefaultPandasUnloadTypeConverter |
| 11 | +from pyathena.polars.converter import DefaultPolarsUnloadTypeConverter |
9 | 12 |
|
10 | 13 |
|
11 | 14 | @pytest.mark.parametrize( |
@@ -408,3 +411,78 @@ def test_hive_syntax_caching(self): |
408 | 411 | # Both should normalize to "array(integer)" in the cache |
409 | 412 | assert "array(integer)" in converter._parsed_hints |
410 | 413 | assert len(converter._parsed_hints) == 1 |
| 414 | + |
| 415 | + def test_normalize_hive_syntax_noop(self): |
| 416 | + """Trino-style input passes through unchanged.""" |
| 417 | + assert DefaultTypeConverter._normalize_hive_syntax("array(integer)") == "array(integer)" |
| 418 | + |
| 419 | + def test_normalize_hive_syntax_replaces(self): |
| 420 | + assert ( |
| 421 | + DefaultTypeConverter._normalize_hive_syntax("array<struct<a:int>>") |
| 422 | + == "array(struct(a int))" |
| 423 | + ) |
| 424 | + |
| 425 | + def test_normalize_hive_syntax_struct(self): |
| 426 | + converter = DefaultTypeConverter() |
| 427 | + result = converter.convert( |
| 428 | + "row", |
| 429 | + "{name=Alice, age=25}", |
| 430 | + type_hint="struct<name:varchar,age:int>", |
| 431 | + ) |
| 432 | + assert result == {"name": "Alice", "age": 25} |
| 433 | + |
| 434 | + def test_normalize_hive_syntax_nested(self): |
| 435 | + converter = DefaultTypeConverter() |
| 436 | + result = converter.convert( |
| 437 | + "array", |
| 438 | + "[{a=1, b=hello}, {a=2, b=world}]", |
| 439 | + type_hint="array<struct<a:int,b:varchar>>", |
| 440 | + ) |
| 441 | + assert result == [{"a": 1, "b": "hello"}, {"a": 2, "b": "world"}] |
| 442 | + |
| 443 | + def test_normalize_hive_syntax_map(self): |
| 444 | + converter = DefaultTypeConverter() |
| 445 | + result = converter.convert( |
| 446 | + "map", |
| 447 | + '{"x": 1, "y": 2}', |
| 448 | + type_hint="map<string,int>", |
| 449 | + ) |
| 450 | + assert result == {"x": 1, "y": 2} |
| 451 | + |
| 452 | + def test_normalize_hive_syntax_mixed(self): |
| 453 | + """Hive angle brackets wrapping Trino-style parenthesized inner type.""" |
| 454 | + converter = DefaultTypeConverter() |
| 455 | + result = converter.convert( |
| 456 | + "array", |
| 457 | + "[{a=1, b=hello}]", |
| 458 | + type_hint="array<row(a int, b varchar)>", |
| 459 | + ) |
| 460 | + assert result == [{"a": 1, "b": "hello"}] |
| 461 | + |
| 462 | + |
| 463 | +class TestConverterPassStubFix: |
| 464 | + """Verify that converters previously stubbed with pass now delegate correctly.""" |
| 465 | + |
| 466 | + def test_pandas_converter_returns_value(self): |
| 467 | + converter = DefaultPandasTypeConverter() |
| 468 | + assert converter.convert("boolean", "true") is True |
| 469 | + |
| 470 | + def test_pandas_converter_default_passthrough(self): |
| 471 | + converter = DefaultPandasTypeConverter() |
| 472 | + assert converter.convert("varchar", "hello") == "hello" |
| 473 | + |
| 474 | + def test_pandas_unload_converter_returns_value(self): |
| 475 | + converter = DefaultPandasUnloadTypeConverter() |
| 476 | + assert converter.convert("varchar", "hello") == "hello" |
| 477 | + |
| 478 | + def test_arrow_unload_converter_returns_value(self): |
| 479 | + converter = DefaultArrowUnloadTypeConverter() |
| 480 | + assert converter.convert("varchar", "hello") == "hello" |
| 481 | + |
| 482 | + def test_polars_unload_converter_returns_value(self): |
| 483 | + converter = DefaultPolarsUnloadTypeConverter() |
| 484 | + assert converter.convert("varchar", "hello") == "hello" |
| 485 | + |
| 486 | + def test_pandas_converter_none_value(self): |
| 487 | + converter = DefaultPandasTypeConverter() |
| 488 | + assert converter.convert("varchar", None) is None |
0 commit comments