Skip to content

feat: add exclude_fields option and drop trailing ">" on end edges - #8

Merged
gcattan merged 3 commits into
mainfrom
feat/drop-tailing-exclude-files
Oct 30, 2026
Merged

gcattan merged 3 commits into
mainfrom
feat/drop-tailing-exclude-files

Conversation

@Adelaiten

Copy link
Copy Markdown
Collaborator

Add a statically configured list of fields excluded from the LDF output, exposed in the library and the CLI, and shorten the encoding of end edges to save tokens.

exclude_fields

  • New option of json_to_lineage_format(graph, {"exclude_fields": [...]}). The default (empty list) leaves the output unchanged.
  • Matching: a bare name removes the field at every nesting level; a dotted path ("technology.id") removes only that field, arrays take no indices and paths are relative to the asset/edge; removing an object or array removes its whole content; wildcards use fnmatch; unknown entries are ignored (logged at debug level).
  • Exclusion runs on a copy of the input before serialization, so the output has no empty separators, entries or sections, and no trace in the header (no path=/T/TID without technology, no HP/parent index without hierarchical_path).
  • Partially removed records use named forms instead of empty positional slots: chc=/cha=/chh= for children, i=/n=/t= in HP segments, n=name or bare id in BT/BC/DC/DSD, attributes without name or value, node head without type. The decoder reads all of them, so excluded output still round-trips.
  • Validation: TypeError for a non-list of str; ValueError when an asset id or an edge source/target is removed.

CLI

  • ldf json-to-lineage gains --exclude (comma-separated and/or repeated).
  • convert_json_file_to_lineage gains an optional exclude_fields argument.

End edges

  • An edge without a target is written as "N7" instead of "N7>" in E and EP. The decoder still accepts the old form and still drops such edges.
  • This changes the default output for inputs that contain edges without a target (20 of 50 edges in big_query_lineage.json, 40 characters fewer). Everything else is unchanged.

Tests

  • tests/test_exclude_fields.py (236 tests): synthetic graphs, validation, names, dotted paths, wildcards, no-trace checks, round trips, CLI, end edges, and an exhaustive and randomised run over big_query_lineage.json (skipped when the file is absent).

Docs: README (usage, exclude_fields table, CLI example, E section) and CHANGELOG.

Add a statically configured list of fields excluded from the LDF output,
exposed in the library and the CLI, and shorten the encoding of end edges
to save tokens.

exclude_fields
- New option of json_to_lineage_format(graph, {"exclude_fields": [...]}).
  The default (empty list) leaves the output unchanged.
- Matching: a bare name removes the field at every nesting level; a dotted
  path ("technology.id") removes only that field, arrays take no indices and
  paths are relative to the asset/edge; removing an object or array removes
  its whole content; wildcards use fnmatch; unknown entries are ignored
  (logged at debug level).
- Exclusion runs on a copy of the input before serialization, so the output
  has no empty separators, entries or sections, and no trace in the header
  (no path=/T/TID without technology, no HP/parent index without
  hierarchical_path).
- Partially removed records use named forms instead of empty positional
  slots: chc=/cha=/chh= for children, i=/n=/t= in HP segments, n=name or bare
  id in BT/BC/DC/DSD, attributes without name or value, node head without
  type. The decoder reads all of them, so excluded output still round-trips.
- Validation: TypeError for a non-list of str; ValueError when an asset id or
  an edge source/target is removed.

CLI
- ldf json-to-lineage gains --exclude (comma-separated and/or repeated).
- convert_json_file_to_lineage gains an optional exclude_fields argument.

End edges
- An edge without a target is written as "N7" instead of "N7>" in E and EP.
  The decoder still accepts the old form and still drops such edges.
- This changes the default output for inputs that contain edges without a
  target (20 of 50 edges in big_query_lineage.json, 40 characters fewer).
  Everything else is unchanged.

Tests
- tests/test_exclude_fields.py (236 tests): synthetic graphs, validation,
  names, dotted paths, wildcards, no-trace checks, round trips, CLI, end
  edges, and an exhaustive and randomised run over big_query_lineage.json
  (skipped when the file is absent).

Docs: README (usage, exclude_fields table, CLI example, E section) and
CHANGELOG.
@Adelaiten
Adelaiten requested a review from gcattan October 30, 2026 12:19
@Adelaiten Adelaiten self-assigned this Oct 30, 2026
@gcattan

gcattan commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Ok, spot a bug with the decoder. Pushing some fix. Not related to your PR, but the type of the edge was dropped.

The token saving is less than expected, because >\n is in fact a single token.

The decoder dropped every edge without a target, together with its EP
type, so end edges (including summary ones) did not survive a round
trip. They are now returned as an edge with only "source" (and "type"
when present), from both "N7" and the older "N7>".

EP types were matched to edges by "source>target" alone, so several
edges between the same pair all took the last type (direct + summary
came back as summary + summary). Types are now queued per pair and
consumed in E order. An untyped edge written before a typed edge on the
same pair still gets the type on the first of the two; the format has no
index to tell them apart.

Tests that asserted the old dropping are updated, and regression tests
cover end edges (typed, untyped, compact, after exclusion, legacy form)
and same-pair duplicates. The CHANGELOG no longer claims a token saved
per edge: `>\n` is one token, so only typed end edges save one, in EP.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fix: decode end edges and match EP types per pair in order
@gcattan
gcattan merged commit 47e7bc6 into main Oct 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants