lliangyu-lin commented on code in PR #424:
URL: https://github.com/apache/iceberg-go/pull/424#discussion_r2080512350


##########
schema.go:
##########
@@ -51,6 +51,17 @@ type Schema struct {
        lazyNameMapping func() NameMapping
 }
 
+// NewSchemaFromJson constructs a new schema with the provided ID and a string 
in json form
+func NewSchemaFromJson(id int, jsonStr string) (*Schema, error) {
+       var fields []NestedField
+       err := json.Unmarshal([]byte(jsonStr), &fields)
+       if err != nil {
+               return nil, fmt.Errorf("failed to parse schema JSON: %w", err)
+       }
+
+       return NewSchema(id, fields...), nil
+}

Review Comment:
   @zeroshade Thanks for the review! I think for directly parse to schema means 
user also needs to provide the other fields in the actual schema structure in 
https://github.com/apache/iceberg-go/blob/main/schema.go#L36-L39
   Ex:
   ```
   --schema '{
     "schema-id": 1,
     "identifier-field-ids": [1],
     "fields": [
       {"id":1,"name":"id","type":"int","required":true},
       {"id":2,"name":"name","type":"string","required":false}
     ]
   }'
   ```
   I'm not sure if it's good idea to ask user to specify the `schema-id` and 
`identifier-field-ids`. 
   But I agree that a new function may not be needed, we can simply parse in 
main whether it's entire schema or just the fields, but my concern is we also 
then export the 
[init()](https://github.com/apache/iceberg-go/blob/main/schema.go#L70) in order 
to be called in main.
   
   What do you think?



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to