-
Notifications
You must be signed in to change notification settings - Fork 29k
SPARK-14139 Dataset loses nullability in operations with RowEncoder #11980
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
Closed
koertkuipers
wants to merge
9
commits into
apache:master
from
tresata-opensource:feat-rowencoder-nullable
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
847d7c7
change RowEncoder to respect nullable for struct fields when generati…
koertkuipers b500c8b
merge from master
koertkuipers 3e32b6a
make scalastyle happy
koertkuipers 15adc9c
Merge branch 'master' into feat-rowencoder-nullable
koertkuipers 2600a2e
first try at using GetExternalRowField instead of Invoke. fails unit …
koertkuipers 50c0005
Merge branch 'master' into feat-rowencoder-nullable
koertkuipers 05e5f19
merge from master
koertkuipers 4b140e5
fix for extractsFor renamed to serializerFor
koertkuipers e9a9a30
fix pattern match in GetExternalRowField where the data types are ext…
koertkuipers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -680,3 +680,53 @@ case class AssertNotNull(child: Expression, walkedTypePath: Seq[String]) | |
| """ | ||
| } | ||
| } | ||
|
|
||
| case class GetExternalRowField( | ||
|
Contributor
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. You can take a look at
Contributor
Author
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. ok will do |
||
| targetObject: Expression, | ||
| index: Int, | ||
| dataType: DataType, | ||
| nullable: Boolean) extends Expression with NonSQLExpression { | ||
|
|
||
| override def children: Seq[Expression] = Seq(targetObject) | ||
|
|
||
| override def eval(input: InternalRow): Any = | ||
| throw new UnsupportedOperationException("Only code-generated evaluation is supported") | ||
|
|
||
| override def genCode(ctx: CodegenContext, ev: ExprCode): String = { | ||
| val javaType = ctx.javaType(dataType) | ||
| val obj = targetObject.gen(ctx) | ||
|
|
||
| val get = dataType match { | ||
| case IntegerType => s"""${obj.value}.getInt($index)""" | ||
| case LongType => s"""${obj.value}.getLong($index)""" | ||
| case FloatType => s"""${obj.value}.getFloat($index)""" | ||
| case ShortType => s"""${obj.value}.getShort($index)""" | ||
| case ByteType => s"""${obj.value}.getByte($index)""" | ||
| case DoubleType => s"""${obj.value}.getDouble($index)""" | ||
| case BooleanType => s"""${obj.value}.getBoolean($index)""" | ||
| case ObjectType(x) if x == classOf[Row] => s"""${obj.value}.getStruct($index)""" | ||
| case _ => s"""((${javaType}) ${obj.value}.get($index))""" | ||
| } | ||
|
|
||
| if (nullable) { | ||
| s""" | ||
| ${obj.code} | ||
| final ${javaType} ${ev.value}; | ||
| final boolean ${ev.isNull}; | ||
| if (${obj.value}.isNullAt(${index})) { | ||
| ${ev.value} = ${ctx.defaultValue(dataType)}; | ||
| ${ev.isNull} = true; | ||
| } else { | ||
| ${ev.value} = ${get}; | ||
| ${ev.isNull} = false; | ||
| } | ||
| """ | ||
| } else { | ||
| s""" | ||
| ${obj.code} | ||
| final ${javaType} ${ev.value} = ${get}; | ||
| final boolean ${ev.isNull} = false; | ||
| """ | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think we can do the null check inside
GetExternalRowFieldThere 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 had that before (basically without the If, since GetExternalRowField already does null checks inside), but the issue is that extractorsFor code path then also runs for nulls , and that causes some weird runtime errors. i will try again.
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.
if we do the null check inside GetExternalRowField then the code for serializerFor also needs to be pushed into it (to be inside the null check), and i can not figure out how to do that...