Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-51296][SQL] Support collecting corrupt data in singleVariantColumn mode. #50517

Conversation

chenhao-db
Copy link
Contributor

What changes were proposed in this pull request?

Currently, if the singleVariantColumn is specified, the schema will be a single variant column. It is then impossible to collect corrupt data, which requires the schema to contain a column for corrupt data. This PR enables collecting corrupt data in singleVariantColumn mode by relaxing the requirement that singleVariantColumn must not exist together with the user-specified schema. The new requirement is that, if the user-specified schema exists, it must either be a variant field, or a variant field plus a corrupt column field. Corrupt data can be collected in the latter case.

Why are the changes needed?

It allows collecting corrupt data in singleVariantColumn mode.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Unit test.

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions github-actions bot added the SQL label Apr 4, 2025
@chenhao-db
Copy link
Contributor Author

@gene-db @sandip-db Please take a look. Thanks!

schema.length match {
case 1 =>
case 2 =>
val corruptRecordName = options.getOrElse(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
val corruptRecordName = options.getOrElse(
val corruptRecordColumnName = options.getOrElse(

@@ -4007,6 +4007,7 @@ abstract class JsonSuite
"true",
"""{"a": [], "b": null}""",
"""{"a": 1}""",
"bad json",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add from_json test

@@ -396,7 +396,7 @@ object CSVOptions extends DataSourceOptions {
val EMPTY_VALUE = newOption("emptyValue")
val LINE_SEP = newOption("lineSep")
val INPUT_BUFFER_SIZE = newOption("inputBufferSize")
val COLUMN_NAME_OF_CORRUPT_RECORD = newOption("columnNameOfCorruptRecord")
val COLUMN_NAME_OF_CORRUPT_RECORD = newOption(DataSourceOptions.COLUMN_NAME_OF_CORRUPT_RECORD)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add from_csv and csv file reader test with corrupt column and variant

Copy link
Contributor

@gene-db gene-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this feature! I left a few comments.

@@ -3330,7 +3330,7 @@
},
"INVALID_SINGLE_VARIANT_COLUMN" : {
"message" : [
"The `singleVariantColumn` option cannot be used if there is also a user specified schema."
"User specified schema <schema> is invalid when the `singleVariantColumn` option is enabled."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we allowed to change existing error codes/messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is okay but I'm not sure.

options: CaseInsensitiveMap[String],
userSpecifiedSchema: Option[StructType]): Unit = {
(options.get(SINGLE_VARIANT_COLUMN), userSpecifiedSchema) match {
case (Some(col), Some(schema)) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: col -> variantColName

@chenhao-db chenhao-db requested review from gene-db and sandip-db April 7, 2025 20:48
@@ -3330,7 +3330,7 @@
},
"INVALID_SINGLE_VARIANT_COLUMN" : {
"message" : [
"The `singleVariantColumn` option cannot be used if there is also a user specified schema."
"User specified schema <schema> is invalid when the `singleVariantColumn` option is enabled."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indicate what is allowed and how can user fix it.

Copy link
Contributor

@gene-db gene-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for supporting this!

LGTM

@chenhao-db
Copy link
Contributor Author

@HyukjinKwon could you help merge it? Thanks!

@HyukjinKwon
Copy link
Member

Merged to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants