Skip to content

Build: Apply spotless for scala code#8023

Merged
kevinjqliu merged 2 commits intoapache:mainfrom
ConeyLiu:scala-spotless
Dec 2, 2025
Merged

Build: Apply spotless for scala code#8023
kevinjqliu merged 2 commits intoapache:mainfrom
ConeyLiu:scala-spotless

Conversation

@ConeyLiu
Copy link
Contributor

@ConeyLiu ConeyLiu commented Jul 9, 2023

Closes #7695.

# specific language governing permissions and limitations
# under the License.

align = none
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is modified from spark

}
danglingParentheses.preset = false
docstrings.style = Asterisk
maxColumn = 100
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Set to 100 to align java code.

Copy link
Contributor

Choose a reason for hiding this comment

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

just curious, what's the default value? For Java the default is mandated by the Google Java Format and set to 100

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zinking
Copy link
Contributor

zinking commented Jul 12, 2023

@Fokko are we going to force styles on scala as well? not sure why this isn't done when enforcing styles on java.
if the answer is yes, guess we need to do this early instead of late.

@ConeyLiu
Copy link
Contributor Author

Hi, @nastra @zinking @Fokko would you mind taking another look at this? Thanks in advance.

@ConeyLiu
Copy link
Contributor Author

Also cc @jackye1995 @amogh-jahagirdar who have disscuessed this at #6736

@nastra
Copy link
Contributor

nastra commented Jul 18, 2023

@ConeyLiu I think this is a great topic to mention on the DEV mailist list & Iceberg Sync, so that people are aware about this effort

@ConeyLiu
Copy link
Contributor Author

Thanks @nastra, raised the discussion at the dev mail list.

@zinking
Copy link
Contributor

zinking commented Jul 19, 2023

LGTM now, I'd suggest let's get this style in early.

@ajantha-bhat
Copy link
Member

Just linking the conclusion here as I was searching for it.
https://lists.apache.org/thread/sv70lr0bwl9jmxtzvho2ml5xcrcpzf3b

@github-actions
Copy link

github-actions bot commented Sep 6, 2024

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.

@github-actions github-actions bot added the stale label Sep 6, 2024
@github-actions
Copy link

This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@github-actions github-actions bot closed this Sep 19, 2024
@nastra
Copy link
Contributor

nastra commented May 14, 2025

@ConeyLiu are you interested in continuing work on this?

@nastra nastra reopened this May 14, 2025
@github-actions github-actions bot removed the stale label May 15, 2025
@ConeyLiu
Copy link
Contributor Author

Sure, I will rebase it these days.

@github-actions
Copy link

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.

@ConeyLiu
Copy link
Contributor Author

Also it would be good to update https://github.com/apache/iceberg/blob/8e897f1b68c38c6352f23d636c320e3754d58eef/site/docs/contribute.md#setting-up-ide-and-code-style and mention how to set up IntelliJ with Scalafmt so that formatting inside IntelliJ produces the same formatting results across cmd line (./gradlew spotlessApply) and the IDE

@nastra Does this need a separate commit or rebased into the first commit 'Add scalafmt and config for spotless'

@ConeyLiu
Copy link
Contributor Author

could you please raise awareness about this on the DEV mailing list so that people have a chance to review this?

Done it.

@nastra
Copy link
Contributor

nastra commented Jun 24, 2025

Also it would be good to update https://github.com/apache/iceberg/blob/8e897f1b68c38c6352f23d636c320e3754d58eef/site/docs/contribute.md#setting-up-ide-and-code-style and mention how to set up IntelliJ with Scalafmt so that formatting inside IntelliJ produces the same formatting results across cmd line (./gradlew spotlessApply) and the IDE

@nastra Does this need a separate commit or rebased into the first commit 'Add scalafmt and config for spotless'

I think adding this into the first commit should be fine


version = 3.9.7

align = none
Copy link
Member

Choose a reason for hiding this comment

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

for learning, why do we deviate for [Imports]

output: Seq[Attribute],
procedure: Procedure,
input: InternalRow) extends LeafV2CommandExec {
case class CallExec(output: Seq[Attribute], procedure: Procedure, input: InternalRow)
Copy link
Member

Choose a reason for hiding this comment

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

nit: can we keep the old one to be more like Spark and be more readable (or does it violate scalafmt because of maxColumns?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because all parameters can be placed in a single line without exceeding the maximum line limit; if the limit is exceeded, they will be stored in multiple columns. I checked the Spark code, and it uses a similar approach.
image

import scala.jdk.CollectionConverters._

class IcebergSparkSqlExtensionsParser(delegate: ParserInterface) extends ParserInterface with ExtendedParser {
class IcebergSparkSqlExtensionsParser(delegate: ParserInterface)
Copy link
Member

Choose a reason for hiding this comment

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

The import org.apache.iceberg.spark.procedures.SparkProcedures is not used in this class. Should it be removed by spotless?

@jackylee-ch
Copy link
Contributor

@singhpk234 Based on the issue and PR in Spotless, the unused imports aren’t handled. We need a separate Scalafix rule to take care of that.

@nastra
Copy link
Contributor

nastra commented Nov 27, 2025

@ConeyLiu where are we with this PR? Could you please rebase it so that we can get it in?

@ConeyLiu
Copy link
Contributor Author

I can rebase it today or tomorrow.

@ConeyLiu ConeyLiu force-pushed the scala-spotless branch 2 times, most recently from a495530 to 4633c41 Compare November 29, 2025 13:56
Copy link
Contributor

@kevinjqliu kevinjqliu left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for adding this.

i tried this out locally. Looks like the spark scalafmt has been modified, maybe we should align with the new configs

Comment on lines 66 to 79
// Configure different scalafmt rules for specific Scala version
if (project.name.startsWith("iceberg-spark") && project.name.endsWith("2.13")) {
scala {
target 'src/main/scala/**/*.scala', 'src/test/scala/**/*.scala', 'src/testFixtures/scala/**/*.scala'
scalafmt("3.9.7").configFile("$rootDir/.baseline/scala/.scala213fmt.conf")
licenseHeaderFile "$rootDir/.baseline/copyright/copyright-header-java.txt", "package"
}
} else if (project.name.startsWith("iceberg-spark") && project.name.endsWith("2.12")) {
scala {
target 'src/main/scala/**/*.scala', 'src/test/scala/**/*.scala', 'src/testFixtures/scala/**/*.scala'
scalafmt("3.9.7").configFile("$rootDir/.baseline/scala/.scala212fmt.conf")
licenseHeaderFile "$rootDir/.baseline/copyright/copyright-header-java.txt", "package"
}
}
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
// Configure different scalafmt rules for specific Scala version
if (project.name.startsWith("iceberg-spark") && project.name.endsWith("2.13")) {
scala {
target 'src/main/scala/**/*.scala', 'src/test/scala/**/*.scala', 'src/testFixtures/scala/**/*.scala'
scalafmt("3.9.7").configFile("$rootDir/.baseline/scala/.scala213fmt.conf")
licenseHeaderFile "$rootDir/.baseline/copyright/copyright-header-java.txt", "package"
}
} else if (project.name.startsWith("iceberg-spark") && project.name.endsWith("2.12")) {
scala {
target 'src/main/scala/**/*.scala', 'src/test/scala/**/*.scala', 'src/testFixtures/scala/**/*.scala'
scalafmt("3.9.7").configFile("$rootDir/.baseline/scala/.scala212fmt.conf")
licenseHeaderFile "$rootDir/.baseline/copyright/copyright-header-java.txt", "package"
}
}
// Configure different scalafmt rules for specific Scala version
if (project.name.startsWith("iceberg-spark") && project.name.endsWith("2.13")) {
scala {
target 'src/**/*.scala'
scalafmt("3.9.7").configFile("$rootDir/.baseline/scala/.scala213fmt.conf")
licenseHeaderFile "$rootDir/.baseline/copyright/copyright-header-java.txt", "package"
}
} else if (project.name.startsWith("iceberg-spark") && project.name.endsWith("2.12")) {
scala {
target 'src/**/*.scala'
scalafmt("3.9.7").configFile("$rootDir/.baseline/scala/.scala212fmt.conf")
licenseHeaderFile "$rootDir/.baseline/copyright/copyright-header-java.txt", "package"
}
}

nit capture all .scala files in case more folders are added in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @kevinjqliu, updated


version = 3.9.7

align = none
Copy link
Contributor

Choose a reason for hiding this comment

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

rewrite.rules

has been removed from https://github.com/apache/spark/blob/f5b9ea8103dd1f37c6f0cea0692d7bc5b50b778c/dev/.scalafmt.conf

the only difference now is version (3.8.6 vs 3.9.7) and maxColumn (98 vs 100) and docstrings.wrap

}

// Configure different scalafmt rules for specific Scala version
if (project.name.startsWith("iceberg-spark") && project.name.endsWith("2.13")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to check iceberg-spark? It only affects the Scala code, right? Also, should we get the scalaVersion from the System.getProperty rather than from the project name?

Copy link
Contributor

Choose a reason for hiding this comment

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

should we get the scalaVersion from the System.getProperty rather than from the project name?

i think thats a good idea, we do it here already

cc @ConeyLiu

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll follow up on this these days

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Submitted #14798

@kevinjqliu kevinjqliu merged commit 166a6eb into apache:main Dec 2, 2025
47 checks passed
@kevinjqliu
Copy link
Contributor

Thank you for the PR @ConeyLiu and thanks everyone for the review.
Merging this in to prevent more conflicts. We can continue to iterate in a follow up PR 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apply spotless for scala code

10 participants