-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-34473][SQL] Avoid NPE in DataFrameReader.schema(StructType) #31593
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,8 +73,10 @@ class DataFrameReader private[sql](sparkSession: SparkSession) extends Logging { | |
| * @since 1.4.0 | ||
| */ | ||
| def schema(schema: StructType): DataFrameReader = { | ||
| val replaced = CharVarcharUtils.failIfHasCharVarchar(schema).asInstanceOf[StructType] | ||
| this.userSpecifiedSchema = Option(replaced) | ||
| if (schema != null) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, probably we should just disallow |
||
| val replaced = CharVarcharUtils.failIfHasCharVarchar(schema).asInstanceOf[StructType] | ||
| this.userSpecifiedSchema = Option(replaced) | ||
| } | ||
| this | ||
| } | ||
|
|
||
|
|
@@ -90,10 +92,7 @@ class DataFrameReader private[sql](sparkSession: SparkSession) extends Logging { | |
| * @since 2.3.0 | ||
| */ | ||
| def schema(schemaString: String): DataFrameReader = { | ||
| val rawSchema = StructType.fromDDL(schemaString) | ||
| val schema = CharVarcharUtils.failIfHasCharVarchar(rawSchema).asInstanceOf[StructType] | ||
| this.userSpecifiedSchema = Option(schema) | ||
| this | ||
| schema(StructType.fromDDL(schemaString)) | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,8 +64,10 @@ final class DataStreamReader private[sql](sparkSession: SparkSession) extends Lo | |
| * @since 2.0.0 | ||
| */ | ||
| def schema(schema: StructType): DataStreamReader = { | ||
| val replaced = CharVarcharUtils.failIfHasCharVarchar(schema).asInstanceOf[StructType] | ||
| this.userSpecifiedSchema = Option(replaced) | ||
| if (schema != null) { | ||
| val replaced = CharVarcharUtils.failIfHasCharVarchar(schema).asInstanceOf[StructType] | ||
| this.userSpecifiedSchema = Option(replaced) | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we change line 81~86 together?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
| this | ||
| } | ||
|
|
||
|
|
@@ -77,10 +79,7 @@ final class DataStreamReader private[sql](sparkSession: SparkSession) extends Lo | |
| * @since 2.3.0 | ||
| */ | ||
| def schema(schemaString: String): DataStreamReader = { | ||
| val rawSchema = StructType.fromDDL(schemaString) | ||
| val schema = CharVarcharUtils.failIfHasCharVarchar(rawSchema).asInstanceOf[StructType] | ||
| this.userSpecifiedSchema = Option(schema) | ||
| this | ||
| schema(StructType.fromDDL(schemaString)) | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine. It'd be OK IMHO to require it to be non-null too.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also prefer not allowing null, but no strong voice. If we'd like to allow null, probably ideal to clearly define the behavior of null rather than leaving it as "undefined behavior".