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-43063][SQL][FOLLOWUP] Add a space between -> and value when first value is null #42434
Conversation
@@ -352,7 +352,7 @@ trait ToStringBase { self: UnaryExpression with TimeZoneAwareExpression => | |||
| $buffer.append($keyToStringFunc($getMapFirstKey)); | |||
| $buffer.append(" ->"); | |||
| if ($map.valueArray().isNullAt(0)) { | |||
| ${appendNull(buffer, isFirstElement = true)} | |||
| ${appendNull(buffer, isFirstElement = false)} |
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.
There should always be a space after ->
and before the value. It does not matter if this is the first key-value pair or not.
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.
Thank you, @andygrove .
...catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvalHelper.scala
Outdated
Show resolved
Hide resolved
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.
+1, LGTM
checkEvaluation(expr, catalystValue, inputRow) | ||
} else { | ||
checkEvaluationWithoutCodegen(expr, catalystValue, inputRow) | ||
} | ||
checkEvaluationWithMutableProjection(expr, catalystValue, inputRow) | ||
if (GenerateUnsafeProjection.canSupport(expr.dataType)) { | ||
checkEvaluationWithUnsafeProjection(expr, catalystValue, inputRow) |
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.
The test already checks codegen. We don't need to touch this file, just update the test to put null in the first element.
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.
Thanks. I reverted that change and confirmed that the test still fails if I remove the fix.
+1. @cloud-fan, this ok with you now? |
@@ -826,9 +826,9 @@ abstract class CastSuiteBase extends SparkFunSuite with ExpressionEvalHelper { | |||
val ret1 = cast(Literal.create(Map(1 -> "a", 2 -> "b", 3 -> "c")), StringType) | |||
checkEvaluation(ret1, s"${lb}1 -> a, 2 -> b, 3 -> c$rb") | |||
val ret2 = cast( | |||
Literal.create(Map("1" -> "a".getBytes, "2" -> null, "3" -> "c".getBytes)), | |||
Literal.create(Map("1" -> null, "2" -> "a".getBytes, "3" -> "c".getBytes)), |
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.
can we also have a null value in the middle? so that we can have test coverage for null in different positions.
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.
Done
thanks, merging to master/3.5! |
…rst value is null As noted by cloud-fan #41432 (comment), #41432 fixed a formatting issue when casting map to string but did not fix it in the codegen case. This PR fixes the issue and updates a unit test to test the codegen path. Without the fix, the test fails with: ``` - SPARK-22973 Cast map to string *** FAILED *** Incorrect evaluation (fallback mode = CODEGEN_ONLY): cast(map(keys: [1,2,3], values: [null,[B5c3fd9f3,[B70f84210]) as string), actual: {1 ->null, 2 -> a, 3 -> c}, expected: {1 -> null, 2 -> a, 3 -> c} (ExpressionEvalHelper.scala:270) ``` Closes #42434 from andygrove/space-before-null-cast-codegen. Authored-by: Andy Grove <andygrove73@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com> (cherry picked from commit 7e52169) Signed-off-by: Wenchen Fan <wenchen@databricks.com>
Late LGTM |
…rst value is null As noted by cloud-fan apache#41432 (comment), apache#41432 fixed a formatting issue when casting map to string but did not fix it in the codegen case. This PR fixes the issue and updates a unit test to test the codegen path. Without the fix, the test fails with: ``` - SPARK-22973 Cast map to string *** FAILED *** Incorrect evaluation (fallback mode = CODEGEN_ONLY): cast(map(keys: [1,2,3], values: [null,[B5c3fd9f3,[B70f84210]) as string), actual: {1 ->null, 2 -> a, 3 -> c}, expected: {1 -> null, 2 -> a, 3 -> c} (ExpressionEvalHelper.scala:270) ``` Closes apache#42434 from andygrove/space-before-null-cast-codegen. Authored-by: Andy Grove <andygrove73@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
…rst value is null As noted by cloud-fan apache#41432 (comment), apache#41432 fixed a formatting issue when casting map to string but did not fix it in the codegen case. This PR fixes the issue and updates a unit test to test the codegen path. Without the fix, the test fails with: ``` - SPARK-22973 Cast map to string *** FAILED *** Incorrect evaluation (fallback mode = CODEGEN_ONLY): cast(map(keys: [1,2,3], values: [null,[B5c3fd9f3,[B70f84210]) as string), actual: {1 ->null, 2 -> a, 3 -> c}, expected: {1 -> null, 2 -> a, 3 -> c} (ExpressionEvalHelper.scala:270) ``` Closes apache#42434 from andygrove/space-before-null-cast-codegen. Authored-by: Andy Grove <andygrove73@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
As noted by @cloud-fan #41432 (comment), #41432 fixed a formatting issue when casting map to string but did not fix it in the codegen case.
This PR fixes the issue and updates a unit test to test the codegen path. Without the fix, the test fails with: