Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b5uEyg58znuchZ8C8i
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
"""Reads 'partition|key|value' lines from stdin, prints one compact line per Debezium event.
|
|
|
|
--sort-lsn : print in WAL order instead of Kafka arrival order. Partitions are read in no particular
|
|
order, so this is for display only; a tombstone takes the LSN of the delete before it.
|
|
"""
|
|
import json, sys
|
|
|
|
def short(o):
|
|
return "null" if o is None else json.dumps(o, separators=(",", ":"))
|
|
|
|
rows, last_lsn = [], {}
|
|
for line in sys.stdin:
|
|
line = line.rstrip("\n")
|
|
if not line.strip():
|
|
continue
|
|
part, key, value = line.split("|", 2)
|
|
if value == "null":
|
|
lsn = last_lsn.get(part, 0)
|
|
rows.append((lsn, 1, f"p={part} key={key} TOMBSTONE (null value)"))
|
|
continue
|
|
v = json.loads(value)
|
|
s = v["source"]
|
|
last_lsn[part] = s["lsn"]
|
|
rows.append((s["lsn"], 0, f"p={part} op={v['op']} key={key} lsn={s['lsn']} txId={s['txId']} snapshot={s['snapshot']} before={short(v['before'])} after={short(v['after'])}"))
|
|
|
|
if "--sort-lsn" in sys.argv:
|
|
rows.sort(key=lambda r: (r[0], r[1]))
|
|
for _, _, text in rows:
|
|
print(text)
|