Skip to content

[SQL][MINOR] Fix compiling for scala 2.12 #22260

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
wants to merge 4 commits into from

Conversation

da-liii
Copy link
Contributor

@da-liii da-liii commented Aug 29, 2018

What changes were proposed in this pull request?

Introduced by #21320 and #11744

$ sbt
> ++2.12.6
> project sql
> compile
...
[error] [warn] spark/sql/core/src/main/scala/org/apache/spark/sql/execution/ProjectionOverSchema.scala:41: match may not be exhaustive.
[error] It would fail on the following inputs: (_, ArrayType(_, _)), (_, _)
[error] [warn]         getProjection(a.child).map(p => (p, p.dataType)).map {
[error] [warn]
[error] [warn] spark/sql/core/src/main/scala/org/apache/spark/sql/execution/ProjectionOverSchema.scala:52: match may not be exhaustive.
[error] It would fail on the following input: (_, _)
[error] [warn]         getProjection(child).map(p => (p, p.dataType)).map {
[error] [warn]
...

And

$ sbt
> ++2.12.6
> project hive
> testOnly *ParquetMetastoreSuite
...
[error] /Users/rendong/wdi/spark/sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveSparkSubmitSuite.scala:22: object tools is not a member of package scala
[error] import scala.tools.nsc.Properties
[error]              ^
[error] /Users/rendong/wdi/spark/sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveSparkSubmitSuite.scala:146: not found: value Properties
[error]     val version = Properties.versionNumberString match {
[error]                   ^
[error] two errors found
...

How was this patch tested?

Existing tests.

@@ -38,7 +38,7 @@ private[execution] case class ProjectionOverSchema(schema: StructType) {
case GetArrayItem(child, arrayItemOrdinal) =>
getProjection(child).map { projection => GetArrayItem(projection, arrayItemOrdinal) }
case a: GetArrayStructFields =>
getProjection(a.child).map(p => (p, p.dataType)).map {
getProjection(a.child).map(p => (p, p.dataType)).collect {
Copy link
Member

Choose a reason for hiding this comment

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

How about this? IMO .collect can't catch illegal inputs?

        getProjection(a.child).map(p => (p, p.dataType)).map {
          case (projection, ArrayType(projSchema @ StructType(_), _)) =>
            GetArrayStructFields(projection,
              projSchema(a.field.name),
              projSchema.fieldIndex(a.field.name),
              projSchema.size,
              a.containsNull)
          case _ =>
            sys.error("....")
        }

Copy link
Contributor Author

@da-liii da-liii Aug 29, 2018

Choose a reason for hiding this comment

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

Well, there is a semantic change using collect. I will provide a unit test to verify the change or simply adopt sys.error

Copy link
Member

Choose a reason for hiding this comment

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

Does this generate an error or just a warning in 2.12? It's an unmatched case error, right?
We had 'fixed' this elsewhere with case _ => throw new IllegalStateException(...) or something. At runtime it would have caused a MatchError before, right? Because it didn't, I hope, or else tests would have failed, it matters a bit less what happens in this case. But it felt more conservative to preserve the error behavior; maybe I was wrong about that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To use collect, one must dive into SPARK-4502.

This PR is intended for #22264 .

I will preserve the error behavior.

@maropu
Copy link
Member

maropu commented Aug 29, 2018

Can you add [SQL][MINOR] in the title? Also, can you narrow down the tittle cuz it is a little obscure.

@HyukjinKwon
Copy link
Member

ok to test

@da-liii da-liii changed the title [MINOR] Fix scala 2.12 build using collect [SQL][MINOR] Fix compiling for scala 2.12 Aug 29, 2018
@da-liii da-liii changed the title [SQL][MINOR] Fix compiling for scala 2.12 [WIP][SQL][MINOR] Fix compiling for scala 2.12 Aug 29, 2018
@SparkQA
Copy link

SparkQA commented Aug 29, 2018

Test build #95401 has finished for PR 22260 at commit 626f265.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@da-liii da-liii changed the title [WIP][SQL][MINOR] Fix compiling for scala 2.12 [SQL][MINOR] Fix compiling for scala 2.12 Aug 29, 2018
@SparkQA
Copy link

SparkQA commented Aug 29, 2018

Test build #95406 has finished for PR 22260 at commit ffdb12d.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@@ -19,7 +19,7 @@ package org.apache.spark.sql.hive

import java.io.{BufferedWriter, File, FileWriter}

import scala.tools.nsc.Properties
import scala.util.Properties
Copy link
Member

Choose a reason for hiding this comment

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

This works in 2.11 and 2.12?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. And

scala.util.Properties is better than scala.tools.nsc.Properties !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

scala.tools is part of scala-compiler

@@ -38,7 +38,7 @@ private[execution] case class ProjectionOverSchema(schema: StructType) {
case GetArrayItem(child, arrayItemOrdinal) =>
getProjection(child).map { projection => GetArrayItem(projection, arrayItemOrdinal) }
case a: GetArrayStructFields =>
getProjection(a.child).map(p => (p, p.dataType)).map {
getProjection(a.child).map(p => (p, p.dataType)).collect {
Copy link
Member

Choose a reason for hiding this comment

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

Does this generate an error or just a warning in 2.12? It's an unmatched case error, right?
We had 'fixed' this elsewhere with case _ => throw new IllegalStateException(...) or something. At runtime it would have caused a MatchError before, right? Because it didn't, I hope, or else tests would have failed, it matters a bit less what happens in this case. But it felt more conservative to preserve the error behavior; maybe I was wrong about that?

@da-liii
Copy link
Contributor Author

da-liii commented Aug 30, 2018

@maropu @srowen please review

@maropu
Copy link
Member

maropu commented Aug 30, 2018

LGTM, too.

@SparkQA
Copy link

SparkQA commented Aug 30, 2018

Test build #95452 has finished for PR 22260 at commit 2dff17b.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@HyukjinKwon
Copy link
Member

Merged to master.

@asfgit asfgit closed this in 56bc700 Aug 30, 2018
fjh100456 pushed a commit to fjh100456/spark that referenced this pull request Aug 31, 2018
## What changes were proposed in this pull request?
Introduced by apache#21320 and apache#11744

```
$ sbt
> ++2.12.6
> project sql
> compile
...
[error] [warn] spark/sql/core/src/main/scala/org/apache/spark/sql/execution/ProjectionOverSchema.scala:41: match may not be exhaustive.
[error] It would fail on the following inputs: (_, ArrayType(_, _)), (_, _)
[error] [warn]         getProjection(a.child).map(p => (p, p.dataType)).map {
[error] [warn]
[error] [warn] spark/sql/core/src/main/scala/org/apache/spark/sql/execution/ProjectionOverSchema.scala:52: match may not be exhaustive.
[error] It would fail on the following input: (_, _)
[error] [warn]         getProjection(child).map(p => (p, p.dataType)).map {
[error] [warn]
...
```

And

```
$ sbt
> ++2.12.6
> project hive
> testOnly *ParquetMetastoreSuite
...
[error] /Users/rendong/wdi/spark/sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveSparkSubmitSuite.scala:22: object tools is not a member of package scala
[error] import scala.tools.nsc.Properties
[error]              ^
[error] /Users/rendong/wdi/spark/sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveSparkSubmitSuite.scala:146: not found: value Properties
[error]     val version = Properties.versionNumberString match {
[error]                   ^
[error] two errors found
...
```

## How was this patch tested?
Existing tests.

Closes apache#22260 from sadhen/fix_exhaustive_match.

Authored-by: 忍冬 <rendong@wacai.com>
Signed-off-by: hyukjinkwon <gurwls223@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants