32
32
from random import choice
33
33
from tempfile import TemporaryDirectory
34
34
from typing import (
35
+ TYPE_CHECKING ,
35
36
Any ,
36
37
Callable ,
37
38
Dict ,
50
51
import boto3
51
52
import botocore .awsrequest
52
53
import botocore .model
53
- import pyarrow as pa
54
54
import pytest
55
55
from moto import mock_dynamodb , mock_glue , mock_s3
56
- from pyarrow import parquet as pq
57
56
58
57
from pyiceberg import schema
59
58
from pyiceberg .catalog import Catalog
69
68
load_file_io ,
70
69
)
71
70
from pyiceberg .io .fsspec import FsspecFileIO
72
- from pyiceberg .io .pyarrow import PyArrowFile , PyArrowFileIO
73
71
from pyiceberg .manifest import DataFile , FileFormat
74
72
from pyiceberg .schema import Schema
75
73
from pyiceberg .serializers import ToOutputFile
91
89
)
92
90
from pyiceberg .utils .datetime import datetime_to_millis
93
91
92
+ if TYPE_CHECKING :
93
+ from pyiceberg .io .pyarrow import PyArrowFile , PyArrowFileIO
94
+
94
95
95
96
def pytest_collection_modifyitems (items : List [pytest .Item ]) -> None :
96
97
for item in items :
@@ -421,6 +422,8 @@ def example_table_metadata_v2() -> Dict[str, Any]:
421
422
422
423
@pytest .fixture (scope = "session" )
423
424
def metadata_location (tmp_path_factory : pytest .TempPathFactory ) -> str :
425
+ from pyiceberg .io .pyarrow import PyArrowFileIO
426
+
424
427
metadata_location = str (tmp_path_factory .mktemp ("metadata" ) / f"{ uuid .uuid4 ()} .metadata.json" )
425
428
metadata = TableMetadataV2 (** EXAMPLE_TABLE_METADATA_V2 )
426
429
ToOutputFile .table_metadata (metadata , PyArrowFileIO ().new_output (location = metadata_location ), overwrite = True )
@@ -429,6 +432,8 @@ def metadata_location(tmp_path_factory: pytest.TempPathFactory) -> str:
429
432
430
433
@pytest .fixture (scope = "session" )
431
434
def metadata_location_gz (tmp_path_factory : pytest .TempPathFactory ) -> str :
435
+ from pyiceberg .io .pyarrow import PyArrowFileIO
436
+
432
437
metadata_location = str (tmp_path_factory .mktemp ("metadata" ) / f"{ uuid .uuid4 ()} .gz.metadata.json" )
433
438
metadata = TableMetadataV2 (** EXAMPLE_TABLE_METADATA_V2 )
434
439
ToOutputFile .table_metadata (metadata , PyArrowFileIO ().new_output (location = metadata_location ), overwrite = True )
@@ -1146,7 +1151,9 @@ def __len__(self) -> int:
1146
1151
def exists (self ) -> bool :
1147
1152
return os .path .exists (self ._path )
1148
1153
1149
- def to_input_file (self ) -> PyArrowFile :
1154
+ def to_input_file (self ) -> "PyArrowFile" :
1155
+ from pyiceberg .io .pyarrow import PyArrowFileIO
1156
+
1150
1157
return PyArrowFileIO ().new_input (location = self .location )
1151
1158
1152
1159
def create (self , overwrite : bool = False ) -> OutputStream :
@@ -1399,7 +1406,9 @@ def fsspec_fileio_gcs(request: pytest.FixtureRequest) -> FsspecFileIO:
1399
1406
1400
1407
1401
1408
@pytest .fixture
1402
- def pyarrow_fileio_gcs (request : pytest .FixtureRequest ) -> PyArrowFileIO :
1409
+ def pyarrow_fileio_gcs (request : pytest .FixtureRequest ) -> "PyArrowFileIO" :
1410
+ from pyiceberg .io .pyarrow import PyArrowFileIO
1411
+
1403
1412
properties = {
1404
1413
GCS_ENDPOINT : request .config .getoption ("--gcs.endpoint" ),
1405
1414
GCS_TOKEN : request .config .getoption ("--gcs.oauth2.token" ),
@@ -1620,6 +1629,9 @@ def clean_up(test_catalog: Catalog) -> None:
1620
1629
1621
1630
@pytest .fixture
1622
1631
def data_file (table_schema_simple : Schema , tmp_path : str ) -> str :
1632
+ import pyarrow as pa
1633
+ from pyarrow import parquet as pq
1634
+
1623
1635
table = pa .table (
1624
1636
{"foo" : ["a" , "b" , "c" ], "bar" : [1 , 2 , 3 ], "baz" : [True , False , None ]},
1625
1637
metadata = {"iceberg.schema" : table_schema_simple .model_dump_json ()},
0 commit comments