From 16d5ab12dac89280e3b49b163fae47720d0cf524 Mon Sep 17 00:00:00 2001 From: Ruslan Iushchenko Date: Tue, 28 Jul 2026 15:00:45 +0200 Subject: [PATCH] #862 Exclude custom option namespaces from redundant option validation. --- .../cobrix/cobol/parser/CopybookParser.scala | 2 +- .../parameters/CobolParametersParser.scala | 7 ++++++- .../cobrix/spark/cobol/CobolSchemaSpec.scala | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/CopybookParser.scala b/cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/CopybookParser.scala index fda49abf..4b29c88d 100644 --- a/cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/CopybookParser.scala +++ b/cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/parser/CopybookParser.scala @@ -305,7 +305,7 @@ object CopybookParser extends Logging { validateFieldParentMap(correctedFieldParentMap) val transformers = Seq( - // Calculate sized of fields and their positions from the beginning of a record + // Calculate sizes of fields and their positions from the beginning of a record BinaryPropertiesAdder(), // Adds virtual primitive fields for GROUPs that can be parsed as concatenation of their children. NonTerminalsAdder(nonTerms, enc, stringTrimmingPolicy, ebcdicCodePage, asciiCharset, isUtf16BigEndian, floatingPointFormat, strictSignOverpunch, improvedNullDetection), diff --git a/cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/reader/parameters/CobolParametersParser.scala b/cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/reader/parameters/CobolParametersParser.scala index c39e19cc..3e4919b6 100644 --- a/cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/reader/parameters/CobolParametersParser.scala +++ b/cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/reader/parameters/CobolParametersParser.scala @@ -946,7 +946,12 @@ object CobolParametersParser extends Logging { if (params.isKeyUsed(key)) { None } else { - Some(key) + val lowercaseKey = key.toLowerCase + if (lowercaseKey.startsWith("custom") || lowercaseKey.startsWith("hidam_") || lowercaseKey.startsWith("db2_") || lowercaseKey.startsWith("_")) { + None + } else { + Some(key) + } } }) diff --git a/spark-cobol/src/test/scala/za/co/absa/cobrix/spark/cobol/CobolSchemaSpec.scala b/spark-cobol/src/test/scala/za/co/absa/cobrix/spark/cobol/CobolSchemaSpec.scala index 59fc9757..c295ae49 100644 --- a/spark-cobol/src/test/scala/za/co/absa/cobrix/spark/cobol/CobolSchemaSpec.scala +++ b/spark-cobol/src/test/scala/za/co/absa/cobrix/spark/cobol/CobolSchemaSpec.scala @@ -722,6 +722,23 @@ class CobolSchemaSpec extends AnyWordSpec with SimpleComparisonBase { assert(ex.getMessage == "Redundant or unrecognized option(s) to 'spark-cobol': dummy_option.") } + + "do not fail fail on redundant options explicitly used from custom options namespaces" in { + val copybook: String = + """ 01 RECORD. + | 05 DATA PIC X(5). + |""".stripMargin + + CobolSchema.fromSparkOptions(Seq(copybook), + Map( + "pedantic" -> "true", + "custom_test" -> "dummy_value", + "hidam_test" -> "dummy_value", + "db2_test" -> "dummy_value", + "_some_test" -> "dummy_value" + ) + ) + } } "getMaximumSegmentIdLength" should {