Repository navigation
feat: add exclude_fields option and drop trailing ">" on end edges - #8
Merged
Merged
Conversation
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.
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 |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
CLI
End edges
Tests
Docs: README (usage, exclude_fields table, CLI example, E section) and CHANGELOG.