Skip to content

Commit

Permalink
#239 Fix row extraction for nested variable occurs case.
Browse files Browse the repository at this point in the history
  • Loading branch information
yruslan committed Feb 18, 2020
1 parent b2095a4 commit 5fb28b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ object RowExtractors {
var i = from
var j = 0
while (i < actualSize) {
val value = getGroupValues(offset, grp)
offset += grp.binaryProperties.dataSize
val (size, value) = getGroupValues(offset, grp)
offset += size
groupValues(j) = value
i += 1
j += 1
Expand All @@ -107,11 +107,11 @@ object RowExtractors {
}
}

def extractValue(field: Statement, useOffset: Int): Any = {
def extractValue(field: Statement, useOffset: Int): (Int, Any) = {
field match {
case grp: Group =>
if (grp.isSegmentRedefine && grp.name.compareToIgnoreCase(activeSegmentRedefine) != 0) {
null
(grp.binaryProperties.actualSize, null)
} else {
getGroupValues(useOffset, grp)
}
Expand All @@ -125,11 +125,11 @@ object RowExtractors {
}
dependFields += st.name -> intVal
}
value
(st.binaryProperties.actualSize, value)
}
}

def getGroupValues(offset: Int, group: Group): Row = {
def getGroupValues(offset: Int, group: Group): (Int, Row) = {
var bitOffset = offset

val fields = new Array[Any](group.nonFillerSize)
Expand All @@ -145,9 +145,13 @@ object RowExtractors {
}
value
} else {
val value = extractValue(field, bitOffset)
val (size, value) = extractValue(field, bitOffset)
if (!field.isRedefined) {
bitOffset += field.binaryProperties.actualSize
if (field.redefines.isDefined) {
bitOffset += field.binaryProperties.actualSize
} else {
bitOffset += size
}
}
value
}
Expand All @@ -157,14 +161,14 @@ object RowExtractors {
}
i += 1
}
new GenericRow(fields)
(bitOffset - offset, new GenericRow(fields))
}

var nextOffset = offsetBytes

val records = for (record <- ast.children) yield {
val values = getGroupValues(nextOffset, record.asInstanceOf[Group])
nextOffset += record.binaryProperties.actualSize
val (size, values) = getGroupValues(nextOffset, record.asInstanceOf[Group])
nextOffset += size
values
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import za.co.absa.cobrix.cobol.parser.policies.{CommentPolicy, StringTrimmingPol
import za.co.absa.cobrix.cobol.parser.recordextractors.VarOccursRecordExtractor
import za.co.absa.cobrix.cobol.parser.stream.{FSStream, SimpleStream}
import za.co.absa.cobrix.spark.cobol.source.base.SparkTestBase
import za.co.absa.cobrix.spark.cobol.utils.FileUtils
import za.co.absa.cobrix.spark.cobol.utils.{FileUtils, RowExtractors}

import scala.collection.immutable.HashMap
import scala.collection.mutable.ListBuffer
Expand Down

0 comments on commit 5fb28b8

Please sign in to comment.