Skip to content

Commit dd6ee03

Browse files
authored
Infra: Enable spotless (#208)
* Infra: Enable spotless * fmt * style
1 parent 4eb66ab commit dd6ee03

File tree

14 files changed

+114
-49
lines changed

14 files changed

+114
-49
lines changed

.github/workflows/style.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# https://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
name: "Check Style"
14+
15+
on:
16+
push:
17+
branches:
18+
- "master"
19+
pull_request:
20+
branches:
21+
- "master"
22+
23+
jobs:
24+
check-style:
25+
runs-on: ubuntu-20.04
26+
steps:
27+
- uses: actions/checkout@v2
28+
- uses: actions/setup-java@v2
29+
with:
30+
distribution: zulu
31+
java-version: 8
32+
cache: gradle
33+
- run: >-
34+
./gradlew spotlessCheck --no-daemon --refresh-dependencies
35+
-PmavenCentralMirror=https://maven-central.storage-download.googleapis.com/maven2/

.github/workflows/tpcds.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# limitations under the License.
1212

1313
name: "Build and Test"
14+
1415
on:
1516
push:
1617
branches:
@@ -20,7 +21,7 @@ on:
2021
- "master"
2122

2223
jobs:
23-
tpcds-tests:
24+
run-tpcds-sf1:
2425
runs-on: ubuntu-20.04
2526
strategy:
2627
fail-fast: false

.scalafmt.conf

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
// See the License for the specific language governing permissions and
1111
// limitations under the License.
1212

13-
version = 3.1.2
13+
version=3.6.1
1414
runner.dialect=scala212
1515
project.git=true
1616

17-
align.preset = none
18-
align.stripMargin = true
19-
docstrings.style = Asterisk
20-
maxColumn = 120
21-
newlines.source = keep
22-
continuationIndent.defnSite = 2
23-
danglingParentheses.callSite = true
24-
assumeStandardLibraryStripMargin = true
25-
rewrite.rules = [SortImports, RedundantBraces, RedundantParens, SortModifiers]
17+
align.preset=none
18+
align.stripMargin=true
19+
docstrings.style=keep
20+
maxColumn=120
21+
newlines.source=keep
22+
continuationIndent.defnSite=2
23+
danglingParentheses.callSite=true
24+
assumeStandardLibraryStripMargin=true
25+
rewrite.rules=[SortImports, RedundantBraces, RedundantParens, SortModifiers]

build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ plugins {
1616
id "idea"
1717
id "org.scoverage" version "7.0.1" apply false
1818
id "org.sonarqube" version "3.4.0.2513"
19+
id "com.diffplug.spotless" version "6.12.1" apply false
1920
id "org.nosphere.apache.rat" version "0.8.0"
2021
id "com.github.maiflai.scalatest" version "0.32" apply false
2122
id "com.github.johnrengelman.shadow" version "7.1.2" apply false
@@ -60,6 +61,7 @@ subprojects {
6061
apply plugin: "scala"
6162
apply plugin: "java-library"
6263
apply plugin: "org.scoverage"
64+
apply plugin: "com.diffplug.spotless"
6365
apply plugin: "com.github.maiflai.scalatest"
6466

6567
repositories {
@@ -99,6 +101,14 @@ subprojects {
99101
highlighting.set(false)
100102
minimumRate.set(0.0)
101103
}
104+
105+
spotless {
106+
scala {
107+
scalafmt("3.6.1")
108+
.configFile("${rootProject.projectDir}/.scalafmt.conf")
109+
.scalaMajorVersion("2.12")
110+
}
111+
}
102112
}
103113

104114
project(':clickhouse-core') {

clickhouse-core/src/main/scala/xenon/clickhouse/Utils.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ object Utils extends Logging {
4747

4848
def classpathResourceAsStream(name: String): InputStream = defaultClassLoader.getResourceAsStream(name)
4949

50-
def getCodeSourceLocation(clazz: Class[_]): String = {
50+
def getCodeSourceLocation(clazz: Class[_]): String =
5151
new File(clazz.getProtectionDomain.getCodeSource.getLocation.toURI).getPath
52-
}
5352

5453
@transient lazy val tmpDirPath: Path = Files.createTempDirectory("classpath_res_")
5554

@@ -113,7 +112,7 @@ object Utils extends Logging {
113112
// The number is too large, show it in scientific notation.
114113
BigDecimal(size, new MathContext(3, RoundingMode.HALF_UP)).toString() + " B"
115114
} else {
116-
val (value, unit) = {
115+
val (value, unit) =
117116
if (size >= 2 * EiB) {
118117
(BigDecimal(size) / EiB, "EiB")
119118
} else if (size >= 2 * PiB) {
@@ -129,7 +128,6 @@ object Utils extends Logging {
129128
} else {
130129
(BigDecimal(size), "B")
131130
}
132-
}
133131
"%.1f %s".formatLocal(Locale.US, value, unit)
134132
}
135133
}

clickhouse-core/src/main/scala/xenon/clickhouse/client/ClusterClient.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class ClusterClient(cluster: ClusterSpec) extends AutoCloseable with Logging {
4242
val replicaSpec = shuffle(shardSpec.replicas.toSeq).head
4343
(shardSpec.num, replicaSpec.num)
4444
case _ => throw CHClientException(
45-
s"Invalid shard[${shard.orNull}] replica[${replica.orNull}] of cluster ${cluster.name}"
46-
)
45+
s"Invalid shard[${shard.orNull}] replica[${replica.orNull}] of cluster ${cluster.name}"
46+
)
4747
}
4848

4949
cache.computeIfAbsent(

clickhouse-core/src/main/scala/xenon/clickhouse/parse/AstVisitor.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,21 @@ class AstVisitor extends ClickHouseSQLBaseVisitor[AnyRef] with Logging {
169169
TupleExpr(visitColumnExprList(ctx.columnExprList))
170170

171171
override def visitColumnExprPrecedence1(ctx: ColumnExprPrecedence1Context): FuncExpr = {
172-
val funcName = if (ctx.PERCENT != null) "remainder"
173-
else if (ctx.SLASH != null) "divide"
174-
else if (ctx.ASTERISK != null) "multiply"
175-
else throw new IllegalArgumentException(s"Invalid [ColumnExprPrecedence1] ${ctx.getText}")
172+
val funcName =
173+
if (ctx.PERCENT != null) "remainder"
174+
else if (ctx.SLASH != null) "divide"
175+
else if (ctx.ASTERISK != null) "multiply"
176+
else throw new IllegalArgumentException(s"Invalid [ColumnExprPrecedence1] ${ctx.getText}")
176177
val funArgs = List(visitColumnExpr(ctx.columnExpr(0)), visitColumnExpr(ctx.columnExpr(1)))
177178
FuncExpr(funcName, funArgs)
178179
}
179180

180181
override def visitColumnExprPrecedence2(ctx: ColumnExprPrecedence2Context): FuncExpr = {
181-
val funcName = if (ctx.PLUS != null) "add"
182-
else if (ctx.DASH != null) "subtract"
183-
else if (ctx.CONCAT != null) "concat"
184-
else throw new IllegalArgumentException(s"Invalid [ColumnExprPrecedence2] ${ctx.getText}")
182+
val funcName =
183+
if (ctx.PLUS != null) "add"
184+
else if (ctx.DASH != null) "subtract"
185+
else if (ctx.CONCAT != null) "concat"
186+
else throw new IllegalArgumentException(s"Invalid [ColumnExprPrecedence2] ${ctx.getText}")
185187
val funArgs = List(visitColumnExpr(ctx.columnExpr(0)), visitColumnExpr(ctx.columnExpr(1)))
186188
FuncExpr(funcName, funArgs)
187189
}

clickhouse-core/src/main/scala/xenon/clickhouse/parse/SQLParser.scala

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,22 @@ class SQLParser(astVisitor: AstVisitor) extends Logging {
4242
parser.removeErrorListeners()
4343
parser.addErrorListener(ParseErrorListener)
4444

45-
try try {
46-
// first, try parsing with potentially faster SLL mode
47-
parser.getInterpreter.setPredictionMode(PredictionMode.SLL)
48-
toResult(parser)
49-
} catch {
50-
case _: ParseCancellationException =>
51-
// if we fail, parse with LL mode
52-
tokenStream.seek(0) // rewind input stream
53-
parser.reset()
54-
55-
// Try Again.
56-
parser.getInterpreter.setPredictionMode(PredictionMode.LL)
45+
try
46+
try {
47+
// first, try parsing with potentially faster SLL mode
48+
parser.getInterpreter.setPredictionMode(PredictionMode.SLL)
5749
toResult(parser)
58-
} catch {
50+
} catch {
51+
case _: ParseCancellationException =>
52+
// if we fail, parse with LL mode
53+
tokenStream.seek(0) // rewind input stream
54+
parser.reset()
55+
56+
// Try Again.
57+
parser.getInterpreter.setPredictionMode(PredictionMode.LL)
58+
toResult(parser)
59+
}
60+
catch {
5961
case rethrow: ParseException => throw rethrow
6062
}
6163
}

dev/reformat

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
set -x
17+
18+
PROJECT_DIR="$(cd "`dirname "$0"`/.."; pwd)"
19+
${PROJECT_DIR}/gradlew spotlessApply

spark-3.3/clickhouse-spark-it/src/test/scala/org/apache/spark/sql/clickhouse/SparkTest.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ trait SparkTest extends QueryTest with SharedSparkSession {
4545
spark.sql(s"CREATE DATABASE IF NOT EXISTS `$database`")
4646
block(database, table)
4747
} finally if (cleanup) {
48-
spark.sql(s"DROP TABLE IF EXISTS `$database`.`$table`")
49-
spark.sql(s"DROP DATABASE IF EXISTS `$database` CASCADE")
50-
}
48+
spark.sql(s"DROP TABLE IF EXISTS `$database`.`$table`")
49+
spark.sql(s"DROP DATABASE IF EXISTS `$database` CASCADE")
50+
}
5151

5252
def withClickHouseSingleIdTable(
5353
database: String,

0 commit comments

Comments
 (0)