Skip to content

Commit d278ee5

Browse files
committed
add test for writing special character column name
1 parent d7b5147 commit d278ee5

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

tests/integration/test_writes/test_writes.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,25 @@ def get_current_snapshot_id(identifier: str) -> int:
270270
assert tbl.current_snapshot().snapshot_id == get_current_snapshot_id(identifier) # type: ignore
271271

272272

273+
@pytest.mark.integration
274+
def test_python_writes_special_character_column_with_spark_reads(spark: SparkSession, session_catalog: Catalog) -> None:
275+
identifier = "default.python_writes_special_character_column_with_spark_reads"
276+
column_name_with_special_character = "letter/abc"
277+
TEST_DATA_WITH_SPECIAL_CHARACTER_COLUMN = {
278+
column_name_with_special_character: ['a', None, 'z'],
279+
}
280+
pa_schema = pa.schema([
281+
(column_name_with_special_character, pa.string()),
282+
])
283+
arrow_table_with_special_character_column = pa.Table.from_pydict(TEST_DATA_WITH_SPECIAL_CHARACTER_COLUMN, schema=pa_schema)
284+
tbl = _create_table(session_catalog, identifier, {"format-version": "1"}, schema=pa_schema)
285+
286+
tbl.overwrite(arrow_table_with_special_character_column)
287+
spark_df = spark.sql(f"SELECT * FROM {identifier}").toPandas()
288+
pyiceberg_df = tbl.scan().to_pandas()
289+
assert spark_df.equals(pyiceberg_df)
290+
291+
273292
@pytest.mark.integration
274293
def test_write_bin_pack_data_files(spark: SparkSession, session_catalog: Catalog, arrow_table_with_null: pa.Table) -> None:
275294
identifier = "default.write_bin_pack_data_files"

tests/integration/test_writes/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
# pylint:disable=redefined-outer-name
18-
from typing import List, Optional
18+
from typing import List, Optional, Union
1919

2020
import pyarrow as pa
2121

@@ -65,6 +65,7 @@ def _create_table(
6565
properties: Properties,
6666
data: Optional[List[pa.Table]] = None,
6767
partition_spec: Optional[PartitionSpec] = None,
68+
schema: Union[Schema, "pa.Schema"] = TABLE_SCHEMA,
6869
) -> Table:
6970
try:
7071
session_catalog.drop_table(identifier=identifier)
@@ -73,10 +74,10 @@ def _create_table(
7374

7475
if partition_spec:
7576
tbl = session_catalog.create_table(
76-
identifier=identifier, schema=TABLE_SCHEMA, properties=properties, partition_spec=partition_spec
77+
identifier=identifier, schema=schema, properties=properties, partition_spec=partition_spec
7778
)
7879
else:
79-
tbl = session_catalog.create_table(identifier=identifier, schema=TABLE_SCHEMA, properties=properties)
80+
tbl = session_catalog.create_table(identifier=identifier, schema=schema, properties=properties)
8081

8182
if data:
8283
for d in data:

0 commit comments

Comments
 (0)