This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/terraform-provider-iceberg.git
The following commit(s) were added to refs/heads/main by this push:
new b63cd68 fix(provider): keep every source ID when reading partition
fields (#145)
b63cd68 is described below
commit b63cd68afa69f58fae1d4b9637a48268111ffdfd
Author: Revanth <[email protected]>
AuthorDate: Thu Oct 22 11:34:58 2026 -0500
fix(provider): keep every source ID when reading partition fields (#145)
---
internal/provider/table_schema.go | 6 ++++-
internal/provider/table_schema_test.go | 46 ++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/internal/provider/table_schema.go
b/internal/provider/table_schema.go
index 6fa211c..c9c02e7 100644
--- a/internal/provider/table_schema.go
+++ b/internal/provider/table_schema.go
@@ -415,8 +415,12 @@ func (s *icebergTablePartitionSpec)
FromIceberg(icebergSpec iceberg.PartitionSpe
s.SpecID = types.Int64Value(int64(icebergSpec.ID()))
s.Fields = make([]icebergTablePartitionField, 0,
icebergSpec.NumFields())
for _, field := range icebergSpec.Fields() {
+ sourceIDs := make([]int64, len(field.SourceIDs))
+ for i, id := range field.SourceIDs {
+ sourceIDs[i] = int64(id)
+ }
s.Fields = append(s.Fields, icebergTablePartitionField{
- SourceIDs: []int64{int64(field.SourceID())},
+ SourceIDs: sourceIDs,
FieldID: types.Int64Value(int64(field.FieldID)),
Name: field.Name,
Transform: field.Transform.String(),
diff --git a/internal/provider/table_schema_test.go
b/internal/provider/table_schema_test.go
index bcef71c..4d71d73 100644
--- a/internal/provider/table_schema_test.go
+++ b/internal/provider/table_schema_test.go
@@ -15,7 +15,9 @@
package provider
import (
+ "encoding/json"
"fmt"
+ "slices"
"strings"
"testing"
@@ -241,3 +243,47 @@ func TestAssignFieldIDsIntoReservedRange(t *testing.T) {
t.Fatalf("expected reserved id error, got %v", err)
}
}
+
+func TestPartitionSpecSourceIDsRoundTrip(t *testing.T) {
+ tests := []struct {
+ name string
+ specJSON string
+ sourceIDs []int64
+ }{
+ {
+ name: "single source",
+ specJSON: `{"spec-id": 1, "fields": [{"source-id": 1,
"field-id": 1000, "name": "id_bucket", "transform": "bucket[16]"}]}`,
+ sourceIDs: []int64{1},
+ },
+ {
+ name: "multi source",
+ specJSON: `{"spec-id": 1, "fields": [{"source-ids":
[1, 2], "field-id": 1000, "name": "id_data_bucket", "transform":
"bucket[16]"}]}`,
+ sourceIDs: []int64{1, 2},
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ var want iceberg.PartitionSpec
+ if err := json.Unmarshal([]byte(tt.specJSON), &want);
err != nil {
+ t.Fatalf("unmarshal spec: %v", err)
+ }
+
+ var s icebergTablePartitionSpec
+ if err := s.FromIceberg(want); err != nil {
+ t.Fatalf("FromIceberg: %v", err)
+ }
+ if got := s.Fields[0].SourceIDs; !slices.Equal(got,
tt.sourceIDs) {
+ t.Errorf("expected source ids %v, got %v",
tt.sourceIDs, got)
+ }
+
+ got, err := s.ToIceberg()
+ if err != nil {
+ t.Fatalf("ToIceberg: %v", err)
+ }
+ if !got.Equals(want) {
+ t.Errorf("expected spec %v after round trip,
got %v", want, *got)
+ }
+ })
+ }
+}