Skip to content

Commit

Permalink
schema: Extract ID fields according to description
Browse files Browse the repository at this point in the history
Use the newly-defined `id_fields` attribute of schemas to extract object
IDs from I/O data correctly. Do not wrap the single-value IDs in tuples
(to produce normalized IDs) to preserve as much backwards compatibility,
as possible.
  • Loading branch information
spbnick committed Oct 18, 2024
1 parent dc836bc commit 5216bb5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions kcidb_io/schema/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,23 @@ def get_ids(cls, data):
Returns:
A dictionary of object list names (types), and lists of IDs of
corresponding objects from the dataset.
objects in the data set. Each ID is either a tuple of values or a
single value (equivalent to a single-value tuple). The values
match the types, the order, and the number of the object's ID
fields as described by the schema's "id_fields" attribute.
"""
assert cls.is_compatible(data)
assert LIGHT_ASSERTS or cls.is_valid(data)
return {
obj_list_name: [obj["id"] for obj in data[obj_list_name]]
for obj_list_name in cls.get_exactly_compatible(data).graph
if obj_list_name and obj_list_name in data
obj_list_name: [
obj[list(id_fields)[0]]
if len(id_fields) == 1 else
tuple(obj[n] for n in id_fields)
for obj in data[obj_list_name]
]
for obj_list_name, id_fields in
cls.get_exactly_compatible(data).id_fields.items()
if data.get(obj_list_name, [])
}

@classmethod
Expand Down

0 comments on commit 5216bb5

Please sign in to comment.