Skip to content

Conversation

@sadikovi
Copy link
Contributor

@sadikovi sadikovi commented May 23, 2022

What changes were proposed in this pull request?

This PR is a follow-up for #32513 and fixes an issue introduced by that patch.

CommandResultExec is supposed to return UnsafeRow records in all of the executeXYZ methods but executeCollect was left out which causes issues like this one:

Error in SQL statement: ClassCastException: org.apache.spark.sql.catalyst.expressions.GenericInternalRow 
cannot be cast to org.apache.spark.sql.catalyst.expressions.UnsafeRow

We need to return unsafeRows instead of rows in executeCollect similar to other methods in the class.

Why are the changes needed?

Fixes a bug in CommandResultExec.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

I added a unit test to check the return type of all commands.

@github-actions github-actions bot added the SQL label May 23, 2022
@sadikovi
Copy link
Contributor Author

cc @cloud-fan @dtenedor.
FYI @beliefer

We might need to backport this fix although I am not sure if other people use this method.

@beliefer
Copy link
Contributor

Under what circumstances did this happen? Or you can describe how to reproduce the problem.

@sadikovi
Copy link
Contributor Author

sadikovi commented May 23, 2022

Unfortunately, I cannot share the full repro.

CommandResultExec is supposed to return UnsafeRow, there is even a comment stating it:

// Input is already UnsafeRows.
override protected val createUnsafeProjection: Boolean = false

This PR fixes executeCollect that was not conforming to the spec.

@cloud-fan
Copy link
Contributor

cloud-fan commented May 23, 2022

thanks, merging to master/3.3/3.2!

@cloud-fan cloud-fan closed this in a0decfc May 23, 2022
cloud-fan pushed a commit that referenced this pull request May 23, 2022
…ultExec.executeCollect()

### What changes were proposed in this pull request?

This PR is a follow-up for #32513 and fixes an issue introduced by that patch.

CommandResultExec is supposed to return `UnsafeRow` records in all of the `executeXYZ` methods but `executeCollect` was left out which causes issues like this one:
```
Error in SQL statement: ClassCastException: org.apache.spark.sql.catalyst.expressions.GenericInternalRow
cannot be cast to org.apache.spark.sql.catalyst.expressions.UnsafeRow
```

We need to return `unsafeRows` instead of `rows` in `executeCollect` similar to other methods in the class.

### Why are the changes needed?

Fixes a bug in CommandResultExec.

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

No.

### How was this patch tested?

I added a unit test to check the return type of all commands.

Closes #36632 from sadikovi/fix-command-exec.

Authored-by: Ivan Sadikov <ivan.sadikov@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit a0decfc)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
cloud-fan pushed a commit that referenced this pull request May 23, 2022
…ultExec.executeCollect()

### What changes were proposed in this pull request?

This PR is a follow-up for #32513 and fixes an issue introduced by that patch.

CommandResultExec is supposed to return `UnsafeRow` records in all of the `executeXYZ` methods but `executeCollect` was left out which causes issues like this one:
```
Error in SQL statement: ClassCastException: org.apache.spark.sql.catalyst.expressions.GenericInternalRow
cannot be cast to org.apache.spark.sql.catalyst.expressions.UnsafeRow
```

We need to return `unsafeRows` instead of `rows` in `executeCollect` similar to other methods in the class.

### Why are the changes needed?

Fixes a bug in CommandResultExec.

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

No.

### How was this patch tested?

I added a unit test to check the return type of all commands.

Closes #36632 from sadikovi/fix-command-exec.

Authored-by: Ivan Sadikov <ivan.sadikov@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit a0decfc)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
@LuciferYang
Copy link
Contributor

Seems UT Hide credentials in show create table failed in master after this pr

2022-05-23T09:48:27.7668925Z [info] - Hide credentials in show create table *** FAILED *** (43 milliseconds)
2022-05-23T09:48:27.7696056Z [info]   "[0,10000000d5,5420455441455243,62617420454c4241,414e20200a282031,4e4952545320454d,45485420200a2c47,a29544e49204449,726f20474e495355,6568636170612e67,732e6b726170732e,a6362646a2e6c71,20534e4f4954504f,7462642720200a28,203d2027656c6261,45502e5453455427,200a2c27454c504f,6f77737361702720,2a27203d20276472,2a2a2a2a2a2a2a2a,6574636164657228,2720200a2c272964,27203d20276c7275,2a2a2a2a2a2a2a2a,746361646572282a,20200a2c27296465,3d20277265737527,7355747365742720,a29277265]" did not contain "TEST.PEOPLE" (JDBCSuite.scala:1146)
2022-05-23T09:48:27.7697358Z [info]   org.scalatest.exceptions.TestFailedException:
2022-05-23T09:48:27.7697954Z [info]   at org.scalatest.Assertions.newAssertionFailedException(Assertions.scala:472)
2022-05-23T09:48:27.7698605Z [info]   at org.scalatest.Assertions.newAssertionFailedException$(Assertions.scala:471)
2022-05-23T09:48:27.7699211Z [info]   at org.scalatest.Assertions$.newAssertionFailedException(Assertions.scala:1231)
2022-05-23T09:48:27.7699785Z [info]   at org.scalatest.Assertions$AssertionsHelper.macroAssert(Assertions.scala:1295)
2022-05-23T09:48:27.7700358Z [info]   at org.apache.spark.sql.jdbc.JDBCSuite.$anonfun$new$117(JDBCSuite.scala:1146)
2022-05-23T09:48:27.7700946Z [info]   at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
2022-05-23T09:48:27.7701557Z [info]   at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33)
2022-05-23T09:48:27.7702126Z [info]   at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:198)
2022-05-23T09:48:27.7702799Z [info]   at org.apache.spark.sql.jdbc.JDBCSuite.$anonfun$new$116(JDBCSuite.scala:1144)
2022-05-23T09:48:27.7703346Z [info]   at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
2022-05-23T09:48:27.7703870Z [info]   at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1481)
2022-05-23T09:48:27.7704451Z [info]   at org.apache.spark.sql.test.SQLTestUtilsBase.withTable(SQLTestUtils.scala:306)
2022-05-23T09:48:27.7705082Z [info]   at org.apache.spark.sql.test.SQLTestUtilsBase.withTable$(SQLTestUtils.scala:304)
2022-05-23T09:48:27.7705692Z [info]   at org.apache.spark.sql.jdbc.JDBCSuite.withTable(JDBCSuite.scala:48)
2022-05-23T09:48:27.7706491Z [info]   at org.apache.spark.sql.jdbc.JDBCSuite.$anonfun$new$115(JDBCSuite.scala:1131)
2022-05-23T09:48:27.7707032Z [info]   at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
2022-05-23T09:48:27.7707551Z [info]   at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
2022-05-23T09:48:27.7708053Z [info]   at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
2022-05-23T09:48:27.7708544Z [info]   at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
2022-05-23T09:48:27.7709026Z [info]   at org.scalatest.Transformer.apply(Transformer.scala:22)
2022-05-23T09:48:27.7709522Z [info]   at org.scalatest.Transformer.apply(Transformer.scala:20)
2022-05-23T09:48:27.7710081Z [info]   at org.scalatest.funsuite.AnyFunSuiteLike$$anon$1.apply(AnyFunSuiteLike.scala:190)
2022-05-23T09:48:27.7710740Z [info]   at org.apache.spark.SparkFunSuite.withFixture(SparkFunSuite.scala:203)
2022-05-23T09:48:27.7711377Z [info]   at org.scalatest.funsuite.AnyFunSuiteLike.invokeWithFixture$1(AnyFunSuiteLike.scala:188)
2022-05-23T09:48:27.7712015Z [info]   at org.scalatest.funsuite.AnyFunSuiteLike.$anonfun$runTest$1(AnyFunSuiteLike.scala:200)
2022-05-23T09:48:27.7712561Z [info]   at org.scalatest.SuperEngine.runTestImpl(Engine.scala:306)
2022-05-23T09:48:27.7713121Z [info]   at org.scalatest.funsuite.AnyFunSuiteLike.runTest(AnyFunSuiteLike.scala:200)
2022-05-23T09:48:27.7713713Z [info]   at org.scalatest.funsuite.AnyFunSuiteLike.runTest$(AnyFunSuiteLike.scala:182)
2022-05-23T09:48:27.7714354Z [info]   at org.apache.spark.SparkFunSuite.org$scalatest$BeforeAndAfterEach$$super$runTest(SparkFunSuite.scala:64)
2022-05-23T09:48:27.7714968Z [info]   at org.scalatest.BeforeAndAfterEach.runTest(BeforeAndAfterEach.scala:234)
2022-05-23T09:48:27.7715541Z [info]   at org.scalatest.BeforeAndAfterEach.runTest$(BeforeAndAfterEach.scala:227)
2022-05-23T09:48:27.7716158Z [info]   at org.apache.spark.sql.jdbc.JDBCSuite.org$scalatest$BeforeAndAfter$$super$runTest(JDBCSuite.scala:48)
2022-05-23T09:48:27.7716733Z [info]   at org.scalatest.BeforeAndAfter.runTest(BeforeAndAfter.scala:213)
2022-05-23T09:48:27.7717270Z [info]   at org.scalatest.BeforeAndAfter.runTest$(BeforeAndAfter.scala:203)
2022-05-23T09:48:27.7717813Z [info]   at org.apache.spark.sql.jdbc.JDBCSuite.runTest(JDBCSuite.scala:48)
2022-05-23T09:48:27.7718398Z [info]   at org.scalatest.funsuite.AnyFunSuiteLike.$anonfun$runTests$1(AnyFunSuiteLike.scala:233)
2022-05-23T09:48:27.7718974Z [info]   at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:413)
2022-05-23T09:48:27.7719487Z [info]   at scala.collection.immutable.List.foreach(List.scala:431)
2022-05-23T09:48:27.7720016Z [info]   at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
2022-05-23T09:48:27.7720554Z [info]   at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:396)
2022-05-23T09:48:27.7721076Z [info]   at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:475)
2022-05-23T09:48:27.7721641Z [info]   at org.scalatest.funsuite.AnyFunSuiteLike.runTests(AnyFunSuiteLike.scala:233)
2022-05-23T09:48:27.7722297Z [info]   at org.scalatest.funsuite.AnyFunSuiteLike.runTests$(AnyFunSuiteLike.scala:232)
2022-05-23T09:48:27.7722872Z [info]   at org.scalatest.funsuite.AnyFunSuite.runTests(AnyFunSuite.scala:1563)
2022-05-23T09:48:27.7723355Z [info]   at org.scalatest.Suite.run(Suite.scala:1112)
2022-05-23T09:48:27.7723787Z [info]   at org.scalatest.Suite.run$(Suite.scala:1094)
2022-05-23T09:48:27.7734912Z [info]   at org.scalatest.funsuite.AnyFunSuite.org$scalatest$funsuite$AnyFunSuiteLike$$super$run(AnyFunSuite.scala:1563)
2022-05-23T09:48:27.7735578Z [info]   at org.scalatest.funsuite.AnyFunSuiteLike.$anonfun$run$1(AnyFunSuiteLike.scala:237)
2022-05-23T09:48:27.7736113Z [info]   at org.scalatest.SuperEngine.runImpl(Engine.scala:535)
2022-05-23T09:48:27.7736675Z [info]   at org.scalatest.funsuite.AnyFunSuiteLike.run(AnyFunSuiteLike.scala:237)
2022-05-23T09:48:27.7737441Z [info]   at org.scalatest.funsuite.AnyFunSuiteLike.run$(AnyFunSuiteLike.scala:236)
2022-05-23T09:48:27.7738075Z [info]   at org.apache.spark.SparkFunSuite.org$scalatest$BeforeAndAfterAll$$super$run(SparkFunSuite.scala:64)
2022-05-23T09:48:27.7738690Z [info]   at org.scalatest.BeforeAndAfterAll.liftedTree1$1(BeforeAndAfterAll.scala:213)
2022-05-23T09:48:27.7739261Z [info]   at org.scalatest.BeforeAndAfterAll.run(BeforeAndAfterAll.scala:210)
2022-05-23T09:48:27.7739809Z [info]   at org.scalatest.BeforeAndAfterAll.run$(BeforeAndAfterAll.scala:208)
2022-05-23T09:48:27.7740411Z [info]   at org.apache.spark.sql.jdbc.JDBCSuite.org$scalatest$BeforeAndAfter$$super$run(JDBCSuite.scala:48)
2022-05-23T09:48:27.7740976Z [info]   at org.scalatest.BeforeAndAfter.run(BeforeAndAfter.scala:273)
2022-05-23T09:48:27.7741492Z [info]   at org.scalatest.BeforeAndAfter.run$(BeforeAndAfter.scala:271)
2022-05-23T09:48:27.7742012Z [info]   at org.apache.spark.sql.jdbc.JDBCSuite.run(JDBCSuite.scala:48)
2022-05-23T09:48:27.7742583Z [info]   at org.scalatest.tools.Framework.org$scalatest$tools$Framework$$runSuite(Framework.scala:318)
2022-05-23T09:48:27.7743347Z [info]   at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:513)
2022-05-23T09:48:27.7743842Z [info]   at sbt.ForkMain$Run.lambda$runTest$1(ForkMain.java:413)
2022-05-23T09:48:27.7744321Z [info]   at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2022-05-23T09:48:27.7744909Z [info]   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
2022-05-23T09:48:27.7745525Z [info]   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
2022-05-23T09:48:27.7746016Z [info]   at java.lang.Thread.run(Thread.java:750)

Suppose there is no problem of this pr, #36637 try to fix above issue.

@dongjoon-hyun
Copy link
Member

Hi, @sadikovi . Initially, we should not make a follow-up for the released JIRA for better traceability.
For example, it's very difficult to mention or trace. Please make a separate JIRA next time.

dongjoon-hyun pushed a commit that referenced this pull request May 23, 2022
### What changes were proposed in this pull request?
[SPARK-35378-FOLLOWUP](#36632) changes the return value of `CommandResultExec.executeCollect()` from `InternalRow` to `UnsafeRow`, this change causes the result of `r.tostring` in the following code:

https://github.com/apache/spark/blob/de73753bb2e5fd947f237e731ff05aa9f2711677/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala#L1143-L1148

change from

```
[CREATE TABLE tab1 (
  NAME STRING,
  THEID INT)
USING org.apache.spark.sql.jdbc
OPTIONS (
  'dbtable' = 'TEST.PEOPLE',
  'password' = '*********(redacted)',
  'url' = '*********(redacted)',
  'user' = 'testUser')
]
```
to

```
[0,10000000d5,5420455441455243,62617420454c4241,414e20200a282031,4e4952545320454d,45485420200a2c47,a29544e49204449,726f20474e495355,6568636170612e67,732e6b726170732e,a6362646a2e6c71,20534e4f4954504f,7462642720200a28,203d2027656c6261,45502e5453455427,200a2c27454c504f,6f77737361702720,2a27203d20276472,2a2a2a2a2a2a2a2a,6574636164657228,2720200a2c272964,27203d20276c7275,2a2a2a2a2a2a2a2a,746361646572282a,20200a2c27296465,3d20277265737527,7355747365742720,a29277265]
```

and the UT `JDBCSuite$Hide credentials in show create table` failed in master branch.

This pr is  change to use `executeCollectPublic()` instead of `executeCollect()` to fix this UT.

### Why are the changes needed?
Fix UT failed in mater branch after [SPARK-35378-FOLLOWUP](#36632)

### Does this PR introduce _any_ user-facing change?
NO.

### How was this patch tested?

- GitHub Action pass
- Manual test

Run `mvn clean install -DskipTests -pl sql/core -am -Dtest=none -DwildcardSuites=org.apache.spark.sql.jdbc.JDBCSuite`

**Before**

```
- Hide credentials in show create table *** FAILED ***
  "[0,10000000d5,5420455441455243,62617420454c4241,414e20200a282031,4e4952545320454d,45485420200a2c47,a29544e49204449,726f20474e495355,6568636170612e67,732e6b726170732e,a6362646a2e6c71,20534e4f4954504f,7462642720200a28,203d2027656c6261,45502e5453455427,200a2c27454c504f,6f77737361702720,2a27203d20276472,2a2a2a2a2a2a2a2a,6574636164657228,2720200a2c272964,27203d20276c7275,2a2a2a2a2a2a2a2a,746361646572282a,20200a2c27296465,3d20277265737527,7355747365742720,a29277265]" did not contain "TEST.PEOPLE" (JDBCSuite.scala:1146)

```

**After**

```
Run completed in 24 seconds, 868 milliseconds.
Total number of tests run: 93
Suites: completed 2, aborted 0
Tests: succeeded 93, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
```

Closes #36637 from LuciferYang/SPARK-39258.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
dongjoon-hyun pushed a commit that referenced this pull request May 23, 2022
### What changes were proposed in this pull request?
[SPARK-35378-FOLLOWUP](#36632) changes the return value of `CommandResultExec.executeCollect()` from `InternalRow` to `UnsafeRow`, this change causes the result of `r.tostring` in the following code:

https://github.com/apache/spark/blob/de73753bb2e5fd947f237e731ff05aa9f2711677/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala#L1143-L1148

change from

```
[CREATE TABLE tab1 (
  NAME STRING,
  THEID INT)
USING org.apache.spark.sql.jdbc
OPTIONS (
  'dbtable' = 'TEST.PEOPLE',
  'password' = '*********(redacted)',
  'url' = '*********(redacted)',
  'user' = 'testUser')
]
```
to

```
[0,10000000d5,5420455441455243,62617420454c4241,414e20200a282031,4e4952545320454d,45485420200a2c47,a29544e49204449,726f20474e495355,6568636170612e67,732e6b726170732e,a6362646a2e6c71,20534e4f4954504f,7462642720200a28,203d2027656c6261,45502e5453455427,200a2c27454c504f,6f77737361702720,2a27203d20276472,2a2a2a2a2a2a2a2a,6574636164657228,2720200a2c272964,27203d20276c7275,2a2a2a2a2a2a2a2a,746361646572282a,20200a2c27296465,3d20277265737527,7355747365742720,a29277265]
```

and the UT `JDBCSuite$Hide credentials in show create table` failed in master branch.

This pr is  change to use `executeCollectPublic()` instead of `executeCollect()` to fix this UT.

### Why are the changes needed?
Fix UT failed in mater branch after [SPARK-35378-FOLLOWUP](#36632)

### Does this PR introduce _any_ user-facing change?
NO.

### How was this patch tested?

- GitHub Action pass
- Manual test

Run `mvn clean install -DskipTests -pl sql/core -am -Dtest=none -DwildcardSuites=org.apache.spark.sql.jdbc.JDBCSuite`

**Before**

```
- Hide credentials in show create table *** FAILED ***
  "[0,10000000d5,5420455441455243,62617420454c4241,414e20200a282031,4e4952545320454d,45485420200a2c47,a29544e49204449,726f20474e495355,6568636170612e67,732e6b726170732e,a6362646a2e6c71,20534e4f4954504f,7462642720200a28,203d2027656c6261,45502e5453455427,200a2c27454c504f,6f77737361702720,2a27203d20276472,2a2a2a2a2a2a2a2a,6574636164657228,2720200a2c272964,27203d20276c7275,2a2a2a2a2a2a2a2a,746361646572282a,20200a2c27296465,3d20277265737527,7355747365742720,a29277265]" did not contain "TEST.PEOPLE" (JDBCSuite.scala:1146)

```

**After**

```
Run completed in 24 seconds, 868 milliseconds.
Total number of tests run: 93
Suites: completed 2, aborted 0
Tests: succeeded 93, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
```

Closes #36637 from LuciferYang/SPARK-39258.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit 6eb15d1)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
dongjoon-hyun pushed a commit that referenced this pull request May 23, 2022
### What changes were proposed in this pull request?
[SPARK-35378-FOLLOWUP](#36632) changes the return value of `CommandResultExec.executeCollect()` from `InternalRow` to `UnsafeRow`, this change causes the result of `r.tostring` in the following code:

https://github.com/apache/spark/blob/de73753bb2e5fd947f237e731ff05aa9f2711677/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala#L1143-L1148

change from

```
[CREATE TABLE tab1 (
  NAME STRING,
  THEID INT)
USING org.apache.spark.sql.jdbc
OPTIONS (
  'dbtable' = 'TEST.PEOPLE',
  'password' = '*********(redacted)',
  'url' = '*********(redacted)',
  'user' = 'testUser')
]
```
to

```
[0,10000000d5,5420455441455243,62617420454c4241,414e20200a282031,4e4952545320454d,45485420200a2c47,a29544e49204449,726f20474e495355,6568636170612e67,732e6b726170732e,a6362646a2e6c71,20534e4f4954504f,7462642720200a28,203d2027656c6261,45502e5453455427,200a2c27454c504f,6f77737361702720,2a27203d20276472,2a2a2a2a2a2a2a2a,6574636164657228,2720200a2c272964,27203d20276c7275,2a2a2a2a2a2a2a2a,746361646572282a,20200a2c27296465,3d20277265737527,7355747365742720,a29277265]
```

and the UT `JDBCSuite$Hide credentials in show create table` failed in master branch.

This pr is  change to use `executeCollectPublic()` instead of `executeCollect()` to fix this UT.

### Why are the changes needed?
Fix UT failed in mater branch after [SPARK-35378-FOLLOWUP](#36632)

### Does this PR introduce _any_ user-facing change?
NO.

### How was this patch tested?

- GitHub Action pass
- Manual test

Run `mvn clean install -DskipTests -pl sql/core -am -Dtest=none -DwildcardSuites=org.apache.spark.sql.jdbc.JDBCSuite`

**Before**

```
- Hide credentials in show create table *** FAILED ***
  "[0,10000000d5,5420455441455243,62617420454c4241,414e20200a282031,4e4952545320454d,45485420200a2c47,a29544e49204449,726f20474e495355,6568636170612e67,732e6b726170732e,a6362646a2e6c71,20534e4f4954504f,7462642720200a28,203d2027656c6261,45502e5453455427,200a2c27454c504f,6f77737361702720,2a27203d20276472,2a2a2a2a2a2a2a2a,6574636164657228,2720200a2c272964,27203d20276c7275,2a2a2a2a2a2a2a2a,746361646572282a,20200a2c27296465,3d20277265737527,7355747365742720,a29277265]" did not contain "TEST.PEOPLE" (JDBCSuite.scala:1146)

```

**After**

```
Run completed in 24 seconds, 868 milliseconds.
Total number of tests run: 93
Suites: completed 2, aborted 0
Tests: succeeded 93, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
```

Closes #36637 from LuciferYang/SPARK-39258.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit 6eb15d1)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
}

test("SPARK-35378: Return UnsafeRow in CommandResultExecCheck execute methods") {
val plan = spark.sql("SHOW FUNCTIONS").queryExecution.executedPlan
Copy link
Member

Choose a reason for hiding this comment

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

I am working on unification of v1 and v2 SHOW FUNCTIONS tests now. Does this command matter here or can be any other command?

Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem to be related to SHOW FUNCTIONS functionality. I don't think we need to include it in the SHOW FUNCTIONS test suite.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was reproducible with SHOW FUNCTIONS due to a bug mentioned in the PR. I don't think you can replace the SQL command in the test.

kazuyukitanimura pushed a commit to kazuyukitanimura/spark that referenced this pull request Aug 10, 2022
…ultExec.executeCollect()

### What changes were proposed in this pull request?

This PR is a follow-up for apache#32513 and fixes an issue introduced by that patch.

CommandResultExec is supposed to return `UnsafeRow` records in all of the `executeXYZ` methods but `executeCollect` was left out which causes issues like this one:
```
Error in SQL statement: ClassCastException: org.apache.spark.sql.catalyst.expressions.GenericInternalRow
cannot be cast to org.apache.spark.sql.catalyst.expressions.UnsafeRow
```

We need to return `unsafeRows` instead of `rows` in `executeCollect` similar to other methods in the class.

### Why are the changes needed?

Fixes a bug in CommandResultExec.

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

No.

### How was this patch tested?

I added a unit test to check the return type of all commands.

Closes apache#36632 from sadikovi/fix-command-exec.

Authored-by: Ivan Sadikov <ivan.sadikov@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit a0decfc)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
kazuyukitanimura pushed a commit to kazuyukitanimura/spark that referenced this pull request Aug 10, 2022
…ultExec.executeCollect()

### What changes were proposed in this pull request?

This PR is a follow-up for apache#32513 and fixes an issue introduced by that patch.

CommandResultExec is supposed to return `UnsafeRow` records in all of the `executeXYZ` methods but `executeCollect` was left out which causes issues like this one:
```
Error in SQL statement: ClassCastException: org.apache.spark.sql.catalyst.expressions.GenericInternalRow
cannot be cast to org.apache.spark.sql.catalyst.expressions.UnsafeRow
```

We need to return `unsafeRows` instead of `rows` in `executeCollect` similar to other methods in the class.

### Why are the changes needed?

Fixes a bug in CommandResultExec.

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

No.

### How was this patch tested?

I added a unit test to check the return type of all commands.

Closes apache#36632 from sadikovi/fix-command-exec.

Authored-by: Ivan Sadikov <ivan.sadikov@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit a0decfc)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
kazuyukitanimura pushed a commit to kazuyukitanimura/spark that referenced this pull request Aug 16, 2022
### What changes were proposed in this pull request?
[SPARK-35378-FOLLOWUP](apache#36632) changes the return value of `CommandResultExec.executeCollect()` from `InternalRow` to `UnsafeRow`, this change causes the result of `r.tostring` in the following code:

https://github.com/apache/spark/blob/de73753bb2e5fd947f237e731ff05aa9f2711677/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala#L1143-L1148

change from

```
[CREATE TABLE tab1 (
  NAME STRING,
  THEID INT)
USING org.apache.spark.sql.jdbc
OPTIONS (
  'dbtable' = 'TEST.PEOPLE',
  'password' = '*********(redacted)',
  'url' = '*********(redacted)',
  'user' = 'testUser')
]
```
to

```
[0,10000000d5,5420455441455243,62617420454c4241,414e20200a282031,4e4952545320454d,45485420200a2c47,a29544e49204449,726f20474e495355,6568636170612e67,732e6b726170732e,a6362646a2e6c71,20534e4f4954504f,7462642720200a28,203d2027656c6261,45502e5453455427,200a2c27454c504f,6f77737361702720,2a27203d20276472,2a2a2a2a2a2a2a2a,6574636164657228,2720200a2c272964,27203d20276c7275,2a2a2a2a2a2a2a2a,746361646572282a,20200a2c27296465,3d20277265737527,7355747365742720,a29277265]
```

and the UT `JDBCSuite$Hide credentials in show create table` failed in master branch.

This pr is  change to use `executeCollectPublic()` instead of `executeCollect()` to fix this UT.

### Why are the changes needed?
Fix UT failed in mater branch after [SPARK-35378-FOLLOWUP](apache#36632)

### Does this PR introduce _any_ user-facing change?
NO.

### How was this patch tested?

- GitHub Action pass
- Manual test

Run `mvn clean install -DskipTests -pl sql/core -am -Dtest=none -DwildcardSuites=org.apache.spark.sql.jdbc.JDBCSuite`

**Before**

```
- Hide credentials in show create table *** FAILED ***
  "[0,10000000d5,5420455441455243,62617420454c4241,414e20200a282031,4e4952545320454d,45485420200a2c47,a29544e49204449,726f20474e495355,6568636170612e67,732e6b726170732e,a6362646a2e6c71,20534e4f4954504f,7462642720200a28,203d2027656c6261,45502e5453455427,200a2c27454c504f,6f77737361702720,2a27203d20276472,2a2a2a2a2a2a2a2a,6574636164657228,2720200a2c272964,27203d20276c7275,2a2a2a2a2a2a2a2a,746361646572282a,20200a2c27296465,3d20277265737527,7355747365742720,a29277265]" did not contain "TEST.PEOPLE" (JDBCSuite.scala:1146)

```

**After**

```
Run completed in 24 seconds, 868 milliseconds.
Total number of tests run: 93
Suites: completed 2, aborted 0
Tests: succeeded 93, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
```

Closes apache#36637 from LuciferYang/SPARK-39258.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit 6eb15d1)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
sunchao pushed a commit to sunchao/spark that referenced this pull request Jun 2, 2023
### What changes were proposed in this pull request?
[SPARK-35378-FOLLOWUP](apache#36632) changes the return value of `CommandResultExec.executeCollect()` from `InternalRow` to `UnsafeRow`, this change causes the result of `r.tostring` in the following code:

https://github.com/apache/spark/blob/de73753bb2e5fd947f237e731ff05aa9f2711677/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala#L1143-L1148

change from

```
[CREATE TABLE tab1 (
  NAME STRING,
  THEID INT)
USING org.apache.spark.sql.jdbc
OPTIONS (
  'dbtable' = 'TEST.PEOPLE',
  'password' = '*********(redacted)',
  'url' = '*********(redacted)',
  'user' = 'testUser')
]
```
to

```
[0,10000000d5,5420455441455243,62617420454c4241,414e20200a282031,4e4952545320454d,45485420200a2c47,a29544e49204449,726f20474e495355,6568636170612e67,732e6b726170732e,a6362646a2e6c71,20534e4f4954504f,7462642720200a28,203d2027656c6261,45502e5453455427,200a2c27454c504f,6f77737361702720,2a27203d20276472,2a2a2a2a2a2a2a2a,6574636164657228,2720200a2c272964,27203d20276c7275,2a2a2a2a2a2a2a2a,746361646572282a,20200a2c27296465,3d20277265737527,7355747365742720,a29277265]
```

and the UT `JDBCSuite$Hide credentials in show create table` failed in master branch.

This pr is  change to use `executeCollectPublic()` instead of `executeCollect()` to fix this UT.

### Why are the changes needed?
Fix UT failed in mater branch after [SPARK-35378-FOLLOWUP](apache#36632)

### Does this PR introduce _any_ user-facing change?
NO.

### How was this patch tested?

- GitHub Action pass
- Manual test

Run `mvn clean install -DskipTests -pl sql/core -am -Dtest=none -DwildcardSuites=org.apache.spark.sql.jdbc.JDBCSuite`

**Before**

```
- Hide credentials in show create table *** FAILED ***
  "[0,10000000d5,5420455441455243,62617420454c4241,414e20200a282031,4e4952545320454d,45485420200a2c47,a29544e49204449,726f20474e495355,6568636170612e67,732e6b726170732e,a6362646a2e6c71,20534e4f4954504f,7462642720200a28,203d2027656c6261,45502e5453455427,200a2c27454c504f,6f77737361702720,2a27203d20276472,2a2a2a2a2a2a2a2a,6574636164657228,2720200a2c272964,27203d20276c7275,2a2a2a2a2a2a2a2a,746361646572282a,20200a2c27296465,3d20277265737527,7355747365742720,a29277265]" did not contain "TEST.PEOPLE" (JDBCSuite.scala:1146)

```

**After**

```
Run completed in 24 seconds, 868 milliseconds.
Total number of tests run: 93
Suites: completed 2, aborted 0
Tests: succeeded 93, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
```

Closes apache#36637 from LuciferYang/SPARK-39258.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit 6eb15d1)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
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.

6 participants