jnagel12 commented on code in PR #629:
URL: https://github.com/apache/iceberg-go/pull/629#discussion_r2542719245


##########
catalog/rest/rest.go:
##########
@@ -1159,55 +1159,95 @@ type createViewRequest struct {
        Schema      *iceberg.Schema    `json:"schema"`
        Location    string             `json:"location,omitempty"`
        Props       iceberg.Properties `json:"properties,omitempty"`
-       SQL         string             `json:"sql"`
-       ViewVersion view.Version       `json:"view-version"`
+       ViewVersion *view.Version      `json:"view-version"`
 }
 
 type viewResponse struct {
        MetadataLoc string             `json:"metadata-location"`
        RawMetadata json.RawMessage    `json:"metadata"`
        Config      iceberg.Properties `json:"config"`
-       Metadata    table.Metadata     `json:"-"`
+       Metadata    view.Metadata      `json:"-"`
+}
+
+func (v *viewResponse) UnmarshalJSON(b []byte) (err error) {
+       type Alias viewResponse
+       if err = json.Unmarshal(b, (*Alias)(v)); err != nil {
+               return err
+       }
+
+       v.Metadata, err = view.ParseMetadataBytes(v.RawMetadata)
+
+       return
 }
 
 // CreateView creates a new view in the catalog.
-func (r *Catalog) CreateView(ctx context.Context, identifier table.Identifier, 
schema *iceberg.Schema, sql string, props iceberg.Properties) error {
-       ns, v, err := splitIdentForPath(identifier)
+func (r *Catalog) CreateView(ctx context.Context, identifier table.Identifier, 
version *view.Version, schema *iceberg.Schema, opts ...catalog.CreateViewOpt) 
(*view.View, error) {
+       ns, viewName, err := splitIdentForPath(identifier)
        if err != nil {
-               return err
+               return nil, err
+       }
+
+       if opts == nil {
+               opts = []catalog.CreateViewOpt{}
+       }
+       cfg := catalog.NewCreateViewCfg()
+       for _, opt := range opts {
+               opt(&cfg)
        }
 
        freshSchema, err := iceberg.AssignFreshSchemaIDs(schema, nil)
        if err != nil {
-               return err
+               return nil, err
+       }
+

Review Comment:
   I think one way of doing this is making Version an interface and making the 
struct private. What do you think? TimestampMS is defaulted to `now` in that 
constructor. 
   
   If we only take representations we lose the ability to set the summary and 
default NS, and adding those explicitly to the REST call bloats the parameter 
list



-- 
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