Skip to content

#855 Add COMP-1 and COMP-2 floating point encoders for the writer.#856

Merged
yruslan merged 2 commits into
masterfrom
feature/855-add-comp-1-2-support-for-writer
Jun 19, 2026
Merged

#855 Add COMP-1 and COMP-2 floating point encoders for the writer.#856
yruslan merged 2 commits into
masterfrom
feature/855-add-comp-1-2-support-for-writer

Conversation

@yruslan

@yruslan yruslan commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Closes #855

Summary by CodeRabbit

  • New Features

    • Added configurable floating-point format support for COBOL COMP-1 and COMP-2 encoding, including IEEE 754 and IBM variants with selectable endianness (and consistent handling of special values like NaN/infinities).
  • Bug Fixes

    • Ensured the selected floating-point format is correctly applied during primitive encoding.
  • Tests

    • Added byte-level encoder validation across IEEE 754 and IBM formats, plus writer tests covering multiple floating_point_format options with edge-case coverage.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 92dbb085-e989-4a4b-901f-0646b0fa8b2b

📥 Commits

Reviewing files that changed from the base of the PR and between 0e4a2d5 and 124bcad.

📒 Files selected for processing (2)
  • cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/encoding/EncoderSelector.scala
  • cobol-parser/src/test/scala/za/co/absa/cobrix/cobol/parser/encoding/FloatingPointEncodersSuite.scala
🚧 Files skipped from review as they are similar to previous changes (1)
  • cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/encoding/EncoderSelector.scala

Walkthrough

Adds write support for COBOL COMP-1 and COMP-2 floating-point fields. A new FloatingPointEncoders object provides byte-array encoders for IEEE-754 and IBM hex-float formats in both endiannesses. EncoderSelector.getEncoder gains a floatingPointFormat parameter and new dispatch cases routing COMP1/COMP2 decimal types to those encoders. ParserVisitor is updated to thread floatingPointFormat through. Comprehensive unit and integration tests cover all four encoding formats.

Changes

COMP-1/COMP-2 floating-point write support

Layer / File(s) Summary
FloatingPointEncoders: IEEE-754 and IBM hex-float byte encoders
cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/encoding/FloatingPointEncoders.scala
New singleton object with eight encoding methods: IEEE-754 single/double in both endiannesses via ByteBuffer, and IBM hex-float single/double big-endian with special-case handling for 0.0, NaN, and infinities plus base-16 exponent/fraction packing; little-endian IBM variants produced by byte reversal.
EncoderSelector: COMP1/COMP2 dispatch and ParserVisitor wiring
cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/encoding/EncoderSelector.scala, cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/antlr/ParserVisitor.scala
getEncoder receives a new floatingPointFormat parameter (default IBM); two new match arms route Decimal(COMP1)/Decimal(COMP2) to getSingleFloatingPointEncoder/getDoubleFloatingPointEncoder helpers that convert numeric inputs and delegate to FloatingPointEncoders. ParserVisitor.visitPrimitive passes floatingPointFormat to getEncoder.
FloatingPointEncodersSuite: unit tests for floating-point encoders
cobol-parser/src/test/scala/za/co/absa/cobrix/cobol/parser/encoding/FloatingPointEncodersSuite.scala
Test suite validating all eight encoder functions across IEEE-754 and IBM formats: exact-byte assertions for zero, one, negative one, infinities, NaN, and MaxValue/MinPositiveValue; round-trip decode validation; and byte-position/endianness verification for sign, exponent, and fraction fields.
FixedLengthEbcdicWriterSuite: COMP-1/COMP-2 encoding integration tests
spark-cobol/src/test/scala/za/co/absa/cobrix/spark/cobol/writer/FixedLengthEbcdicWriterSuite.scala
Four integration test cases validate each floating_point_format option (IEEE754_little_endian, IEEE754, IBM_little_endian, IBM) by writing DataFrames with positive/negative/zero/infinity/NaN/null float values and asserting written bytes match pre-computed expected arrays.

Sequence Diagram(s)

sequenceDiagram
    participant ParserVisitor
    participant EncoderSelector
    participant SingleFloatHelper as getSingle<br/>FloatingPoint<br/>Encoder
    participant DoubleFloatHelper as getDouble<br/>FloatingPoint<br/>Encoder
    participant FloatingPointEncoders

    ParserVisitor->>EncoderSelector: getEncoder(Decimal(COMP1), floatingPointFormat=IEEE754)
    EncoderSelector->>SingleFloatHelper: convert input to Float
    SingleFloatHelper->>FloatingPointEncoders: encodeIeee754SingleBigEndian(f)
    FloatingPointEncoders-->>SingleFloatHelper: Array[Byte]
    SingleFloatHelper-->>EncoderSelector: Encoder
    EncoderSelector-->>ParserVisitor: Some(Encoder)

    ParserVisitor->>EncoderSelector: getEncoder(Decimal(COMP2), floatingPointFormat=IBM)
    EncoderSelector->>DoubleFloatHelper: convert input to Double
    DoubleFloatHelper->>FloatingPointEncoders: encodeIbmDoubleBigEndian(d)
    FloatingPointEncoders-->>DoubleFloatHelper: Array[Byte]
    DoubleFloatHelper-->>EncoderSelector: Encoder
    EncoderSelector-->>ParserVisitor: Some(Encoder)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • AbsaOSS/cobrix#783: Modifies the same EncoderSelector.scala encoder dispatch pipeline that this PR extends for COMP-1/COMP-2 support.

Poem

A bunny once hopped through mainframe land,
Where COMP-1 and COMP-2 values expand.
IEEE-754, IBM hex-float bytes in place,
Big-endian, little-endian—encoded with grace.
🐇 With a flip and a scale, the floats find their way,
Written to EBCDIC data, hooray! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the main change: adding COMP-1 and COMP-2 floating point encoders for the writer, which matches the core objective of the PR.
Linked Issues check ✅ Passed The code changes successfully implement support for writing COMP-1 and COMP-2 fields by introducing floating point encoders with multiple format support (IEEE754, IBM, endianness variants) and updating the writer to use them.
Out of Scope Changes check ✅ Passed All changes are focused on the floating point encoder implementation and writer support for COMP-1/COMP-2. No unrelated modifications detected outside the stated objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/855-add-comp-1-2-support-for-writer

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

JaCoCo code coverage report - 'cobol-parser'

Overall Project 90.17% -0.04% 🍏
Files changed 96.27% 🍏

File Coverage
FloatingPointEncoders.scala 97.35% -2.65% 🍏
ParserVisitor.scala 89.46% 🍏
EncoderSelector.scala 87.2% -2.4% 🍏

@github-actions

Copy link
Copy Markdown

JaCoCo code coverage report - 'spark-cobol'

Overall Project 83.4% 🍏

There is no coverage information present for the Files changed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/encoding/EncoderSelector.scala`:
- Line 189: In the getDoubleFloatingPointEncoder method, the fallback case at
line 189 converts values using x.toString.toFloat which causes precision loss.
Change this to x.toString.toDouble to maintain proper double-precision accuracy
when handling non-standard input types in the encoder.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 15ddd494-8ff3-45f9-a705-9e95a7a325c6

📥 Commits

Reviewing files that changed from the base of the PR and between 1e6e9f7 and 0e4a2d5.

📒 Files selected for processing (4)
  • cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/antlr/ParserVisitor.scala
  • cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/encoding/EncoderSelector.scala
  • cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/encoding/FloatingPointEncoders.scala
  • spark-cobol/src/test/scala/za/co/absa/cobrix/spark/cobol/writer/FixedLengthEbcdicWriterSuite.scala

@yruslan yruslan merged commit 2f1d330 into master Jun 19, 2026
7 checks passed
@yruslan yruslan deleted the feature/855-add-comp-1-2-support-for-writer branch June 19, 2026 08:14
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.

Add support for writing COMP-1 and COMP-2 fields

1 participant