Skip to content

#3833: ETL unpacker reads any EBCDIC code page, Decimal not float, never a silent 0.0 - #3894

Merged
squid-protocol merged 2 commits into
mainfrom
fleet/3833-etl
Sep 27, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
fleet/3833-etl

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Part of #3833 (the "ETL unpacker" bullet).

What changed

gitgalaxy/tools/cobol_to_cobol/cobol_etl_unpacker.py:

  • Code page is a parameter. New --code-page (default cp037), validated by resolve_code_page: calls gitgalaxy.core.ebcdic_codecs.register(), then codecs.lookup, and rejects a non-EBCDIC codec (e.g. utf-8) by checking that bytes F0-F9 decode to 0-9. A bad page exits with code 2. Text fields and zoned digits both decode in that page, so cp273 / cp277 / cp278 / cp297 / cp1047 files now come out as the right letters.
  • Decimal, not float. unpack_comp3 and the new unpack_zoned return decimal.Decimal, built exactly from the digits with exponent -decimals. The CSV gets format(value, "f"), so there is no exponent and the field's scale is kept (12.50 for V99, 0.10, 0.0000001). Negative zero prints as 0.00.
  • Signed zoned. The last byte's overpunch is read with java_target.zoned_sign_characters(code_page), so there is no second sign table: cp037 uses {A-I / }J-R, cp277 uses æ... / å..., and so on.
  • Invalid data is loud (strict). The CLI had no lenient mode, so I chose the strict rule. A zoned field that is not all digits with an optional last-byte overpunch, or a packed field with a digit nibble above 9 or a sign nibble outside A-F, raises UnpackError("record N, field NAME: ..."). The CLI prints it, deletes the partial CSV and exits with code 1. No value is ever written as 0.0 for bad data.
  • COMP-3 signs are unchanged: C/A/E/F are positive (F = unsigned) and D/B are negative.
  • docs/wiki/05-09-etl-unpacker.md: describes the code page, Decimal, zoned signs and the strict rule, and drops the "cp037 only" limitation.

Tests

tests/cobol_mainframe/test_cobol_etl_unpacker.py. The two existing float assertions in test_unpack_comp3 now compare with Decimal (Decimal("1234.56") != 1234.56); nothing was removed. New tests:

  • cp273 German text (MÜLLÄÖß) round-trips, and the same bytes read under cp037 do not.
  • cp277 Nordic text (ÆØÅæøå) round-trips.
  • Zoned S9(5)V99 -1234.50 gives -1234.50 under cp037, cp277, cp273 and cp297.
  • A positive overpunch gives 12.50, and unsigned zoned gives 0.10.
  • COMP-3 S9(7)V99 0.10 gives exactly 0.10.
  • Negative zero and a tiny value print with no exponent.
  • Corrupt zoned (a sign mid-field, spaces, a lowercase letter) and corrupt packed data raise.
  • A corrupt record stops the CLI with exit 1, the error names record 2, field AMOUNT, and no CSV is left behind.
  • A bad --code-page exits with code 2.

18 of the 21 tests fail on main.

Not done, and why

  • Behaviour change to be aware of: an all-spaces numeric field used to become 0.0 and is now an error. Spaces are not a valid zoned number, and writing 0.0 for them is exactly the silent data loss this bullet is about. If blank numerics turn out to be common in real extracts, a --lenient mode (empty cell plus a reported count) could follow.
  • A trailing partial record is still dropped silently at EOF (len(record_bytes) < record_length: break). That is pre-existing and out of this bullet's scope.
  • The pre-existing parenthesised with (...) is Python 3.10+ syntax; I left it untouched.
  • SIGN LEADING / SIGN SEPARATE zoned fields are not in the JSON schema, so they are not handled (unchanged).

Gates

python tests/tools/pr_gates.py: 7/7 pass (lint, audits, secrets, xray, gauntlet, golden 212s, suite 1035s). No golden masters, baselines or refraction snapshots moved. After merging origin/main, ruff format, ruff_audit --ci and mypy_audit --ci are clean.

🤖 Generated with Claude Code

…gned zoned, never a silent 0.0

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

…0.0, not a failed run

All EBCDIC spaces (X'40') or low-values (X'00') in a zoned or packed field is
an unfilled field, common in real extracts: it becomes an empty CSV cell (a
NULL downstream) and the run reports how many. Garbage -- a sign mid-field,
a letter, a bad nibble -- still stops the run naming record and field.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@squid-protocol
squid-protocol merged commit 03e8831 into main Sep 27, 2026
37 checks passed
@squid-protocol
squid-protocol deleted the fleet/3833-etl branch September 27, 2026 16:43
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.

1 participant