infer schema strategy: nested nullable flips fail and nested {} to null is mangled

Đang mở
#196 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
backend, data

Hướng nghiên cứu

Start with middleware_schema_infer.go, especially inferAndEncodePayload and inferPayloadSchema, where the issue says the witness and nullable merge only inspect top-level fields. Read the existing tests around inferred schema encoding, then add cases for nested empty maps, nullable flips in both directions, and nested type mismatches. Done means empty maps are preserved or rejected, nullable values encode successfully on both sides, and mismatches still fail.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Schema encode middleware: a nested empty map is written as NULL, and a nested value -> NULL flip still fails

Summary

There are two pre-existing limitations of the infer strategy for nested values. #193's fix does not change either of them; it only handles top-level fields.

  1. A nested {} is silently encoded as NULL (invariant 6). The processor returns before = {"n": {"f": {}}} and after = {"n": {"f": nil}}. The schema inferred from after types n as an Avro map whose values are ["null","string"]. The codec accepts the empty map {} for that union and writes it as null. before decodes as {"n": {"f": nil}}, with no error. Main and #193 behave the same. #193 fixes the top-level version of this ({"f": {}} -> {"f": nil}), because there the extracted schema is checked with a lossless round trip first.
  2. A nested value -> NULL flip fails the record. With before = {"n": {"q": 7}} and after = {"n": {"q": nil}}, the map's values are inferred from after as ["null","string"], and before's 7 does not fit (unknown union type int). This fails closed, so it is not data loss. But jsonb or Mongo-style nested documents whose inner fields go to NULL will see error records where Kafka Connect would succeed.

Where

  • middleware_schema_infer.go: inferAndEncodePayload and inferPayloadSchema. The witness and nullable merge only look at top-level fields.
  • The fallback path's plain encodeWithSchema does not round-trip check, because infer accepts documented losses (int widened to long, sub-microsecond time truncation). That is why case 1 passes silently.
  • The codec behaviour (empty map accepted for ["null", T]) is in iskorotkov/avro via conduit-commons' Avro serde.

Proposed fix

  • Make the witness and nullable merge recursive over nested StructuredData and map[string]any. A nested value that is nil on one side takes its type from the other side and becomes nullable at that path. For Avro map values, the nullable union goes on the map's value type.
  • Run the fallback encode through a round-trip check that tolerates only the documented infer losses (number width, time precision), and fails on anything else (a map turned into null, a dropped key).
  • Tests:
    • nested {} -> NULL keeps {} (or fails), never NULL;
    • nested value -> NULL and NULL -> value encode both sides;
    • nested type mismatches still fail.

Out of scope

The extend strategy already fails closed on nested changes ("a key added to or removed from a nested record").

Ngôn ngữ chính
Go
Star
1
Fork
1
Merge trung bình
11 phút
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ConduitIO/conduit-processor-sdk

Tất cả issue của ConduitIO/conduit-processor-sdk

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.