Skip to content

Commit

Permalink
#338 Add creation of raw record extractors.
Browse files Browse the repository at this point in the history
  • Loading branch information
yruslan committed Dec 3, 2020
1 parent c6624dc commit e887772
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import za.co.absa.cobrix.cobol.parser.encoding.codepage.CodePage
import za.co.absa.cobrix.cobol.parser.encoding.{ASCII, EBCDIC}
import za.co.absa.cobrix.cobol.parser.headerparsers.{RecordHeaderParser, RecordHeaderParserFactory}
import za.co.absa.cobrix.cobol.parser.{Copybook, CopybookParser}
import za.co.absa.cobrix.cobol.reader.extractors.raw.{RawRecordExtractor, RawRecordExtractorParameters, TextRecordExtractor, VarOccursRecordExtractor}
import za.co.absa.cobrix.cobol.reader.extractors.raw._
import za.co.absa.cobrix.cobol.reader.extractors.record.RecordHandler
import za.co.absa.cobrix.cobol.reader.index.IndexGenerator
import za.co.absa.cobrix.cobol.reader.index.entry.SparseIndexEntry
Expand Down Expand Up @@ -59,20 +59,22 @@ class VarLenNestedReader[T: ClassTag](copybookContents: Seq[String],

protected def recordExtractor(startingRecordNumber: Long,
binaryData: SimpleStream,
copybook: Copybook,
additionalInfo: String
copybook: Copybook
): Option[RawRecordExtractor] = {
if (readerProperties.isText) {
Some(new TextRecordExtractor(RawRecordExtractorParameters(startingRecordNumber, binaryData, copybook, additionalInfo)))
} else {
if (readerProperties.variableSizeOccurs &&
val reParams = RawRecordExtractorParameters(startingRecordNumber, binaryData, copybook, readerProperties.reAdditionalInfo)

readerProperties.recordExtractor match {
case Some(recordExtractorClass) =>
Some(RawRecordExtractorFactory.createRecordHeaderParser(recordExtractorClass, reParams))
case None if readerProperties.isText =>
Some(new TextRecordExtractor(reParams))
case None if readerProperties.variableSizeOccurs &&
readerProperties.recordHeaderParser.isEmpty &&
!readerProperties.isRecordSequence &&
readerProperties.lengthFieldName.isEmpty) {
Some(new VarOccursRecordExtractor(RawRecordExtractorParameters(startingRecordNumber, binaryData, copybook, additionalInfo)))
} else {
readerProperties.lengthFieldName.isEmpty =>
Some(new VarOccursRecordExtractor(reParams))
case None =>
None
}
}
}

Expand All @@ -93,7 +95,7 @@ class VarLenNestedReader[T: ClassTag](copybookContents: Seq[String],
binaryData,
readerProperties,
recordHeaderParser,
recordExtractor(startingRecordIndex, binaryData, cobolSchema.copybook, readerProperties.reAdditionalInfo),
recordExtractor(startingRecordIndex, binaryData, cobolSchema.copybook),
fileNumber,
startingRecordIndex,
startingFileOffset,
Expand All @@ -103,7 +105,7 @@ class VarLenNestedReader[T: ClassTag](copybookContents: Seq[String],
binaryData,
readerProperties,
recordHeaderParser,
recordExtractor(startingRecordIndex, binaryData, cobolSchema.copybook, readerProperties.reAdditionalInfo),
recordExtractor(startingRecordIndex, binaryData, cobolSchema.copybook),
fileNumber,
startingRecordIndex,
startingFileOffset,
Expand Down Expand Up @@ -158,7 +160,7 @@ class VarLenNestedReader[T: ClassTag](copybookContents: Seq[String],
binaryData,
isRdwBigEndian,
recordHeaderParser,
recordExtractor(0L, binaryData, copybook, readerProperties.reAdditionalInfo),
recordExtractor(0L, binaryData, copybook),
inputSplitSizeRecords,
inputSplitSizeMB,
Some(copybook),
Expand All @@ -169,7 +171,7 @@ class VarLenNestedReader[T: ClassTag](copybookContents: Seq[String],
binaryData,
isRdwBigEndian,
recordHeaderParser,
recordExtractor(0L, binaryData, copybook, readerProperties.reAdditionalInfo),
recordExtractor(0L, binaryData, copybook),
inputSplitSizeRecords,
inputSplitSizeMB,
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class VarLenNestedReader(copybookContents: Seq[String],
binaryData,
readerProperties,
recordHeaderParser,
recordExtractor(startingRecordIndex, binaryData, cobolSchema.copybook, readerProperties.reAdditionalInfo),
recordExtractor(startingRecordIndex, binaryData, cobolSchema.copybook),
fileNumber,
startingRecordIndex,
startingFileOffset,
Expand All @@ -73,7 +73,7 @@ final class VarLenNestedReader(copybookContents: Seq[String],
binaryData,
readerProperties,
recordHeaderParser,
recordExtractor(startingRecordIndex, binaryData, cobolSchema.copybook, readerProperties.reAdditionalInfo),
recordExtractor(startingRecordIndex, binaryData, cobolSchema.copybook),
fileNumber,
startingRecordIndex,
startingFileOffset,
Expand Down

0 comments on commit e887772

Please sign in to comment.