Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion flow/record/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,13 @@ def __init__(self, name: str, records: list[Record | GroupedRecord]):
self.fieldname_to_record[fname] = rec
if fname not in required_fields:
self.flat_fields.append(field)
# flat descriptor to maintain compatibility with Record
# Flat descriptor to maintain compatibility with Record

self._desc = RecordDescriptor(self.name, [(f.typename, f.name) for f in self.flat_fields])

# _field_types to maintain compatibility with RecordDescriptor
self._field_types = self._desc.recordType._field_types

def get_record_by_type(self, type_name: str) -> Record | None:
"""
Get record in a GroupedRecord by type_name.
Expand Down
17 changes: 16 additions & 1 deletion tests/test_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ def test_grouped_record() -> None:
("string", "hello"),
],
)
expected_field_types = {
"hello": fieldtypes.string,
"world": fieldtypes.string,
"count": fieldtypes.uint32,
"assignee": fieldtypes.string,
"profile": fieldtypes.string,
"_source": fieldtypes.string,
"_classification": fieldtypes.string,
"_generated": fieldtypes.datetime,
"_version": fieldtypes.varint,
}

test_record = TestRecord("a", "b", 12345)
meta_record = WQMetaRecord("me", "this is a test", "other hello")
Expand All @@ -176,7 +187,7 @@ def test_grouped_record() -> None:

assert len(grouped.records) == 2

# test grouped._asdict
# Test grouped._asdict
rdict = grouped._asdict()
assert {"hello", "world", "count", "assignee", "profile"} <= set(rdict)

Expand All @@ -185,6 +196,10 @@ def test_grouped_record() -> None:
assert rdict["profile"] == "omg"
assert rdict["count"] == 12345

# Test grouped._field_types
assert grouped._field_types
assert grouped._field_types == expected_field_types


def test_grouped_records_packing(tmp_path: Path) -> None:
RecordA = RecordDescriptor(
Expand Down