zeroshade commented on code in PR #297:
URL: https://github.com/apache/iceberg-go/pull/297#discussion_r1949651999
##########
catalog/rest/rest.go:
##########
@@ -880,59 +934,112 @@ func (r *Catalog) RenameTable(ctx context.Context, from,
to table.Identifier) (*
}
func (r *Catalog) CreateNamespace(ctx context.Context, namespace
table.Identifier, props iceberg.Properties) error {
+
if err := checkValidNamespace(namespace); err != nil {
return err
}
- _, err := doPost[map[string]any, struct{}](ctx, r.baseURI,
[]string{"namespaces"},
- map[string]any{"namespace": namespace, "properties": props},
r.cl, map[int]error{
- http.StatusNotFound: catalog.ErrNoSuchNamespace,
http.StatusConflict: catalog.ErrNamespaceAlreadyExists})
- return err
+ ref := table.Identifier{}
+ if refStr := iceberg.GetRefFromContext(ctx); refStr != "" {
+ ref = catalog.ToIdentifier(refStr)
+ }
+
+ payload := map[string]any{
+ "type": "NAMESPACE",
+ "elements": namespace,
+ "properties": props,
+ }
+
+ path := []string{"namespaces", "namespace", strings.Join(ref, "."),
strings.Join(namespace, ".")}
+
+ _, err := doPut[map[string]any, map[string]any](ctx, r.baseURI, path,
payload, r.cl, map[int]error{
+ http.StatusNotFound: catalog.ErrNoSuchNamespace,
http.StatusConflict: catalog.ErrNamespaceAlreadyExists})
+
+ if err != nil {
+ return err
+ }
+
+ return nil
}
func (r *Catalog) DropNamespace(ctx context.Context, namespace
table.Identifier) error {
if err := checkValidNamespace(namespace); err != nil {
return err
}
- _, err := doDelete[struct{}](ctx, r.baseURI, []string{"namespaces",
strings.Join(namespace, namespaceSeparator)},
+ ref := table.Identifier{}
+ if refStr := iceberg.GetRefFromContext(ctx); refStr != "" {
+ ref = catalog.ToIdentifier(refStr)
+ }
+
+ path := []string{"namespaces", "namespace", strings.Join(ref, "."),
strings.Join(namespace, ".")}
+ _, err := doDelete[struct{}](ctx, r.baseURI, path,
r.cl, map[int]error{http.StatusNotFound:
catalog.ErrNoSuchNamespace})
return err
}
func (r *Catalog) ListNamespaces(ctx context.Context, parent table.Identifier)
([]table.Identifier, error) {
- uri := r.baseURI.JoinPath("namespaces")
+ ref := table.Identifier{}
+ if refStr := iceberg.GetRefFromContext(ctx); refStr != "" {
+ ref = catalog.ToIdentifier(refStr)
+ }
+
+ uri := r.baseURI.JoinPath("namespaces/", strings.Join(ref, "."))
+
if len(parent) != 0 {
v := url.Values{}
v.Set("parent", strings.Join(parent, namespaceSeparator))
uri.RawQuery = v.Encode()
}
+ type namespaceItem struct {
+ Type string `json:"type"`
+ ID string `json:"id"`
+ Elements []string `json:"elements"`
+ }
+
type rsptype struct {
- Namespaces []table.Identifier `json:"namespaces"`
+ Namespaces []namespaceItem `json:"namespaces"`
}
rsp, err := doGet[rsptype](ctx, uri, []string{}, r.cl,
map[int]error{http.StatusNotFound: catalog.ErrNoSuchNamespace})
if err != nil {
return nil, err
}
- return rsp.Namespaces, nil
+ var result []table.Identifier
+ for _, ns := range rsp.Namespaces {
+ result = append(result, ns.Elements)
+ }
+
+ return result, nil
}
func (r *Catalog) LoadNamespaceProperties(ctx context.Context, namespace
table.Identifier) (iceberg.Properties, error) {
if err := checkValidNamespace(namespace); err != nil {
return nil, err
}
+ ref := table.Identifier{}
+ if refStr := iceberg.GetRefFromContext(ctx); refStr != "" {
+ ref = catalog.ToIdentifier(refStr)
+ }
+
+ type namespaceItem struct {
+ Type string `json:"type"`
+ ID string `json:"id"`
+ Elements []string `json:"elements"`
+ }
Review Comment:
is this something in the actual REST API spec? or is it unique to Nessie's
implementation? If this is unique to Nessie, then I would not be in favor of
adding this to the REST catalog implementation
--
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]