Skip to content

Commit 5d6132e

Browse files
authored
use dot notation nestedly to read in struct fields
1 parent 00380c6 commit 5d6132e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

bindings/python/pymongoarrow/schema.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,23 @@ def _normalize_mapping(mapping):
6868
def _get_projection(self):
6969
projection = {"_id": False}
7070
for fname, ftype in self.typemap.items():
71-
if isinstance(ftype, pa.StructType):
72-
for nested_ftype in ftype:
73-
projection[fname+"."+nested_ftype.name] = self._get_field_projection_value(nested_ftype.type)
74-
else:
75-
projection[fname] = self._get_field_projection_value(ftype)
71+
value = self._get_field_projection_value(fname, ftype)
72+
if isinstance(value, bool):
73+
projection[updated_name] = value
74+
elif isinstance(value, dict[str,bool]):
75+
projection.update(value)
7676
return projection
7777

78-
def _get_field_projection_value(self, ftype):
78+
def _get_field_projection_value(self, fname, ftype):
7979
value = True
8080
if isinstance(ftype, pa.ListType):
81-
return self._get_field_projection_value(ftype.value_field.type)
81+
return self._get_field_projection_value(fname, ftype.value_field.type)
8282
if isinstance(ftype, pa.StructType):
8383
projection = {}
8484
for nested_ftype in ftype:
85-
projection[nested_ftype.name] = self._get_field_projection_value(nested_ftype.type)
85+
projection[fname + "." + nested_ftype.name] = self._get_field_projection_value(fname + "." + nested_ftype.name, nested_ftype.type)
8686
value = projection
87-
return value
87+
return fname, value
8888

8989
def __eq__(self, other):
9090
if isinstance(other, type(self)):

0 commit comments

Comments
 (0)