samredai edited a comment on pull request #4318:
URL: https://github.com/apache/iceberg/pull/4318#issuecomment-1082617851
Added an `IndexByName` visitor and did a comparison with the java client
which produces the same result.
```java
import org.apache.iceberg.Schema;
import org.apache.iceberg.types.Types;
import org.apache.iceberg.types.TypeUtil;
Schema schema = new Schema(
Types.NestedField.required(1, "foo", Types.StringType.get()),
Types.NestedField.optional(2, "bar", Types.IntegerType.get()),
Types.NestedField.required(3, "baz", Types.BooleanType.get()),
Types.NestedField.required(4, "qux", Types.ListType.ofOptional(5,
Types.StringType.get())),
Types.NestedField.required(6, "quux", Types.MapType.ofOptional(7, 8,
Types.StringType.get(), Types.MapType.ofOptional(9, 10, Types.StringType.get(),
Types.IntegerType.get())))
);
Map<String, Integer> index = TypeUtil.indexByName(schema.asStruct());
System.out.println(index);
```
output:
```
{foo=1, bar=2, baz=3, qux=4, qux.element=5, quux=6, quux.key=7,
quux.value=8, quux.value.key=9, quux.value.value=10}
```
```py
from iceberg.types import (
BooleanType,
IntegerType,
ListType,
MapType,
NestedField,
StringType,
StructType,
)
from iceberg.table.schema import Schema, index_by_name
schema = Schema(
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),
NestedField(field_id=4, name="qux", field_type=ListType(element_id=5,
element_type=StringType(), element_is_optional=True), is_optional=True),
NestedField(field_id=6, name="quux", field_type=MapType(key_id=7,
key_type=StringType(), value_id=8, value_type=MapType(key_id=9,
key_type=StringType(), value_id=10, value_type=IntegerType(),
value_is_optional=True), value_is_optional=True), is_optional=True)
)
index = index_by_name(schema)
print(index)
```
output:
```
{'foo': 1, 'bar': 2, 'baz': 3, 'qux': 4, 'qux.element': 5, 'quux': 6,
'quux.key': 7, 'quux.value': 8, 'quux.value.key': 9, 'quux.value.value': 10}
```
--
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]