Skip to content
Open
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
@@ -0,0 +1,41 @@
#include <gtest/gtest.h>

#include <Storages/ObjectStorage/DataLakes/Iceberg/Utils.h>

using namespace DB::Iceberg;

TEST(GetProperFilePathFromMetadataInfo, S3SchemePreservesPercentEncodedSlash)
{
auto result = getProperFilePathFromMetadataInfo(
"s3://bucket/warehouse/data/partition=us%2Fwest/file.parquet",
"warehouse",
"s3://bucket/warehouse");
ASSERT_EQ(result, "warehouse/data/partition=us%2Fwest/file.parquet");
}

TEST(GetProperFilePathFromMetadataInfo, SimpleKeyWithoutEncoding)
{
auto result = getProperFilePathFromMetadataInfo(
"s3://bucket/warehouse/data/file.parquet",
"warehouse",
"s3://bucket/warehouse");
ASSERT_EQ(result, "warehouse/data/file.parquet");
}

TEST(GetProperFilePathFromMetadataInfo, MultiplePercentEncodedSegments)
{
auto result = getProperFilePathFromMetadataInfo(
"s3://bucket/warehouse/data/region=us%2Fwest/city=san%20francisco/file.parquet",
"warehouse",
"s3://bucket/warehouse");
ASSERT_EQ(result, "warehouse/data/region=us%2Fwest/city=san%20francisco/file.parquet");
}

TEST(GetProperFilePathFromMetadataInfo, HttpSchemePreservesPercentEncodedSlash)
{
auto result = getProperFilePathFromMetadataInfo(
"http://minio:9000/bucket/warehouse/data/partition=us%2Fwest/file.parquet",
"warehouse",
"http://minio:9000/bucket/warehouse");
ASSERT_EQ(result, "warehouse/data/partition=us%2Fwest/file.parquet");
}
44 changes: 44 additions & 0 deletions tests/integration/test_database_iceberg/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,50 @@ def test_table_with_slash(started_cluster):
assert node.query(f"SELECT * FROM {CATALOG_NAME}.`{root_namespace}.{table_encoded_name}`") == "\\N\tAAPL\t193.24\t193.31\t('bot')\n"


def test_partition_value_with_slash(started_cluster):
"""Partition value containing '/' produces object keys with %2F; reading must preserve encoding."""
node = started_cluster.instances["node1"]

test_ref = f"test_partition_slash_{uuid.uuid4()}"
table_name = f"{test_ref}_table"
root_namespace = f"{test_ref}_namespace"

partition_spec = PartitionSpec(
PartitionField(
source_id=2, field_id=1000, transform=IdentityTransform(), name="symbol"
)
)
schema = DEFAULT_SCHEMA

catalog = load_catalog_impl(started_cluster)
catalog.create_namespace(root_namespace)

table = create_table(
catalog,
root_namespace,
table_name,
schema,
partition_spec=partition_spec,
sort_order=DEFAULT_SORT_ORDER,
)

data = [
{
"datetime": datetime.now(),
"symbol": "us/west",
"bid": 100.0,
"ask": 101.0,
"details": {"created_by": "test"},
}
]
df = pa.Table.from_pylist(data)
table.append(df)

create_clickhouse_iceberg_database(started_cluster, node, CATALOG_NAME)
assert 1 == int(node.query(f"SELECT count() FROM {CATALOG_NAME}.`{root_namespace}.{table_name}`"))
assert "us/west" in node.query(f"SELECT symbol FROM {CATALOG_NAME}.`{root_namespace}.{table_name}`")


def test_cluster_select(started_cluster):
node1 = started_cluster.instances["node1"]
node2 = started_cluster.instances["node2"]
Expand Down
Loading