Repository navigation
feat: Add initial support for create table CLI through json schema - #424
Conversation
Yea, let's not attempt to parse SQL ourselves haha. Providing it via JSON should be fine. |
| // 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 | ||
| } |
There was a problem hiding this comment.
do we actually need this function instead of just letting people use json.Unmarshal(bytes, &schema) ?
There was a problem hiding this 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() in order to be called in main.
What do you think?
There was a problem hiding this comment.
Okay that's fair enough, we should probably rename the argument to be --fields then instead 😄
| --description TEXT specify a description for the namespace | ||
| --location-uri TEXT specify a location URI for the namespace` | ||
| --location-uri TEXT specify a location URI for the namespace | ||
| --fields TEXT specify table schema fields in json (for create table use only) |
There was a problem hiding this comment.
this is the json serialization rule for schema
https://iceberg.apache.org/spec/#schemas
There was a problem hiding this comment.
Hi @kevinjqliu, thank you for looking into this! I think schema and fields was also discussed above with @zeroshade
#424 (comment)
The concern about specifying a full schema json is that user will also be asked to provide the json field for "schema-id", "identifier-field-ids", which are more like internal metadata that user don't need to worry about. And usually create table only requires specifying the table fields and their type, so it's just the fields. Although I feel like the word schema is more understandable compare to fields.
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}
]
}'
and
--fields '{[
{"id":1,"name":"id","type":"int","required":true},
{"id":2,"name":"name","type":"string","required":false}
]}'
There was a problem hiding this comment.
oh thanks for pointing me to that, i didnt see it initially.
i like
--schema '{[
{"name":"id","type":"int","required":true},
{"name":"name","type":"string","required":false}
]}'
we dont necessary need schema-id, theres a default value. we can also provide --schema-id to override it.
Similarly for identifier-field-ids, its default to empty list and we can use --identifier-field-ids to override that param too.
the id inside the fields can also be auto assigned.
For me, the --schema represents the schema of the table itself, without any of the details about iceberg tables.
go run . create table lliangyu_test_db.test_tbl \
--catalog glue \
--schema '[{"name":"id","type":"int","required":false},{"name":"name","type":"string","required":true}]' \
--location-uri s3://xxxxx/xxxxx
should be sufficient
WDYT? This is definitely a nit comment :)
There was a problem hiding this comment.
I totally agree. I like --schema '[{"name":"id","type":"int","required":false},{"name":"name","type":"string","required":true}]' as well. Put out an update on this.
I'm thinking we could support schema-id, identifier-field-ids in separate PRs.
kevinjqliu
left a comment
There was a problem hiding this comment.
LGTM!
I dont think we have integration tests yet but it'll be good to run this against a catalog :)
| --schema TEXT specify table schema in json (for create table use only) | ||
| Ex: [{"name":"id","type":"int","required":false,"doc":"unique id"}]` |
There was a problem hiding this comment.
should this be TEXT or JSON?
There was a problem hiding this comment.
also does the Ex:... part show up in usage? all the other options have 1 line only
There was a problem hiding this comment.
should this be TEXT or JSON?
Goot point, I think JSON make more sense. Let me update that
also does the Ex:... part show up in usage?
Yes, this is what shows up when I ran go run . -h. Definitely feel like the formatting could be improved, but I think could be fixed later.
Options:
-h --help show this help messages and exit
--catalog TEXT specify the catalog type [default: rest]
--uri TEXT specify the catalog URI
--output TYPE output type (json/text) [default: text]
--credential TEXT specify credentials for the catalog
--warehouse TEXT specify the warehouse to use
--config TEXT specify the path to the configuration file
--description TEXT specify a description for the namespace
--location-uri TEXT specify a location URI for the namespace
--schema TEXT specify table schema in json (for create table use only)
Ex: [{"name":"id","type":"int","required":false,"doc":"unique id"}]
There was a problem hiding this comment.
thanks for checking! I just wanted to make sure its not truncated :)
|
Thanks for the contribution @lliangyu-lin! I just tested this locally against pyiceberg's integration test's IRC. did not output any messages, even though it ran successfully Another run of the same command outputted: I also noticed that when running I think we can address these in a followup PR :) |
…it table API and improve references (#429) ### Description * Close the gap in properties CLI using the commit table implementation * Update references and loggings as mentioned in #424 ### Testing ``` go run . properties get table lliangyu_test_db.tbl1 --catalog glue ┌──────────────┐ | Key | Value | | ------------ | | key1 | val1 | └──────────────┘ go run . properties set table lliangyu_test_db.tbl1 write.object-storage.enabled true --catalog glue Setting write.object-storage.enabled=true on lliangyu_test_db.tbl1 Updated write.object-storage.enabled on lliangyu_test_db.tbl1 go run . properties get table lliangyu_test_db.tbl1 --catalog glue ┌──────────────────────────────────────┐ | Key | Value | | ------------------------------------ | | key1 | val1 | | write.object-storage.enabled | true | └──────────────────────────────────────┘
Description
id bigint NOT NULL COMMENT 'unique id', but the parsing may get complicated with nestings.Testings
Result metadata file