|
15 | 15 | # specific language governing permissions and limitations |
16 | 16 | # under the License. |
17 | 17 | # pylint:disable=redefined-outer-name |
| 18 | +import os |
| 19 | +import time |
18 | 20 | import uuid |
19 | 21 | from datetime import date, datetime |
| 22 | +from pathlib import Path |
20 | 23 | from typing import Any, Dict, List |
21 | 24 | from urllib.parse import urlparse |
22 | 25 |
|
23 | 26 | import pyarrow as pa |
24 | 27 | import pyarrow.parquet as pq |
25 | 28 | import pytest |
| 29 | +import pytz |
26 | 30 | from pyarrow.fs import S3FileSystem |
27 | 31 | from pyspark.sql import SparkSession |
28 | 32 | from pytest_mock.plugin import MockerFixture |
29 | 33 |
|
30 | 34 | from pyiceberg.catalog import Catalog, Properties, Table, load_catalog |
| 35 | +from pyiceberg.catalog.sql import SqlCatalog |
31 | 36 | from pyiceberg.exceptions import NamespaceAlreadyExistsError, NoSuchTableError |
32 | 37 | from pyiceberg.schema import Schema |
33 | 38 | from pyiceberg.types import ( |
@@ -573,3 +578,59 @@ def test_summaries_with_only_nulls( |
573 | 578 | 'total-position-deletes': '0', |
574 | 579 | 'total-records': '0', |
575 | 580 | } |
| 581 | + |
| 582 | + |
| 583 | +@pytest.mark.integration |
| 584 | +def test_duckdb_url_import(warehouse: Path, arrow_table_with_null: pa.Table) -> None: |
| 585 | + os.environ['TZ'] = 'Etc/UTC' |
| 586 | + time.tzset() |
| 587 | + tz = pytz.timezone(os.environ['TZ']) |
| 588 | + |
| 589 | + catalog = SqlCatalog("test_sql_catalog", uri="sqlite:///:memory:", warehouse=f"/{warehouse}") |
| 590 | + catalog.create_namespace("default") |
| 591 | + |
| 592 | + identifier = "default.arrow_table_v1_with_null" |
| 593 | + tbl = _create_table(catalog, identifier, {}, [arrow_table_with_null]) |
| 594 | + location = tbl.metadata_location |
| 595 | + |
| 596 | + import duckdb |
| 597 | + |
| 598 | + duckdb.sql('INSTALL iceberg; LOAD iceberg;') |
| 599 | + result = duckdb.sql( |
| 600 | + f""" |
| 601 | + SELECT * |
| 602 | + FROM iceberg_scan('{location}') |
| 603 | + """ |
| 604 | + ).fetchall() |
| 605 | + |
| 606 | + assert result == [ |
| 607 | + ( |
| 608 | + False, |
| 609 | + 'a', |
| 610 | + 'aaaaaaaaaaaaaaaaaaaaaa', |
| 611 | + 1, |
| 612 | + 1, |
| 613 | + 0.0, |
| 614 | + 0.0, |
| 615 | + datetime(2023, 1, 1, 19, 25), |
| 616 | + datetime(2023, 1, 1, 19, 25, tzinfo=tz), |
| 617 | + date(2023, 1, 1), |
| 618 | + b'\x01', |
| 619 | + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', |
| 620 | + ), |
| 621 | + (None, None, None, None, None, None, None, None, None, None, None, None), |
| 622 | + ( |
| 623 | + True, |
| 624 | + 'z', |
| 625 | + 'zzzzzzzzzzzzzzzzzzzzzz', |
| 626 | + 9, |
| 627 | + 9, |
| 628 | + 0.8999999761581421, |
| 629 | + 0.9, |
| 630 | + datetime(2023, 3, 1, 19, 25), |
| 631 | + datetime(2023, 3, 1, 19, 25, tzinfo=tz), |
| 632 | + date(2023, 3, 1), |
| 633 | + b'\x12', |
| 634 | + b'\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11', |
| 635 | + ), |
| 636 | + ] |
0 commit comments