rdblue commented on code in PR #6323: URL: https://github.com/apache/iceberg/pull/6323#discussion_r1199808676
########## python/mkdocs/docs/api.md: ########## @@ -241,52 +146,88 @@ catalog.create_table( ) ``` -Which returns a newly created table: +## Altering the table metadata + +Using the Python API you can alter table metadata. + +### Update the schema + +Add a new field to the table: + +```python +from pyiceberg.schema import Schema +from pyiceberg.types import ( + BooleanType, + DoubleType, + IntegerType, + NestedField, + StringType, + TimestampType, +) + +schema = Schema( + NestedField(field_id=1, name="str", field_type=StringType(), required=False), + NestedField(field_id=2, name="int", field_type=IntegerType(), required=True), + NestedField(field_id=3, name="bool", field_type=BooleanType(), required=False), + NestedField( + field_id=4, name="datetime", field_type=TimestampType(), required=False + ), + # Add a new column to the table + NestedField(field_id=5, name="double", field_type=DoubleType(), required=False), +) + +table = table.alter().set_schema(schema).commit() Review Comment: I really think it is unlikely that we will want to expose a `set_schema` function. That may be a simple API, but it makes it harder for both the caller and for the library to do things correctly. It would force the caller to understand field IDs and how they are used to correctly construct new schemas. The caller also needs to know that the library will reassign field IDs when a table is created, so they can't just modify the original schema used to create a table. This has been really confusing for people in the past. For the library, we have to detect the changes that are being made and validate them. It's not too bad to detect changes, but it's still harder. -- 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]
