Skip to content

Commit ca92837

Browse files
committed
Add the rest of the _convert_schema_if_needed calls
1 parent 24b12dd commit ca92837

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

pyiceberg/catalog/dynamodb.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionSpec
5454
from pyiceberg.schema import Schema
5555
from pyiceberg.serializers import FromInputFile
56-
from pyiceberg.table import CommitTableResponse, Table
56+
from pyiceberg.table import CommitTableResponse, Table, TableProperties
5757
from pyiceberg.table.locations import load_location_provider
5858
from pyiceberg.table.metadata import new_table_metadata
5959
from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder
@@ -181,7 +181,10 @@ def create_table(
181181
ValueError: If the identifier is invalid, or no path is given to store metadata.
182182
183183
"""
184-
schema: Schema = self._convert_schema_if_needed(schema) # type: ignore
184+
schema: Schema = self._convert_schema_if_needed( # type: ignore
185+
schema,
186+
int(properties.get(TableProperties.FORMAT_VERSION, TableProperties.DEFAULT_FORMAT_VERSION)), # type: ignore
187+
)
185188

186189
database_name, table_name = self.identifier_to_database_and_table(identifier)
187190

pyiceberg/catalog/sql.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionSpec
6363
from pyiceberg.schema import Schema
6464
from pyiceberg.serializers import FromInputFile
65-
from pyiceberg.table import CommitTableResponse, Table
65+
from pyiceberg.table import CommitTableResponse, Table, TableProperties
6666
from pyiceberg.table.locations import load_location_provider
6767
from pyiceberg.table.metadata import new_table_metadata
6868
from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder
@@ -200,7 +200,10 @@ def create_table(
200200
ValueError: If the identifier is invalid, or no path is given to store metadata.
201201
202202
"""
203-
schema: Schema = self._convert_schema_if_needed(schema) # type: ignore
203+
schema: Schema = self._convert_schema_if_needed( # type: ignore
204+
schema,
205+
int(properties.get(TableProperties.FORMAT_VERSION, TableProperties.DEFAULT_FORMAT_VERSION)), # type: ignore
206+
)
204207

205208
namespace_identifier = Catalog.namespace_from(identifier)
206209
table_name = Catalog.table_name_from(identifier)

tests/integration/test_writes/test_writes.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,13 +2251,19 @@ def test_branch_py_write_spark_read(session_catalog: Catalog, spark: SparkSessio
22512251
@pytest.mark.integration
22522252
def test_nanosecond_support_on_catalog(session_catalog: Catalog) -> None:
22532253
identifier = "default.test_nanosecond_support_on_catalog"
2254-
# Create a pyarrow table with a nanosecond timestamp column
2255-
table = pa.Table.from_arrays(
2256-
[
2257-
pa.array([datetime.now()], type=pa.timestamp("ns")),
2258-
pa.array([datetime.now()], type=pa.timestamp("ns", tz="America/New_York")),
2259-
],
2260-
names=["timestamp_ns", "timestamptz_ns"],
2254+
2255+
catalog = load_catalog("default", type="in-memory")
2256+
catalog.create_namespace("ns")
2257+
2258+
table = pa.Table.from_arrays([pa.array([datetime.now()], type=pa.timestamp("ns"))], names=["timestamps"])
2259+
table2 = pa.Table.from_arrays(
2260+
[pa.array([datetime.now()], type=pa.timestamp("ns", tz="America/New_York"))], names=["timestamps"]
22612261
)
22622262

22632263
_create_table(session_catalog, identifier, {"format-version": "3"}, schema=table.schema)
2264+
2265+
with pytest.raises(NotImplementedError, match="Writing V3 is not yet supported"):
2266+
catalog.create_table("ns.table1", schema=table.schema, properties={"format-version": "3"})
2267+
2268+
with pytest.raises(NotImplementedError, match="Writing V3 is not yet supported"):
2269+
catalog.create_table("ns.table2", schema=table2.schema, properties={"format-version": "3"})

0 commit comments

Comments
 (0)