-
Notifications
You must be signed in to change notification settings - Fork 86
#795 Add the ability to process EBCDIC files in-place and convert them to VRL format #799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
61cb376
#795 Implement the CobolProcessor that allows changing record sizes.
yruslan daef609
#795 Use big-endian RDWs when generating VRL file.
yruslan 89520b8
#795 Add a feature to get RDD of raw records for raw EBCDIC processing.
yruslan 9d9c23d
#795 Add support for indexes when processing raw records via RDDs.
yruslan 98751ef
#795 Improve the syntax of generating raw record RDDs.
yruslan b4f5707
#795 Add the description for the new feature to README.
yruslan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
24 changes: 24 additions & 0 deletions
24
cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/processor/CobolProcessingStrategy.scala
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * Copyright 2018 ABSA Group Limited | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package za.co.absa.cobrix.cobol.processor | ||
|
|
||
| trait CobolProcessingStrategy | ||
|
|
||
| object CobolProcessingStrategy { | ||
| case object InPlace extends CobolProcessingStrategy | ||
| case object ToVariableLength extends CobolProcessingStrategy | ||
| } |
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
50 changes: 50 additions & 0 deletions
50
cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/processor/impl/CobolProcessorBase.scala
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Copyright 2018 ABSA Group Limited | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package za.co.absa.cobrix.cobol.processor.impl | ||
|
|
||
| import za.co.absa.cobrix.cobol.processor.CobolProcessor | ||
| import za.co.absa.cobrix.cobol.reader.VarLenNestedReader | ||
| import za.co.absa.cobrix.cobol.reader.extractors.raw.RawRecordExtractor | ||
| import za.co.absa.cobrix.cobol.reader.parameters.ReaderParameters | ||
| import za.co.absa.cobrix.cobol.reader.stream.SimpleStream | ||
|
|
||
| /** | ||
| * Implements common methods of direct EBCDIC to EBCDIC data processor implementations. | ||
| * | ||
| * The processing can be done from inside an RDD so this is why it is serializable. | ||
| */ | ||
| abstract class CobolProcessorBase extends CobolProcessor with Serializable | ||
|
|
||
| object CobolProcessorBase { | ||
| def getRecordExtractor(readerParameters: ReaderParameters, copybookContents: String, inputStream: SimpleStream, headerStreamOpt: Option[SimpleStream]): RawRecordExtractor = { | ||
| val dataStream = inputStream.copyStream() | ||
| val headerStream = headerStreamOpt match { | ||
| case Some(stream) => stream | ||
| case None => inputStream.copyStream() | ||
| } | ||
|
|
||
| val reader = new VarLenNestedReader[Array[Any]](Seq(copybookContents), readerParameters, new ArrayOfAnyHandler) | ||
|
|
||
| reader.recordExtractor(0, dataStream, headerStream) match { | ||
| case Some(extractor) => extractor | ||
| case None => | ||
| throw new IllegalArgumentException(s"Cannot create a record extractor for the given reader parameters. " + | ||
| "Please check the copybook and the reader parameters." | ||
| ) | ||
| } | ||
| } | ||
| } |
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
53 changes: 53 additions & 0 deletions
53
cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/processor/impl/CobolProcessorToRdw.scala
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Copyright 2018 ABSA Group Limited | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package za.co.absa.cobrix.cobol.processor.impl | ||
|
|
||
| import za.co.absa.cobrix.cobol.parser.Copybook | ||
| import za.co.absa.cobrix.cobol.processor.RawRecordProcessor | ||
| import za.co.absa.cobrix.cobol.reader.parameters.ReaderParameters | ||
| import za.co.absa.cobrix.cobol.reader.stream.SimpleStream | ||
|
|
||
| import java.io.OutputStream | ||
|
|
||
| /** | ||
| * Implementation of the CobolProcessor trait, responsible for processing COBOL data streams | ||
| * by extracting records and applying a user-defined raw record processor. This processor | ||
| * converts the input format to the variable record length format with big-endian RDW records. | ||
| * | ||
| * Please, do not use this class directly. Use `CobolProcessor.builder()` instead. | ||
| * | ||
| * @param readerParameters Configuration for record extraction and COBOL file parsing. | ||
| * @param copybook The copybook definition used for interpreting COBOL data structures. | ||
| * @param copybookContents The raw textual representation of the copybook. | ||
| * @param options A map of processing options to customize the behavior of the processor (same as for `spark-cobol`). | ||
| */ | ||
| class CobolProcessorToRdw(readerParameters: ReaderParameters, | ||
| copybook: Copybook, | ||
| copybookContents: String, | ||
| options: Map[String, String]) extends CobolProcessorBase { | ||
| override def process(inputStream: SimpleStream, | ||
| outputStream: OutputStream) | ||
| (rawRecordProcessor: RawRecordProcessor): Long = { | ||
| val recordExtractor = CobolProcessorBase.getRecordExtractor(readerParameters, copybookContents, inputStream, None) | ||
|
|
||
| StreamProcessor.processStreamToRdw(copybook, | ||
| options, | ||
| recordExtractor, | ||
| rawRecordProcessor, | ||
| outputStream) | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify RDW length calculation includes RDW header.
Line 99 calculates the RDW using only
updatedRecord.length. According to IBM mainframe VRL standards, the RDW length field typically includes the 4-byte RDW header itself. This means the length should beupdatedRecord.length + 4.Verify that the current calculation matches your intended RDW format specification. If this needs to be compatible with standard mainframe VRL readers, the length should likely include the RDW header.
🏁 Script executed:
Length of output: 131567
[/run_scripts]
🏁 Script executed:
Length of output: 6151
[/run_scripts]
🏁 Script executed:
Length of output: 0
[/web_search]
🌐 Web query:
💡 Result:
Short answer: The RDW is 4 bytes and the length field (the first two bytes of the RDW) contains the logical record length including those 4 RDW bytes. The second two RDW bytes are the segment/spanning descriptor (zero if not spanned). [1][2]
Sources:
Correct the RDW length calculation to include the 4-byte header.
The RDW length field must include the 4-byte RDW header itself per IBM mainframe standard. The RDW length field contains the logical record length including those 4 RDW bytes. Line 99 should calculate the RDW as:
Without this adjustment, the output will not conform to standard mainframe VRL format and will be incompatible with standard RDW readers.
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have observed both cases:
Historically, Cobrix uses the second option, and loading files which has RDWs that include header size need an adjustment by -4 (
option("rdw_adjustment", "-1")). Going to keep this implementation because it matches Cobrix defaults. But if later different types of RDWs are required, we can always add an option of RDW adjustment for the writer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yruslan, thank you for the clarification! That makes perfect sense. Maintaining consistency with Cobrix's historical RDW format (payload-only) ensures backward compatibility and aligns with the existing
rdw_adjustmentoption behavior. The flexibility to add writer-side RDW adjustment options later if needed sounds like a solid approach.I've noted this convention for future reference.
✏️ Learnings added