mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-16 11:30:44 +02:00
iceberg: reject unsupported stage-create table creation
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user