Revanth14 commented on code in PR #1505: URL: https://github.com/apache/iceberg-go/pull/1505#discussion_r3781097618
########## catalog/rest/scan_planning_integration_test.go: ########## @@ -0,0 +1,321 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build integration + +package rest_test + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + stdio "io" + "net/http" + "net/url" + "os" + "strings" + "sync" + "time" + + "github.com/apache/arrow-go/v18/arrow/array" + "github.com/apache/arrow-go/v18/arrow/memory" + "github.com/apache/arrow-go/v18/parquet/pqarrow" + "github.com/apache/iceberg-go" + "github.com/apache/iceberg-go/catalog" + "github.com/apache/iceberg-go/catalog/rest" + iceio "github.com/apache/iceberg-go/io" + "github.com/apache/iceberg-go/table" +) + +const ( + runIntegrationTestsEnv = "RUN_INTEGRATION_TESTS" + integrationAccessDelegation = "vended-credentials" + integrationAccessDelegationHeader = "X-Iceberg-Access-Delegation" + integrationGCSToken = "scan-planning-integration-token" + integrationGCSTokenKey = "gcs.oauth2.token" +) + +func (s *RestIntegrationSuite) TestScanPlanningJavaSynchronousInteroperability() { + s.requireScanPlanningIntegration() + + transport := newScanPlanningCaptureTransport() + s.T().Cleanup(transport.CloseIdleConnections) + planningCatalog, err := rest.NewCatalog(s.ctx, "scan-planning-java-wire", "http://localhost:8181", + rest.WithCustomTransport(transport)) + s.Require().NoError(err) + s.T().Cleanup(func() { s.Require().NoError(planningCatalog.Close()) }) + s.requireJavaScanPlanningCapabilities(planningCatalog) + + ident := catalog.ToIdentifier(TestNamespaceIdent, "scan-planning-java-wire") + tbl, dataPath := s.createScanPlanningTable(ident) + + filter, err := json.Marshal(iceberg.EqualTo(iceberg.Reference("foo"), "hello")) + s.Require().NoError(err) + snapshotID := tbl.CurrentSnapshot().SnapshotID + caseSensitive := true + useSnapshotSchema := false + minRowsRequested := int64(1) + + response, err := planningCatalog.PlanTableScan(s.ctx, ident, rest.PlanTableScanRequest{ + AccessDelegation: stringPointer(integrationAccessDelegation), + SnapshotID: &snapshotID, + Select: []string{"foo", "bar"}, + Filter: filter, + MinRowsRequested: &minRowsRequested, + CaseSensitive: &caseSensitive, + UseSnapshotSchema: &useSnapshotSchema, + StatsFields: []string{"foo", "bar"}, + }) + s.Require().NoError(err) + s.Require().Equal(rest.PlanStatusCompleted, response.Status) + s.Require().NotNil(response.PlanID) + s.Require().NotEmpty(*response.PlanID) + planID := *response.PlanID + planCancelled := false + s.T().Cleanup(func() { + if planCancelled { + return + } + + _ = cancelPlanningWithTimeout(planningCatalog, ident, planID) + }) + s.Empty(response.PlanTasks) + s.Require().Len(response.FileScanTasks, 1) + s.Empty(response.DeleteFiles) + s.assertJavaPlanningCredentials(response.StorageCredentials) + + rawResponses := transport.PlanResponses() + s.Require().Len(rawResponses, 1) + requestHeaders := transport.PlanRequestHeaders() + s.Require().Len(requestHeaders, 1) + s.Equal(integrationAccessDelegation, requestHeaders[0].Get(integrationAccessDelegationHeader)) + raw := parseRawPlanningFixture(s.T(), string(rawResponses[0])) + s.Equal("completed", raw.Status) + s.Equal(*response.PlanID, raw.PlanID) + s.Empty(raw.PlanTasks) + s.Require().Len(raw.FileScanTasks, 1) + s.Empty(raw.DeleteFiles) + + task := raw.FileScanTasks[0] + s.Equal("data", task.DataFile.Content) + s.Equal(dataPath, task.DataFile.FilePath) + s.Require().Len(task.DataFile.Partition, 1) + s.Equal("17", string(task.DataFile.Partition[0]), + "Java partitions must remain typed JSON values, not binary-bound strings") + s.JSONEq(`{"type":"eq","term":"foo","value":"hello"}`, string(task.ResidualFilter)) + s.Empty(task.DeleteFileReferences) + + lowerBounds := valueMapByFieldID(s, task.DataFile.LowerBounds) + upperBounds := valueMapByFieldID(s, task.DataFile.UpperBounds) + s.ElementsMatch([]int{1, 2}, task.DataFile.LowerBounds.Keys) + s.ElementsMatch([]int{1, 2}, task.DataFile.UpperBounds.Keys) + s.Equal("68656C6C6F", lowerBounds[1], "Java string lower bounds must be uppercase hexadecimal") + s.Equal("68656C6C6F", upperBounds[1], "Java string upper bounds must be uppercase hexadecimal") + s.Equal("11000000", lowerBounds[2], "Java int lower bounds must use Iceberg little-endian binary") + s.Equal("11000000", upperBounds[2], "Java int upper bounds must use Iceberg little-endian binary") + + s.Require().Len(raw.StorageCredentials, 1) + s.Equal("gcp", raw.StorageCredentials[0].Prefix) + s.Equal(integrationGCSToken, raw.StorageCredentials[0].Config[integrationGCSTokenKey]) + + // The reference fixture retains its synchronous plan state until the client + // releases it, so this also verifies the advertised DELETE route end to end. + s.Require().NoError(cancelPlanningWithTimeout(planningCatalog, ident, planID)) + planCancelled = true +} + +func (s *RestIntegrationSuite) TestScanPlanningJavaErrorTypes() { + s.requireScanPlanningIntegration() + s.requireJavaScanPlanningCapabilities(s.cat) + s.ensureNamespace() + // The published fixture defaults to synchronous inline planning and exposes + // no container setting for async planning or a smaller plan-task page size. + // The not-found cases still exercise the live GET and POST routes and their + // Java error models; deterministic successful polling/fanout remains covered + // by planfake until the reference image exposes those controls. + + missingTable := catalog.ToIdentifier(TestNamespaceIdent, "missing-scan-planning-table") + _, err := s.cat.PlanTableScan(s.ctx, missingTable, rest.PlanTableScanRequest{}) + s.ErrorIs(err, catalog.ErrNoSuchTable) + + ident := catalog.ToIdentifier(TestNamespaceIdent, "scan-planning-java-errors") + tbl, err := s.cat.CreateTable(s.ctx, ident, tableSchemaSimple) + s.Require().NoError(err) + s.Require().NotNil(tbl) + s.T().Cleanup(func() { s.Require().NoError(s.cat.DropTable(s.ctx, ident)) }) + + _, err = s.cat.FetchPlanningResult(s.ctx, ident, "missing-plan-id", rest.FetchPlanningResultOptions{}) + s.ErrorIs(err, rest.ErrPlanExpired) + + _, err = s.cat.FetchScanTasks(s.ctx, ident, rest.FetchScanTasksRequest{PlanTask: "missing-plan-task"}) + s.ErrorIs(err, rest.ErrNoSuchPlanTask) +} + +func (s *RestIntegrationSuite) requireScanPlanningIntegration() { + s.T().Helper() + if os.Getenv(runIntegrationTestsEnv) != "1" { + s.T().Skipf("set %s=1 to run Java REST scan-planning integration tests", runIntegrationTestsEnv) + } +} + +func (s *RestIntegrationSuite) requireJavaScanPlanningCapabilities(cat *rest.Catalog) { + s.T().Helper() + s.Require().True(cat.SupportsPlanTableScan(), "Java fixture must advertise planTableScan") Review Comment: Agreed. I updated the capability guard to call `Skip` when the server doesn’t advertise the required scan-planning endpoints. This now behaves consistently with `requireScanPlanningIntegration` and reports a mismatched fixture image as a skipped test rather than a failure. -- 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]
