Commit ac5fce4
[SPARK-51920][SS][PYTHON] Fix type handling of namedTuple for transfromWithState
### What changes were proposed in this pull request?
Fix type handling of namedTuple for transfromWithState
### Why are the changes needed?
We hit the issue when using namedTuple as value of structType like
```
class Person(NamedTuple):
age: Integer
name: String
def handleInputRows(
self,
key: Any,
rows: Iterator[Row],
timerValues: TimerValues
) -> Iterator[Row]:
person: Person = Person(age = 1, name= "peter")
person_list = []
person_list.append(person)
self.person_list.update((person_list,))
```
The `_serialize_to_bytes` cannot construct the namedTuple correctly and hit
```
File "/databricks/spark/python/pyspark/sql/streaming/stateful_processor_api_client.py", line 575, in normalize_value
return type(v)(normalize_value(e) for e in v)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Person.__new__() missing 2 required positional arguments: 'age' and 'name'
```
It's because NamedTuple cannot accept generator as parameter.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
UT
### Was this patch authored or co-authored using generative AI tooling?
No
Closes #53314 from zeruibao/zeruibao/SPARK-5192-fix-namedtuple-type.
Lead-authored-by: zeruibao <[email protected]>
Co-authored-by: Zerui Bao <[email protected]>
Signed-off-by: Jungtaek Lim <[email protected]>1 parent ca17514 commit ac5fce4
File tree
2 files changed
+59
-13
lines changed- python/pyspark/sql
- streaming
- tests/pandas/helper
2 files changed
+59
-13
lines changedLines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
501 | 501 | | |
502 | 502 | | |
503 | 503 | | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
504 | 509 | | |
505 | 510 | | |
506 | 511 | | |
| |||
Lines changed: 54 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
| |||
1663 | 1666 | | |
1664 | 1667 | | |
1665 | 1668 | | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
1666 | 1673 | | |
1667 | 1674 | | |
1668 | 1675 | | |
1669 | 1676 | | |
| 1677 | + | |
1670 | 1678 | | |
1671 | 1679 | | |
1672 | 1680 | | |
| |||
1681 | 1689 | | |
1682 | 1690 | | |
1683 | 1691 | | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
1684 | 1703 | | |
1685 | 1704 | | |
1686 | 1705 | | |
| |||
1700 | 1719 | | |
1701 | 1720 | | |
1702 | 1721 | | |
1703 | | - | |
| 1722 | + | |
1704 | 1723 | | |
1705 | 1724 | | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
1706 | 1728 | | |
1707 | 1729 | | |
1708 | 1730 | | |
1709 | | - | |
| 1731 | + | |
1710 | 1732 | | |
1711 | 1733 | | |
1712 | 1734 | | |
1713 | 1735 | | |
1714 | 1736 | | |
1715 | | - | |
| 1737 | + | |
1716 | 1738 | | |
1717 | | - | |
| 1739 | + | |
1718 | 1740 | | |
1719 | 1741 | | |
1720 | 1742 | | |
1721 | | - | |
| 1743 | + | |
1722 | 1744 | | |
1723 | 1745 | | |
1724 | 1746 | | |
| |||
1736 | 1758 | | |
1737 | 1759 | | |
1738 | 1760 | | |
1739 | | - | |
| 1761 | + | |
1740 | 1762 | | |
1741 | 1763 | | |
1742 | 1764 | | |
| |||
1767 | 1789 | | |
1768 | 1790 | | |
1769 | 1791 | | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
1770 | 1796 | | |
1771 | 1797 | | |
1772 | 1798 | | |
1773 | 1799 | | |
| 1800 | + | |
1774 | 1801 | | |
1775 | 1802 | | |
1776 | 1803 | | |
| |||
1785 | 1812 | | |
1786 | 1813 | | |
1787 | 1814 | | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
1788 | 1826 | | |
1789 | 1827 | | |
1790 | 1828 | | |
| |||
1804 | 1842 | | |
1805 | 1843 | | |
1806 | 1844 | | |
1807 | | - | |
| 1845 | + | |
1808 | 1846 | | |
1809 | 1847 | | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
1810 | 1851 | | |
1811 | 1852 | | |
1812 | 1853 | | |
1813 | | - | |
| 1854 | + | |
1814 | 1855 | | |
1815 | 1856 | | |
1816 | 1857 | | |
1817 | 1858 | | |
1818 | 1859 | | |
1819 | | - | |
| 1860 | + | |
1820 | 1861 | | |
1821 | | - | |
| 1862 | + | |
1822 | 1863 | | |
1823 | 1864 | | |
1824 | 1865 | | |
1825 | | - | |
| 1866 | + | |
1826 | 1867 | | |
1827 | 1868 | | |
1828 | 1869 | | |
| |||
1840 | 1881 | | |
1841 | 1882 | | |
1842 | 1883 | | |
1843 | | - | |
| 1884 | + | |
1844 | 1885 | | |
1845 | 1886 | | |
1846 | 1887 | | |
| |||
0 commit comments