Skip to content

Commit

Permalink
Fix too eager validator that denies 'with_input_file_name_col' for so…
Browse files Browse the repository at this point in the history
…me valid combinations.
  • Loading branch information
yruslan committed Apr 21, 2023
1 parent c1a4d76 commit d7fefed
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ object CobolParametersParser extends Logging {

private def getDebuggingFieldsPolicy(recordFormat: RecordFormat, params: Parameters): DebugFieldsPolicy = {
val debugFieldsPolicyName = params.getOrElse(PARAM_DEBUG, "false")
val isText = params.getOrElse(PARAM_IS_TEXT, "false").toBoolean
val debugFieldsPolicy = DebugFieldsPolicy.withNameOpt(debugFieldsPolicyName)

val policy = debugFieldsPolicy match {
Expand All @@ -205,7 +206,7 @@ object CobolParametersParser extends Logging {
throw new IllegalArgumentException(s"Invalid value '$debugFieldsPolicyName' for '$PARAM_DEBUG' option. " +
"Allowed one of: 'true' = 'hex', 'raw', 'binary', 'string' (ASCII only), 'false' = 'none'. ")
}
if (policy == DebugFieldsPolicy.StringValue && recordFormat != RecordFormat.AsciiText && recordFormat != RecordFormat.CobrixAsciiText) {
if (policy == DebugFieldsPolicy.StringValue && recordFormat != RecordFormat.AsciiText && recordFormat != RecordFormat.CobrixAsciiText && !isText) {
throw new IllegalArgumentException(s"Invalid value '$debugFieldsPolicyName' for '$PARAM_DEBUG' option. " +
"Allowed only for record_format = 'D' or 'D2'.")
}
Expand Down Expand Up @@ -836,7 +837,7 @@ object CobolParametersParser extends Logging {
"since hierarchical records are composites of more than one raw record.")
}
}
if (!isRecordSequence && params.contains(PARAM_INPUT_FILE_COLUMN)) {
if (!isRecordSequence && recordFormat != AsciiText && recordFormat != CobrixAsciiText && params.contains(PARAM_INPUT_FILE_COLUMN)) {
val recordSequenceCondition = s"one of this holds: '$PARAM_RECORD_FORMAT' = V or '$PARAM_RECORD_FORMAT' = VB or '$PARAM_IS_RECORD_SEQUENCE' = true" +
s" or one of these options is set: '$PARAM_RECORD_LENGTH_FIELD', '$PARAM_FILE_START_OFFSET', '$PARAM_FILE_END_OFFSET' or " +
"a custom record extractor is specified. If you see the error, please use Spark standard function 'input_file_name()' instead."
Expand Down

0 comments on commit d7fefed

Please sign in to comment.