Commit b46634c
authored
fix: PostgreSQL dialect can not support tinyint type (#21445)
## Which issue does this PR close?
- No linked issue.
## Rationale for this change
DataFusion's PostgreSQL unparser should emit PostgreSQL-compatible SQL
for integer casts.`Int8` was still being rendered as `TINYINT`, which is
not valid PostgreSQL syntax. This change makes PostgreSQL output
`SMALLINT` instead.
## What changes are included in this PR?
- Added an `int8_cast_dtype` hook to the SQL unparser dialect
abstraction.
- Updated `PostgreSqlDialect` to map `Int8` to `SMALLINT`.
- Routed `DataType::Int8` unparsing through the dialect hook.
- Added a regression test covering `select cast(3 as tinyint)]` with
PostgreSQL unparser output.
## Are these changes tested?
- Yes. Ran:
- `cargo test -p datafusion-sql --test sql_integration
cases::plan_to_sql::test_cast_to_tinyint -- --exact`
- The test passes.
## Are there any user-facing changes?
- Yes. PostgreSQL dialect SQL generation now renders `CAST(... AS
SMALLINT)` for `Int8` values instead of `CAST(... AS TINYINT)`.1 parent 4389f14 commit b46634c
File tree
3 files changed
+48
-1
lines changed- datafusion/sql
- src/unparser
- tests/cases
3 files changed
+48
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
103 | 109 | | |
104 | 110 | | |
105 | 111 | | |
| |||
345 | 351 | | |
346 | 352 | | |
347 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
348 | 358 | | |
349 | 359 | | |
350 | 360 | | |
| |||
664 | 674 | | |
665 | 675 | | |
666 | 676 | | |
| 677 | + | |
667 | 678 | | |
668 | 679 | | |
669 | 680 | | |
| |||
689 | 700 | | |
690 | 701 | | |
691 | 702 | | |
| 703 | + | |
692 | 704 | | |
693 | 705 | | |
694 | 706 | | |
| |||
748 | 760 | | |
749 | 761 | | |
750 | 762 | | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
751 | 767 | | |
752 | 768 | | |
753 | 769 | | |
| |||
839 | 855 | | |
840 | 856 | | |
841 | 857 | | |
| 858 | + | |
842 | 859 | | |
843 | 860 | | |
844 | 861 | | |
| |||
870 | 887 | | |
871 | 888 | | |
872 | 889 | | |
| 890 | + | |
873 | 891 | | |
874 | 892 | | |
875 | 893 | | |
| |||
898 | 916 | | |
899 | 917 | | |
900 | 918 | | |
| 919 | + | |
901 | 920 | | |
902 | 921 | | |
903 | 922 | | |
| |||
952 | 971 | | |
953 | 972 | | |
954 | 973 | | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
955 | 980 | | |
956 | 981 | | |
957 | 982 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1734 | 1734 | | |
1735 | 1735 | | |
1736 | 1736 | | |
1737 | | - | |
| 1737 | + | |
1738 | 1738 | | |
1739 | 1739 | | |
1740 | 1740 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1937 | 1937 | | |
1938 | 1938 | | |
1939 | 1939 | | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
| 1944 | + | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
1940 | 1962 | | |
1941 | 1963 | | |
1942 | 1964 | | |
| |||
0 commit comments