Uh oh!
There was an error while loading. Please reload this page.
[SPARK-35912][SQL] Fix cast struct contains null value to string/struct - #33146
[SPARK-35912][SQL] Fix cast struct contains null value to string/struct#33146cfmcgrady wants to merge 3 commits into
Conversation
AmplabJenkins
commented
Jun 30, 2021
Can one of the admins verify this patch? |
There was a problem hiding this comment.
When the actual value is null, for primitive type field, row.isNullAt(i) return ture, but row.getXXX return a default value.
For exmaple:
valr=new org.apache.spark.sql.catalyst.expressions.GenericInternalRow(Array(1, null))
println(r.getInt(0)) // 1
println(r.getInt(1)) // 0
println(r.isNullAt(1)) // trueso we cann't only check row.isNullAt(i) here, we need to do the same logical like BoundReference.doGenCode(), add nullable check.
HyukjinKwon
commented
Jun 30, 2021
how is the cache issue related to the cast? |
cfmcgrady
commented
Jun 30, 2021
HI, @HyukjinKwon |
cfmcgrady
commented
Jun 30, 2021
There was a problem hiding this comment.
if fields(0).nullable is false, how can row.isNullAt(0) be true?
There was a problem hiding this comment.
If user create dataframe from spark.internalCreateDataFrame(), the row.isNullAt() may be true even though the schema nullable is false.
For instance:
valschema=StructType(Seq(
StructField("x",
StructType(Seq(
StructField("y", IntegerType, true),
StructField("z", IntegerType, false)
)))))
valrdd= spark.sparkContext.parallelize(Seq(InternalRow(InternalRow(1, null))))
valdf= spark.internalCreateDataFrame(rdd, schema)
df.show
// current master branch output// +---------+// | x|// +---------+// |{1, null}|// +---------+Although the spark.internalCreateDataFrame() is sql package private API, but spark.read.json() and spark.read.csv() call it without null value handled.(the example show in pr description)
There was a problem hiding this comment.
Then we need to fix the nullability. There are so many places in the Spark codebase that relies on nullability to do optimizations. It's not possible to change all of them to not trust the nullability anymore.
Can we fix spark.read.json() to set the nullability correctly?
HyukjinKwon
commented
Jun 30, 2021
Hey mind explaining why cast path issue is related to being cached? |
There was a problem hiding this comment.
nit:
Seq(true, false).foreach { nullable =>
There was a problem hiding this comment.
nit: Seq(true, false).foreach { nullable =>
cfmcgrady
commented
Jul 1, 2021
Actually, the cached result is what we want. The issue is that |
Shouldn't it fail instead of setting it as |
cfmcgrady
commented
Jul 1, 2021
Thanks for your suggestion, I'll try. |
cfmcgrady
commented
Jul 5, 2021
Create a new PR BTW, Shall we merge this PR? The cast issue may occur when the user create dataframe from API |
cloud-fan
commented
Jul 5, 2021
|
What changes were proposed in this pull request?
This PR fixes an issue that cast the struct which contains null value to other type has a difference result when we enable/disable codegen.
Here is an example:
Actually, the result should be depending on the field nullable setting. this bug also happens when we cast struct to struct.
Does this PR introduce any user-facing change?
No, only bug fix.
How was this patch tested?
New test.