samredai opened a new pull request #4318:
URL: https://github.com/apache/iceberg/pull/4318
This adds the Schema class by carving it out of PR #3228 by @nssalian and
building upon it.
A `Schema` object is created by providing a list of `NestedField` instances,
a schema ID, and optionally a map of aliases to field IDs. The
`get_field_id(...)` method allows you to retrieve a field ID by providing the
field name or an alias, and the `get_field(...)` method allows you to retrieve
the field object by providing the field ID. There's also a `get_type` method
that lets you retrieve the type of field by providing the field ID.
```py
from iceberg.table.schema import Schema
from iceberg.types import BooleanType, IntegerType, NestedField, StringType
fields = [
NestedField(field_id=1, name="foo", field_type=StringType(),
is_optional=False),
NestedField(field_id=2, name="bar", field_type=IntegerType(),
is_optional=True),
NestedField(field_id=3, name="baz", field_type=BooleanType(),
is_optional=False),
]
table_schema = Schema(fields=fields, schema_id=1, aliases={"qux": 3})
print(table_schema)
```
output
```
1: name=foo, type=string, required=True
2: name=bar, type=int, required=False
3: name=baz, type=boolean, required=True
```
--
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]