From e98788a67e07eb58c9cb39d62cdd9389be6daf53 Mon Sep 17 00:00:00 2001 From: tr00d Date: Thu, 26 Nov 2026 11:42:03 +0100 Subject: [PATCH] refactor(storage): let Iceberg identifiers address their tables collection Create and list no longer build the tables path by hand from the namespace: IcebergNamespace.TablesPath and IcebergTable.CollectionPath own it, and IcebergTable.Path builds on it. Internal only; wire behavior unchanged. --- .../Storage/Storage.Tests/Common/IcebergNamespaceTests.cs | 4 ++++ packages/Storage/Storage.Tests/Common/IcebergTableTests.cs | 5 +++++ packages/Storage/Storage/Common/IcebergNamespace.cs | 2 ++ packages/Storage/Storage/Common/IcebergTable.cs | 4 +++- packages/Storage/Storage/IcebergCatalog.cs | 4 ++-- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/Storage/Storage.Tests/Common/IcebergNamespaceTests.cs b/packages/Storage/Storage.Tests/Common/IcebergNamespaceTests.cs index 33ebef16..e16e1052 100644 --- a/packages/Storage/Storage.Tests/Common/IcebergNamespaceTests.cs +++ b/packages/Storage/Storage.Tests/Common/IcebergNamespaceTests.cs @@ -85,6 +85,10 @@ public void ToString_ShouldJoinLevelsWithDots() => public void Path_ShouldEscapeAndJoinLevelsWithTheEncodedUnitSeparator() => IcebergNamespace.Of("a b", "c/d").Path.Should().Be("namespaces/a%20b%1Fc%2Fd", "the Iceberg REST spec joins levels with the 0x1F separator"); + [TestMethod] + public void TablesPath_ShouldNestTheTablesCollectionUnderTheNamespace() => + IcebergNamespace.Of("sales", "europe").TablesPath.Should().Be("namespaces/sales%1Feurope/tables", "the Iceberg REST spec lists and creates tables under the namespace"); + [TestMethod] public void Path_ShouldAcceptLevelsContainingDots() => IcebergNamespace.Of("a..b").Path.Should().Be("namespaces/a..b"); diff --git a/packages/Storage/Storage.Tests/Common/IcebergTableTests.cs b/packages/Storage/Storage.Tests/Common/IcebergTableTests.cs index 777cf743..27d74db7 100644 --- a/packages/Storage/Storage.Tests/Common/IcebergTableTests.cs +++ b/packages/Storage/Storage.Tests/Common/IcebergTableTests.cs @@ -24,6 +24,11 @@ public void Equals_ShouldBeTrue_GivenSameNamespaceAndName() => public void Equals_ShouldBeFalse_GivenDifferentName() => IcebergNamespace.Of("sales").Table("events").Should().NotBe(IcebergNamespace.Of("sales").Table("orders")); + [TestMethod] + public void CollectionPath_ShouldBeTheTablesCollectionOfItsNamespace() => + IcebergNamespace.Of("sales", "europe").Table("events").CollectionPath + .Should().Be("namespaces/sales%1Feurope/tables", "a table is created by posting to its namespace's tables"); + [TestMethod] public void Path_ShouldNestTheEscapedNameUnderTheTablesOfItsNamespace() => IcebergNamespace.Of("sales", "europe").Table("a/b?c#d").Path diff --git a/packages/Storage/Storage/Common/IcebergNamespace.cs b/packages/Storage/Storage/Common/IcebergNamespace.cs index c21d0ac0..a38a8d47 100644 --- a/packages/Storage/Storage/Common/IcebergNamespace.cs +++ b/packages/Storage/Storage/Common/IcebergNamespace.cs @@ -68,6 +68,8 @@ public override int GetHashCode() => internal string Path => $"namespaces/{PathSegment.Escape(this.Joined(), "A namespace", "namespace")}"; + internal string TablesPath => $"{this.Path}/tables"; + private static void RejectMissing(string[]? levels) { if (levels is null) diff --git a/packages/Storage/Storage/Common/IcebergTable.cs b/packages/Storage/Storage/Common/IcebergTable.cs index f2118bcc..16025e87 100644 --- a/packages/Storage/Storage/Common/IcebergTable.cs +++ b/packages/Storage/Storage/Common/IcebergTable.cs @@ -20,5 +20,7 @@ internal IcebergTable(IcebergNamespace @namespace, string name) /// public override string ToString() => $"{this.Namespace}.{this.Name}"; - internal string Path => $"{this.Namespace.Path}/tables/{PathSegment.Escape(this.Name, "A table name", "table")}"; + internal string Path => $"{this.CollectionPath}/{PathSegment.Escape(this.Name, "A table name", "table")}"; + + internal string CollectionPath => this.Namespace.TablesPath; } diff --git a/packages/Storage/Storage/IcebergCatalog.cs b/packages/Storage/Storage/IcebergCatalog.cs index 0cb48b54..199bbe31 100644 --- a/packages/Storage/Storage/IcebergCatalog.cs +++ b/packages/Storage/Storage/IcebergCatalog.cs @@ -67,7 +67,7 @@ public async Task CreateTableAsync(IcebergTable table, Ice { RequireArgument(table, nameof(table)); RequireArgument(schema, nameof(schema)); - var response = await Helpers.MakeRequestAsync(this.requestClient, this.options, HttpMethod.Post, this.ResourceUrl($"{table.Namespace.Path}/tables"), CreateTableBody.For(table, schema, options), this.headers(), cancellationToken).ConfigureAwait(false); + var response = await Helpers.MakeRequestAsync(this.requestClient, this.options, HttpMethod.Post, this.ResourceUrl(table.CollectionPath), CreateTableBody.For(table, schema, options), this.headers(), cancellationToken).ConfigureAwait(false); return response!.ToMetadata(); } @@ -97,7 +97,7 @@ public Task DeleteTableAsync(IcebergTable table, DeleteTableOptions? options = n public async Task ListTablesAsync(IcebergNamespace @namespace, ListTablesOptions? options = null, CancellationToken cancellationToken = default) { RequireArgument(@namespace, nameof(@namespace)); - var url = ListTablesQuery.For(this.ResourceUrl($"{@namespace.Path}/tables"), options); + var url = ListTablesQuery.For(this.ResourceUrl(@namespace.TablesPath), options); var response = await Helpers.MakeRequestAsync(this.requestClient, this.options, HttpMethod.Get, url, null, this.headers(), cancellationToken).ConfigureAwait(false); return response!.ToPage(@namespace); }