|
20 | 20 | import random |
21 | 21 | import time |
22 | 22 | from datetime import date, datetime, timedelta |
| 23 | +from decimal import Decimal |
23 | 24 | from pathlib import Path |
24 | 25 | from typing import Any, Dict |
25 | 26 | from urllib.parse import urlparse |
|
50 | 51 | from pyiceberg.transforms import DayTransform, HourTransform, IdentityTransform |
51 | 52 | from pyiceberg.types import ( |
52 | 53 | DateType, |
| 54 | + DecimalType, |
53 | 55 | DoubleType, |
54 | 56 | IntegerType, |
55 | 57 | ListType, |
@@ -1810,3 +1812,32 @@ def test_evolve_and_write( |
1810 | 1812 | ) |
1811 | 1813 |
|
1812 | 1814 | assert session_catalog.load_table(identifier).scan().to_arrow().column(0).combine_chunks() == numbers |
| 1815 | + |
| 1816 | + |
| 1817 | +@pytest.mark.integration |
| 1818 | +def test_read_write_decimals(session_catalog: Catalog) -> None: |
| 1819 | + """Roundtrip decimal types to make sure that we correctly write them as ints""" |
| 1820 | + identifier = "default.test_read_write_decimals" |
| 1821 | + |
| 1822 | + arrow_table = pa.Table.from_pydict( |
| 1823 | + { |
| 1824 | + "decimal8": pa.array([Decimal("123.45"), Decimal("678.91")], pa.decimal128(8, 2)), |
| 1825 | + "decimal16": pa.array([Decimal("12345679.123456"), Decimal("67891234.678912")], pa.decimal128(16, 6)), |
| 1826 | + "decimal19": pa.array([Decimal("1234567890123.123456"), Decimal("9876543210703.654321")], pa.decimal128(19, 6)), |
| 1827 | + }, |
| 1828 | + ) |
| 1829 | + |
| 1830 | + tbl = _create_table( |
| 1831 | + session_catalog, |
| 1832 | + identifier, |
| 1833 | + properties={"format-version": 2}, |
| 1834 | + schema=Schema( |
| 1835 | + NestedField(1, "decimal8", DecimalType(8, 2)), |
| 1836 | + NestedField(2, "decimal16", DecimalType(16, 6)), |
| 1837 | + NestedField(3, "decimal19", DecimalType(19, 6)), |
| 1838 | + ), |
| 1839 | + ) |
| 1840 | + |
| 1841 | + tbl.append(arrow_table) |
| 1842 | + |
| 1843 | + assert tbl.scan().to_arrow() == arrow_table |
0 commit comments