zeroshade commented on code in PR #1379:
URL: https://github.com/apache/iceberg-go/pull/1379#discussion_r3553758483


##########
cmd/iceberg/utils_test.go:
##########
@@ -242,3 +305,123 @@ func TestParseSortOrder(t *testing.T) {
                })
        }
 }
+
+func TestParsePartitionSpecSendsFieldIDsInRestCreatePayload(t *testing.T) {
+       schema := iceberg.NewSchema(0,
+               iceberg.NestedField{
+                       ID:       10,
+                       Name:     "customer_id",
+                       Type:     iceberg.PrimitiveTypes.String,
+                       Required: false,
+               },
+               iceberg.NestedField{
+                       ID:       20,
+                       Name:     "event_time",
+                       Type:     iceberg.PrimitiveTypes.TimestampNs,
+                       Required: false,
+               },
+       )
+
+       spec, err := parsePartitionSpec("customer_id,event_time", schema)
+       require.NoError(t, err)
+       require.NotNil(t, spec)
+
+       var lastCreateBody map[string]any
+       createCalled := false
+
+       srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, 
req *http.Request) {
+               switch req.URL.Path {
+               case "/v1/config":
+                       w.Header().Set("Content-Type", "application/json")
+                       require.NoError(t, 
json.NewEncoder(w).Encode(map[string]any{
+                               "defaults":  map[string]any{},
+                               "overrides": map[string]any{},
+                               "endpoints": []string{},
+                       }))
+
+                       return
+               case "/v1/namespaces/db/tables":
+                       require.Equal(t, http.MethodPost, req.Method)
+                       createCalled = true
+
+                       require.NoError(t, 
json.NewDecoder(req.Body).Decode(&lastCreateBody))
+
+                       w.Header().Set("Content-Type", "application/json")
+                       w.WriteHeader(http.StatusOK)
+                       _, _ = w.Write([]byte(`{
+                               "metadata-location": 
"s3://warehouse/db/tbl/metadata/v1.json",
+                               "metadata": ` + tableMetadataJSON("") + `
+                       }`))
+
+                       return
+               default:
+                       w.WriteHeader(http.StatusNotFound)
+               }
+       }))
+       defer srv.Close()
+
+       cat, err := rest.NewCatalog(context.Background(), "rest", srv.URL)
+       require.NoError(t, err)
+
+       _, err = cat.CreateTable(context.Background(), table.Identifier{"db", 
"test_table"}, schema,
+               catalog.WithPartitionSpec(spec))
+       require.NoError(t, err)
+       require.True(t, createCalled, "create endpoint should be called")
+
+       rawPartitionSpec, ok := 
lastCreateBody["partition-spec"].(map[string]any)
+       require.True(t, ok)
+       fields, ok := rawPartitionSpec["fields"].([]any)
+       require.True(t, ok)
+       require.Len(t, fields, 2)
+
+       field0, ok := fields[0].(map[string]any)
+       require.True(t, ok)
+       field1, ok := fields[1].(map[string]any)
+       require.True(t, ok)
+       require.EqualValues(t, 1000, field0["field-id"])
+       require.EqualValues(t, 1001, field1["field-id"])
+}
+
+func tableMetadataJSON(tableUUID string) string {

Review Comment:
   nit: this helper builds a schema that doesn't match the one exercised by the 
test above — harmless since only the partition spec matters for the assertion, 
but a matching schema would read less confusingly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to