Skip to content

Commit

Permalink
Make sure spark option keys are case-insensitive when passed to the o…
Browse files Browse the repository at this point in the history
…ption parser.
  • Loading branch information
yruslan committed Apr 26, 2024
1 parent 874b772 commit 4b141ef
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ object CobolSchema {
}

def fromSparkOptions(copyBookContents: Seq[String], sparkReaderOptions: Map[String, String]): CobolSchema = {
val cobolParameters = CobolParametersParser.parse(new Parameters(sparkReaderOptions))
val lowercaseOptions = sparkReaderOptions.map { case (k, v) => (k.toLowerCase, v) }
val cobolParameters = CobolParametersParser.parse(new Parameters(lowercaseOptions))
val readerParameters = getReaderProperties(cobolParameters, None)

CobolSchema.fromBaseReader(CobolReaderSchema.fromReaderParameters(copyBookContents, readerParameters))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,24 @@ class CobolSchemaSpec extends AnyWordSpec with SimpleComparisonBase {
assert(sparkSchema.fields(8).dataType.isInstanceOf[StructType])
}

"work in the case insensitive way" in {
val copybook: String =
""" 01 RECORD.
| 05 STR1 PIC X(10).
|""".stripMargin

val cobolSchema = CobolSchema.fromSparkOptions(Seq(copybook),
Map(
"pedantic" -> "true",
"generate_RECORD_id" -> "true"
)
)

val sparkSchema = cobolSchema.getSparkSchema

assert(sparkSchema.fields.length == 4)
}

"fail on redundant options when pedantic mode is turned on" in {
val copybook: String =
""" 01 RECORD.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Test22RecordLengthGenId extends AnyWordSpec with SparkTestBase with Binary
.format("cobol")
.option("copybook_contents", copybook)
.option("record_format", "F")
.option("record_length", "4")
.option("record_LENGTH", "4")
.option("pedantic", "true")
.load(tmpFileName)

Expand Down

0 comments on commit 4b141ef

Please sign in to comment.