Skip to content

Commit 74caa17

Browse files
authored
Test: Add test to partition on field with a dot (#610)
1 parent 7bd5d9e commit 74caa17

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

tests/integration/test_writes/test_writes.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
from pyiceberg.catalog.hive import HiveCatalog
3737
from pyiceberg.catalog.sql import SqlCatalog
3838
from pyiceberg.exceptions import NoSuchTableError
39+
from pyiceberg.partitioning import PartitionField, PartitionSpec
40+
from pyiceberg.schema import Schema
3941
from pyiceberg.table import TableProperties, _dataframe_to_data_files
42+
from pyiceberg.transforms import IdentityTransform
43+
from pyiceberg.types import IntegerType, NestedField
4044
from tests.conftest import TEST_DATA_WITH_NULL
4145
from utils import _create_table
4246

@@ -807,3 +811,25 @@ def test_hive_catalog_storage_descriptor(
807811
assert len(tbl.scan().to_arrow()) == 3
808812
# check if spark can read the table
809813
assert spark.sql("SELECT * FROM hive.default.test_storage_descriptor").count() == 3
814+
815+
816+
@pytest.mark.integration
817+
@pytest.mark.parametrize('catalog', [pytest.lazy_fixture('session_catalog_hive'), pytest.lazy_fixture('session_catalog')])
818+
def test_sanitize_character_partitioned(catalog: Catalog) -> None:
819+
table_name = "default.test_table_partitioned_sanitized_character"
820+
try:
821+
catalog.drop_table(table_name)
822+
except NoSuchTableError:
823+
pass
824+
825+
tbl = _create_table(
826+
session_catalog=catalog,
827+
identifier=table_name,
828+
schema=Schema(NestedField(field_id=1, name="some.id", type=IntegerType(), required=True)),
829+
partition_spec=PartitionSpec(
830+
PartitionField(source_id=1, field_id=1000, name="some.id_identity", transform=IdentityTransform())
831+
),
832+
data=[pa.Table.from_arrays([range(22)], schema=pa.schema([pa.field("some.id", pa.int32(), nullable=False)]))],
833+
)
834+
835+
assert len(tbl.scan().to_arrow()) == 22

tests/integration/test_writes/utils.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121

2222
from pyiceberg.catalog import Catalog
2323
from pyiceberg.exceptions import NoSuchTableError
24-
from pyiceberg.partitioning import PartitionSpec
24+
from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionSpec
2525
from pyiceberg.schema import Schema
2626
from pyiceberg.table import Table
27-
from pyiceberg.typedef import Properties
27+
from pyiceberg.typedef import EMPTY_DICT, Properties
2828
from pyiceberg.types import (
2929
BinaryType,
3030
BooleanType,
@@ -62,24 +62,19 @@
6262
def _create_table(
6363
session_catalog: Catalog,
6464
identifier: str,
65-
properties: Properties,
65+
properties: Properties = EMPTY_DICT,
6666
data: Optional[List[pa.Table]] = None,
67-
partition_spec: Optional[PartitionSpec] = None,
67+
partition_spec: PartitionSpec = UNPARTITIONED_PARTITION_SPEC,
6868
schema: Union[Schema, "pa.Schema"] = TABLE_SCHEMA,
6969
) -> Table:
7070
try:
7171
session_catalog.drop_table(identifier=identifier)
7272
except NoSuchTableError:
7373
pass
7474

75-
if partition_spec:
76-
tbl = session_catalog.create_table(
77-
identifier=identifier, schema=schema, properties=properties, partition_spec=partition_spec
78-
)
79-
else:
80-
tbl = session_catalog.create_table(identifier=identifier, schema=schema, properties=properties)
75+
tbl = session_catalog.create_table(identifier=identifier, schema=schema, properties=properties, partition_spec=partition_spec)
8176

82-
if data:
77+
if data is not None:
8378
for d in data:
8479
tbl.append(d)
8580

0 commit comments

Comments
 (0)