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-43063][SQL][FOLLOWUP] Add a space between -> and value when first value is null #42434

Closed

Conversation

andygrove
Copy link
Member

@andygrove andygrove commented Aug 10, 2023

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,[B@5c3fd9f3,[B@70f84210]) as string), 
  actual: {1 ->null, 2 -> a, 3 -> c}, 
expected: {1 -> null, 2 -> a, 3 -> c} (ExpressionEvalHelper.scala:270)

@github-actions github-actions bot added the SQL label Aug 10, 2023
@@ -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)}
Copy link
Member Author

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.

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

Thank you, @andygrove .

@andygrove andygrove changed the title [WIP][SPARK-43063][SQL][FOLLOWUP] Add a space between -> and value when first value is null [SPARK-43063][SQL][FOLLOWUP] Add a space between -> and value when first value is null Aug 10, 2023
Copy link
Contributor

@tgravescs tgravescs left a 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)
Copy link
Contributor

@cloud-fan cloud-fan Aug 11, 2023

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.

Copy link
Member Author

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.

@tgravescs
Copy link
Contributor

+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)),
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@cloud-fan
Copy link
Contributor

thanks, merging to master/3.5!

@cloud-fan cloud-fan closed this in 7e52169 Aug 15, 2023
cloud-fan pushed a commit that referenced this pull request Aug 15, 2023
…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>
@yaooqinn
Copy link
Member

Late LGTM

valentinp17 pushed a commit to valentinp17/spark that referenced this pull request Aug 24, 2023
…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>
ragnarok56 pushed a commit to ragnarok56/spark that referenced this pull request Mar 2, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants