Skip to content

Conversation

@LuciferYang
Copy link
Contributor

@LuciferYang LuciferYang commented Oct 26, 2022

What changes were proposed in this pull request?

This pr refactor AnalysisTest#assertAnalysisErrorClass method to use e.messageParameters != expectedMessageParameters instead of !e.messageParameters.sameElements(expectedMessageParameters) to avoid wrong check result when expectedMessageParameters.size <= 4

Why are the changes needed?

Avoid wrong check result of AnalysisTest#assertAnalysisErrorClass when expectedMessageParameters.size <= 4.

Does this PR introduce any user-facing change?

No

How was this patch tested?

  • Pass GitHub Actions
  • Manual test:
Welcome to Scala 2.12.17 (OpenJDK 64-Bit Server VM, Java 1.8.0_352).
Type in expressions for evaluation. Or try :help.

scala> :paste
// Entering paste mode (ctrl-D to finish)

val messageParameters = Map(
      "exprName" -> "`window_duration`",
      "valueRange" -> s"(0, 9223372036854775807]",
      "currentValue" -> "-1000000L",
      "sqlExpr" -> "\"window(2016-01-01 01:01:01, -1000000, 1000000, 0)\""
    )
val expectedMessageParameters =  Map(
      "sqlExpr" -> "\"window(2016-01-01 01:01:01, -1000000, 1000000, 0)\"",
      "exprName" -> "`window_duration`",
      "valueRange" -> s"(0, 9223372036854775807]",
      "currentValue" -> "-1000000L"
    )

val tret = !messageParameters.sameElements(expectedMessageParameters)
val fret = messageParameters != expectedMessageParameters


// Exiting paste mode, now interpreting.

messageParameters: scala.collection.immutable.Map[String,String] = Map(exprName -> `window_duration`, valueRange -> (0, 9223372036854775807], currentValue -> -1000000L, sqlExpr -> "window(2016-01-01 01:01:01, -1000000, 1000000, 0)")
expectedMessageParameters: scala.collection.immutable.Map[String,String] = Map(sqlExpr -> "window(2016-01-01 01:01:01, -1000000, 1000000, 0)", exprName -> `window_duration`, valueRange -> (0, 9223372036854775807], currentValue -> -1000000L)
tret: Boolean = true
fret: Boolean = false

line: Int = -1,
pos: Int = -1): Unit = {

def sameMapContents(left: Map[String, String], right: Map[String, String]): Boolean =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc @MaxGekk fix the problem I mentioned in #38394 (comment)

@LuciferYang LuciferYang changed the title [SPARK-40919][SQL][TESTS] Refactor AnalysisTest#assertAnalysisErrorClass to avoid bad case when expectedMessageParameters.size <= 4 [SPARK-40919][SQL][TESTS] Refactor AnalysisTest#assertAnalysisErrorClass to avoid wrong check result when expectedMessageParameters.size <= 4 Oct 26, 2022
@MaxGekk
Copy link
Member

MaxGekk commented Oct 26, 2022

@LuciferYang How about to use ==?

scala> :paste
// Entering paste mode (ctrl-D to finish)

val messageParameters = Map(
      "exprName" -> "`window_duration`",
      "valueRange" -> s"(0, 9223372036854775807]",
      "currentValue" -> "-1000000L",
      "sqlExpr" -> "\"window(2016-01-01 01:01:01, -1000000, 1000000, 0)\""
    )
val expectedMessageParameters =  Map(
      "sqlExpr" -> "\"window(2016-01-01 01:01:01, -1000000, 1000000, 0)\"",
      "exprName" -> "`window_duration`",
      "valueRange" -> s"(0, 9223372036854775807]",
      "currentValue" -> "-1000000L"
    )

// Exiting paste mode, now interpreting.

messageParameters: scala.collection.immutable.Map[String,String] = Map(exprName -> `window_duration`, valueRange -> (0, 9223372036854775807], currentValue -> -1000000L, sqlExpr -> "window(2016-01-01 01:01:01, -1000000, 1000000, 0)")
expectedMessageParameters: scala.collection.immutable.Map[String,String] = Map(sqlExpr -> "window(2016-01-01 01:01:01, -1000000, 1000000, 0)", exprName -> `window_duration`, valueRange -> (0, 9223372036854775807], currentValue -> -1000000L)

scala> messageParameters == expectedMessageParameters
res0: Boolean = true

@LuciferYang
Copy link
Contributor Author

I think == is fine


if (e.getErrorClass != expectedErrorClass ||
!e.messageParameters.sameElements(expectedMessageParameters) ||
!(e.messageParameters == expectedMessageParameters) ||
Copy link
Member

Choose a reason for hiding this comment

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

Let's simplify this and use != instead of combination of ! and ==.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

@MaxGekk MaxGekk left a comment

Choose a reason for hiding this comment

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

Waiting for CI.

@dongjoon-hyun dongjoon-hyun changed the title [SPARK-40919][SQL][TESTS] Refactor AnalysisTest#assertAnalysisErrorClass to avoid wrong check result when expectedMessageParameters.size <= 4 [SPARK-40919][SQL][TESTS] Fix AnalysisTest#assertAnalysisErrorClass to avoid wrong check result when expectedMessageParameters.size <= 4 Oct 26, 2022

if (e.getErrorClass != expectedErrorClass ||
!e.messageParameters.sameElements(expectedMessageParameters) ||
e.messageParameters != expectedMessageParameters ||
Copy link
Member

Choose a reason for hiding this comment

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

nit, Could you fix the indentation by adding two more space here while we are touching this line?

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.

+1, LGTM (except a minor indentation comment)

!e.messageParameters.sameElements(expectedMessageParameters) ||
(line >= 0 && e.line.getOrElse(-1) != line) ||
(pos >= 0) && e.startPosition.getOrElse(-1) != pos) {
e.messageParameters != expectedMessageParameters ||
Copy link
Contributor Author

@LuciferYang LuciferYang Oct 27, 2022

Choose a reason for hiding this comment

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

Is the indentation correct now?

@MaxGekk
Copy link
Member

MaxGekk commented Oct 27, 2022

+1, LGTM. All GAs passed. Merging to master.
Thank you, @LuciferYang and @dongjoon-hyun @HyukjinKwon for review.

@MaxGekk MaxGekk closed this in a40f8c1 Oct 27, 2022
@LuciferYang
Copy link
Contributor Author

Thanks @MaxGekk @dongjoon-hyun @HyukjinKwon

SandishKumarHN pushed a commit to SandishKumarHN/spark that referenced this pull request Dec 12, 2022
… to avoid wrong check result when `expectedMessageParameters.size <= 4`

### What changes were proposed in this pull request?
This pr refactor `AnalysisTest#assertAnalysisErrorClass` method to use `e.messageParameters != expectedMessageParameters` instead of `!e.messageParameters.sameElements(expectedMessageParameters)` to avoid wrong check result when `expectedMessageParameters.size <= 4`

### Why are the changes needed?
Avoid wrong check result of  `AnalysisTest#assertAnalysisErrorClass`  when `expectedMessageParameters.size <= 4`.

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?

- Pass GitHub Actions
- Manual test:

```scala
Welcome to Scala 2.12.17 (OpenJDK 64-Bit Server VM, Java 1.8.0_352).
Type in expressions for evaluation. Or try :help.

scala> :paste
// Entering paste mode (ctrl-D to finish)

val messageParameters = Map(
      "exprName" -> "`window_duration`",
      "valueRange" -> s"(0, 9223372036854775807]",
      "currentValue" -> "-1000000L",
      "sqlExpr" -> "\"window(2016-01-01 01:01:01, -1000000, 1000000, 0)\""
    )
val expectedMessageParameters =  Map(
      "sqlExpr" -> "\"window(2016-01-01 01:01:01, -1000000, 1000000, 0)\"",
      "exprName" -> "`window_duration`",
      "valueRange" -> s"(0, 9223372036854775807]",
      "currentValue" -> "-1000000L"
    )

val tret = !messageParameters.sameElements(expectedMessageParameters)
val fret = messageParameters != expectedMessageParameters

// Exiting paste mode, now interpreting.

messageParameters: scala.collection.immutable.Map[String,String] = Map(exprName -> `window_duration`, valueRange -> (0, 9223372036854775807], currentValue -> -1000000L, sqlExpr -> "window(2016-01-01 01:01:01, -1000000, 1000000, 0)")
expectedMessageParameters: scala.collection.immutable.Map[String,String] = Map(sqlExpr -> "window(2016-01-01 01:01:01, -1000000, 1000000, 0)", exprName -> `window_duration`, valueRange -> (0, 9223372036854775807], currentValue -> -1000000L)
tret: Boolean = true
fret: Boolean = false
```

Closes apache#38396 from LuciferYang/SPARK-40919.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants