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-45629][CORE][SQL][CONNECT][ML][STREAMING][BUILD][EXAMPLES]Fix Implicit definition should have explicit type #43526

Closed
wants to merge 31 commits into from

Conversation

laglangyue
Copy link

@laglangyue laglangyue commented Oct 25, 2023

What changes were proposed in this pull request?

This PR aims to fix Implicit definition should have explicit type in Scala 2.13.

This pr includes:

  1. Declaration types for global variables of implicit
  2. Add @scala.annotation.warn

Why are the changes needed?

  • For implicit global variables without explicit type declaration, will get warnning :
    warning: Implicit definition should have explicit type (inferred String) [quickfixable]
  • No modifications are required for local variables.
    Additionally, to handle cases involving reflection-related types like ClassTag in implicit variables, the @scala.annotation.warn annotation is used to suppress the warning.

Furthermore, warnings generated in Spark will be treated as errors:

[error] ... Implicit definition should have explicit type (inferred org.json4s.DefaultFormats.type) [quickfixable]
...
[error] implicit val formats = org.json4s.DefaultFormats

Jira link:
SPARK-45314: https://issues.apache.org/jira/browse/SPARK-45629

Related issue link about implicit :
scala/bug#5265

Does this PR introduce any user-facing change?

no

How was this patch tested?

Most of the testing is completed through CI, and the example module is locally compiled and tested in IDEA Additionally, there are some writing changes that are verified through demo code

Was this patch authored or co-authored using generative AI tooling?

no

@laglangyue
Copy link
Author

Hi, brother
@LuciferYang
How can I reproduce this? I would like to check if I have made all the necessary modifications

[error] /Users/yangjie01/SourceCode/git/spark-mine-sbt/core/src/main/scala/org/apache/spark/deploy/FaultToleranceTest.scala:343:16: Implicit definition should have explicit type (inferred org.json4s.DefaultFormats.type) [quickfixable]
[error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=other-implicit-type, site=org.apache.spark.deploy.TestMasterInfo.formats
[error]   implicit val formats = org.json4s.DefaultFormats
[error]   

@LuciferYang
Copy link
Contributor

LuciferYang commented Nov 1, 2023

"-Wconf:msg=Implicit definition should have explicit type:s",

@laglangyue You can delete the above line and then compile with

build/sbt -Phadoop-3 -Pdocker-integration-tests -Pspark-ganglia-lgpl -Pkinesis-asl -Pkubernetes -Phive-thriftserver -Pconnect -Pyarn -Phive -Phadoop-cloud -Pvolcano -Pkubernetes-integration-tests Test/package streaming-kinesis-asl-assembly/assembly connect/assembly

If no further compilation errors occur, we can consider the task completed.

@laglangyue laglangyue changed the title [WIP][SPARK-45629]Fix Implicit definition should have explicit type [SPARK-45629]Fix Implicit definition should have explicit type Nov 3, 2023
@laglangyue
Copy link
Author

"-Wconf:msg=Implicit definition should have explicit type:s",

@laglangyue You can delete the above line and then compile with

build/sbt -Phadoop-3 -Pdocker-integration-tests -Pspark-ganglia-lgpl -Pkinesis-asl -Pkubernetes -Phive-thriftserver -Pconnect -Pyarn -Phive -Phadoop-cloud -Pvolcano -Pkubernetes-integration-tests Test/package streaming-kinesis-asl-assembly/assembly connect/assembly

If no further compilation errors occur, we can consider the task completed.

Exciting for building successful,I has finished.

@laglangyue
Copy link
Author

image

Copy link
Contributor

@LuciferYang LuciferYang left a comment

Choose a reason for hiding this comment

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

Can you update the pr title to add the corresponding module label? Can you update the pr description to specifically explain why this work needs to be done (I don't think the subtask of SPARK-45314 is a rigorous reason)? Also, is it still a compile warning in Scala 3, or will it turn into a compile error?

project/SparkBuild.scala Show resolved Hide resolved
@@ -340,7 +341,7 @@ private object FaultToleranceTest extends App with Logging {
private class TestMasterInfo(val ip: String, val dockerId: DockerId, val logFile: File)
Copy link
Contributor

Choose a reason for hiding this comment

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

FaultToleranceTest is a strange file, it's a test class, but it's in the production directory (so it probably has never been run by GA task). Can we directly delete this file? @srowen @dongjoon-hyun @HyukjinKwon

@LuciferYang
Copy link
Contributor

@laglangyue Additionally, GA's testing has not yet passed, we need to make them all pass

@laglangyue
Copy link
Author

@LuciferYang there is a CI error,I don't know why.

@LuciferYang
Copy link
Contributor

I think we can just retry the failed task

@LuciferYang
Copy link
Contributor

Is this one ready to review?

@laglangyue
Copy link
Author

Is this one ready to review?

yes.

@@ -23,7 +23,7 @@ import java.nio.file.Files
import scala.collection.mutable
import scala.util.control.NonFatal

import org.json4s.{DefaultFormats, Extraction}
import org.json4s._
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import org.json4s._
import org.json4s.{DefaultFormats, Extraction, Formats}

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm... seems like this has been revert again?


/** Needed to serialize type T into JSON when using Jackson */
@nowarn
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@nowarn
@scala.annotation.nowarn

Copy link
Contributor

Choose a reason for hiding this comment

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

When this annotation is only needed in one place in this class, it is customary to use xx directly.

Copy link
Author

Choose a reason for hiding this comment

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

thanks, get it firstly.

@@ -36,8 +33,8 @@ class FileStreamSourceLog(
path: String)
extends CompactibleFileStreamLog[FileEntry](metadataLogVersion, sparkSession, path) {

import CompactibleFileStreamLog._
import FileStreamSourceLog._
import org.apache.spark.sql.execution.streaming.CompactibleFileStreamLog._
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it necessary to change to import with the full name here?

Copy link
Author

Choose a reason for hiding this comment

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

maybe changed by Idea. I have reverted


/** Needed to serialize type T into JSON when using Jackson */
@nowarn
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@nowarn
@scala.annotation.nowarn


@nowarn
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@nowarn
@scala.annotation.nowarn

Copy link
Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@LuciferYang LuciferYang 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 , pending test

@LuciferYang
Copy link
Contributor

@laglangyue Could you modify the description of this PR again? Need to focus on the description of the Why are the changes needed? part.

In addition to fixing a compilation warning in Scala 2.13, you may need to summarize the key points in #43526 (comment), and add it to the pr description so that the changes in this pr can be considered necessary. Note, this is just an example, if you have a more solid reason to describe Why are the changes needed?, that would be better.

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.

Sorry for being late for this PR. Feel free to proceed to merge, @LuciferYang .

@LuciferYang
Copy link
Contributor

Merged into master for Spark 4.0. Thanks @laglangyue and @dongjoon-hyun ~

asl3 pushed a commit to asl3/spark that referenced this pull request Dec 5, 2023
… `Implicit definition should have explicit type`

### What changes were proposed in this pull request?
This PR aims to fix `Implicit definition should have explicit type` in Scala 2.13.

This pr includes:
1. Declaration types for global variables of implicit
2. Add scala.annotation.warn

### Why are the changes needed?

- For implicit global variables without explicit type declaration, will get warnning :
warning: Implicit definition should have explicit type (inferred String) [quickfixable]
- No modifications are required for local variables.
Additionally, to handle cases involving reflection-related types like ClassTag in implicit variables, the [scala.annotation.warn](https://github.com/scala.annotation.warn) annotation is used to suppress the warning.

Furthermore, warnings generated in Spark will be treated as errors:

[error] ... Implicit definition should have explicit type (inferred org.json4s.DefaultFormats.type) [quickfixable]
...
[error]   implicit val formats = org.json4s.DefaultFormats

Jira link:
SPARK-45314: https://issues.apache.org/jira/browse/SPARK-45629

Related issue link about `implicit` :
scala/bug#5265

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

no

### How was this patch tested?

Most of the testing is completed through CI, and the example module is locally compiled and tested in IDEA Additionally, there are some writing changes that are verified through demo code

### Was this patch authored or co-authored using generative AI tooling?

no

Closes apache#43526 from laglangyue/SPARK-45629.

Lead-authored-by: tangjiafu <jiafu.tang@qq.com>
Co-authored-by: tangjiafu <tangjiafu@corp.netease.com>
Signed-off-by: yangjie01 <yangjie01@baidu.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants