Skip to content

DGS-19492 Handle records nested in arrays/maps when searching for tags #1890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 7, 2025
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
6 changes: 5 additions & 1 deletion src/confluent_kafka/schema_registry/avro.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,11 @@ def _get_inline_tags_recursively(
return
else:
schema_type = schema.get("type")
if schema_type == 'record':
if schema_type == 'array':
_get_inline_tags_recursively(ns, name, schema.get("items"), tags)
elif schema_type == 'map':
_get_inline_tags_recursively(ns, name, schema.get("values"), tags)
elif schema_type == 'record':
record_ns = schema.get("namespace")
record_name = schema.get("name")
if record_ns is None:
Expand Down
75 changes: 75 additions & 0 deletions tests/schema_registry/test_avro_serdes.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,81 @@ def test_avro_cel_field_transform_complex_with_none():
assert obj2 == newobj


def test_avro_cel_field_transform_complex_nested():
conf = {'url': _BASE_URL}
client = SchemaRegistryClient.new_client(conf)
ser_conf = {'auto.register.schemas': False, 'use.latest.version': True}
schema = {
'type': 'record',
'name': 'UnionTest',
'namespace': 'test',
'fields': [
{
'name': 'emails',
'type': [
'null',
{
'type': 'array',
'items': {
'type': 'record',
'name': 'Email',
'fields': [
{
'name': 'email',
'type': [
'null',
'string'
],
'doc': 'Email address',
'confluent:tags': [
'PII'
]
}
]
}
}
],
'doc': 'Communication Email',
}
]
}

rule = Rule(
"test-cel",
"",
RuleKind.TRANSFORM,
RuleMode.WRITE,
"CEL_FIELD",
None,
None,
"typeName == 'STRING' ; value + '-suffix'",
None,
None,
False
)
client.register_schema(_SUBJECT, Schema(
json.dumps(schema),
"AVRO",
[],
None,
RuleSet(None, [rule])
))

obj = {
'emails': [{'email': 'john@acme.com'}]
}
ser = AvroSerializer(client, schema_str=None, conf=ser_conf)
ser_ctx = SerializationContext(_TOPIC, MessageField.VALUE)
obj_bytes = ser(obj, ser_ctx)

obj2 = {
'emails': [{'email': 'john@acme.com-suffix'}]
}
deser = AvroDeserializer(client)
newobj = deser(obj_bytes, ser_ctx)
assert obj2 == newobj


def test_avro_cel_field_condition():
conf = {'url': _BASE_URL}
client = SchemaRegistryClient.new_client(conf)
Expand Down