Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ingest/iceberg): add support for nested dictionaries when configuring pyiceberg #10762

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from dataclasses import dataclass, field
from typing import Dict, List, Optional
from typing import Any, Dict, List, Optional

from pydantic import Field, validator
from pyiceberg.catalog import Catalog, load_catalog
Expand Down Expand Up @@ -59,7 +59,7 @@ class IcebergSourceConfig(StatefulIngestionConfigBase, DatasetSourceConfigMixin)
default=None, description="Iceberg Stateful Ingestion Config."
)
# The catalog configuration is using a dictionary to be open and flexible. All the keys and values are handled by pyiceberg. This will future-proof any configuration change done by pyiceberg.
catalog: Dict[str, Dict[str, str]] = Field(
catalog: Dict[str, Dict[str, Any]] = Field(
description="Catalog configuration where to find Iceberg tables. Only one catalog specification is supported. The format is the same as [pyiceberg's catalog configuration](https://py.iceberg.apache.org/configuration/), where the catalog name is specified as the object name and attributes are set as key-value pairs.",
)
table_pattern: AllowDenyPattern = Field(
Expand Down
30 changes: 29 additions & 1 deletion metadata-ingestion/tests/unit/test_iceberg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import uuid
from decimal import Decimal
from typing import Any, Optional
from typing import Any, Dict, List, Optional

import pytest
from pydantic import ValidationError
Expand Down Expand Up @@ -124,6 +124,34 @@ def test_config_for_tests():
with_iceberg_source()


def test_config_support_nested_dicts():
"""
Test that Iceberg source supports nested dictionaries inside its configuration, as allowed by pyiceberg.
"""
catalog = {
"test": {
"type": "rest",
"nested_dict": {
"nested_key": "nested_value",
"nested_array": ["a1", "a2"],
"subnested_dict": {"subnested_key": "subnested_value"},
},
}
}
test_config = IcebergSourceConfig(catalog=catalog)
assert isinstance(test_config.catalog["test"]["nested_dict"], Dict)
assert test_config.catalog["test"]["nested_dict"]["nested_key"] == "nested_value"
assert isinstance(test_config.catalog["test"]["nested_dict"]["nested_array"], List)
assert test_config.catalog["test"]["nested_dict"]["nested_array"][0] == "a1"
assert isinstance(
test_config.catalog["test"]["nested_dict"]["subnested_dict"], Dict
)
assert (
test_config.catalog["test"]["nested_dict"]["subnested_dict"]["subnested_key"]
== "subnested_value"
)


@pytest.mark.parametrize(
"iceberg_type, expected_schema_field_type",
[
Expand Down
Loading