Browse Source

iceberg: reject unsupported stage-create table creation

fix/iceberg-stage-create-semantics
Chris Lu 1 day ago
parent
commit
49703baa7c
  1. 20
      weed/s3api/iceberg/iceberg.go
  2. 27
      weed/s3api/iceberg/iceberg_create_table_test.go

20
weed/s3api/iceberg/iceberg.go

@ -566,6 +566,8 @@ const (
maxListPageSize = 1000
)
var errStageCreateUnsupported = errors.New("stage-create is not supported")
func getPaginationQueryParam(r *http.Request, primary, fallback string) string {
if v := strings.TrimSpace(r.URL.Query().Get(primary)); v != "" {
return v
@ -600,6 +602,16 @@ func normalizeNamespaceProperties(properties map[string]string) map[string]strin
return properties
}
func validateCreateTableRequest(req CreateTableRequest) error {
if req.Name == "" {
return errors.New("table name is required")
}
if req.StageCreate {
return errStageCreateUnsupported
}
return nil
}
// handleConfig returns catalog configuration.
func (s *Server) handleConfig(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
@ -908,8 +920,12 @@ func (s *Server) handleCreateTable(w http.ResponseWriter, r *http.Request) {
return
}
if req.Name == "" {
writeError(w, http.StatusBadRequest, "BadRequestException", "Table name is required")
if err := validateCreateTableRequest(req); err != nil {
if errors.Is(err, errStageCreateUnsupported) {
writeError(w, http.StatusNotImplemented, "NotImplementedException", "stage-create is not supported; submit create without stage-create")
return
}
writeError(w, http.StatusBadRequest, "BadRequestException", err.Error())
return
}

27
weed/s3api/iceberg/iceberg_create_table_test.go

@ -0,0 +1,27 @@
package iceberg
import (
"errors"
"testing"
)
func TestValidateCreateTableRequestRejectsStageCreate(t *testing.T) {
err := validateCreateTableRequest(CreateTableRequest{Name: "orders", StageCreate: true})
if !errors.Is(err, errStageCreateUnsupported) {
t.Fatalf("validateCreateTableRequest() error = %v, want errStageCreateUnsupported", err)
}
}
func TestValidateCreateTableRequestRequiresName(t *testing.T) {
err := validateCreateTableRequest(CreateTableRequest{})
if err == nil {
t.Fatalf("validateCreateTableRequest() expected error")
}
}
func TestValidateCreateTableRequestAcceptsStandardCreate(t *testing.T) {
err := validateCreateTableRequest(CreateTableRequest{Name: "orders"})
if err != nil {
t.Fatalf("validateCreateTableRequest() error = %v, want nil", err)
}
}
Loading…
Cancel
Save