Skip to content

Commit 631d235

Browse files
committed
Replace println with proper SLF4J logging in test fixtures
- Added Logging trait to ClickHouseSingleMixIn - Replaced all println statements with log.info() calls - Provides structured, filterable logging for test execution - Maintains test output visibility while enabling proper log management
1 parent 6ec7406 commit 631d235

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

clickhouse-core/src/testFixtures/scala/com/clickhouse/spark/base/ClickHouseSingleMixIn.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ import com.clickhouse.data.ClickHouseVersion
1919
import com.dimafeng.testcontainers.{ForAllTestContainer, JdbcDatabaseContainer, SingleContainer}
2020
import org.scalatest.BeforeAndAfterAll
2121
import org.scalatest.funsuite.AnyFunSuite
22+
import org.slf4j.LoggerFactory
2223
import org.testcontainers.containers.ClickHouseContainer
2324
import org.testcontainers.utility.{DockerImageName, MountableFile}
2425
import java.nio.file.{Path, Paths}
2526
import scala.collection.JavaConverters._
2627

2728
trait ClickHouseSingleMixIn extends AnyFunSuite with BeforeAndAfterAll with ForAllTestContainer
2829
with ClickHouseProvider {
30+
31+
private val logger = LoggerFactory.getLogger(getClass)
2932
// format: off
3033
private val CLICKHOUSE_IMAGE: String = Utils.load("CLICKHOUSE_IMAGE", "clickhouse/clickhouse-server:23.8")
3134
private val CLICKHOUSE_USER: String = Utils.load("CLICKHOUSE_USER", "default")
@@ -36,7 +39,7 @@ trait ClickHouseSingleMixIn extends AnyFunSuite with BeforeAndAfterAll with ForA
3639
private val CLICKHOUSE_TPC_PORT = 9000
3740
// format: on
3841

39-
println(s"[ClickHouseSingleMixIn] Initializing with ClickHouse image: $CLICKHOUSE_IMAGE")
42+
logger.info(s"Initializing with ClickHouse image: $CLICKHOUSE_IMAGE")
4043

4144
override val clickhouseVersion: ClickHouseVersion = ClickHouseVersion.of(CLICKHOUSE_IMAGE.split(":").last)
4245

@@ -87,17 +90,17 @@ trait ClickHouseSingleMixIn extends AnyFunSuite with BeforeAndAfterAll with ForA
8790

8891
override def beforeAll(): Unit = {
8992
val startTime = System.currentTimeMillis()
90-
println(s"[ClickHouseSingleMixIn] Starting ClickHouse container: $CLICKHOUSE_IMAGE")
93+
logger.info(s"Starting ClickHouse container: $CLICKHOUSE_IMAGE")
9194
super.beforeAll() // This starts the container and makes mappedPort available
9295
val duration = System.currentTimeMillis() - startTime
93-
println(
94-
s"[ClickHouseSingleMixIn] ClickHouse container started in ${duration}ms at ${container.host}:${container.mappedPort(CLICKHOUSE_HTTP_PORT)}"
96+
logger.info(
97+
s"ClickHouse container started in ${duration}ms at ${container.host}:${container.mappedPort(CLICKHOUSE_HTTP_PORT)}"
9598
)
9699
}
97100

98101
override def afterAll(): Unit = {
99-
println(s"[ClickHouseSingleMixIn] Stopping ClickHouse container")
102+
logger.info("Stopping ClickHouse container")
100103
super.afterAll()
101-
println(s"[ClickHouseSingleMixIn] ClickHouse container stopped")
104+
logger.info("ClickHouse container stopped")
102105
}
103106
}

spark-4.0/clickhouse-spark/src/main/scala/com/clickhouse/spark/ClickHouseCatalog.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class ClickHouseCatalog extends TableCatalog
109109
case Array(database) =>
110110
nodeClient.syncQueryOutputJSONEachRow(s"SHOW TABLES IN ${quoted(database)}") match {
111111
case Left(exception) if exception.code == UNKNOWN_DATABASE.code =>
112-
throw new NoSuchNamespaceException(namespace.mkString("."))
112+
throw new NoSuchNamespaceException(namespace)
113113
case Left(rethrow) =>
114114
throw rethrow
115115
case Right(output) =>
@@ -118,7 +118,7 @@ class ClickHouseCatalog extends TableCatalog
118118
.map(table => Identifier.of(namespace, table))
119119
.toArray
120120
}
121-
case _ => throw new NoSuchNamespaceException(namespace.mkString("."))
121+
case _ => throw new NoSuchNamespaceException(namespace)
122122
}
123123

124124
@throws[NoSuchTableException]
@@ -131,7 +131,7 @@ class ClickHouseCatalog extends TableCatalog
131131
throw new NoSuchTableException(ident)
132132
// not sure if this check is necessary
133133
case Left(exception) if exception.code == UNKNOWN_DATABASE.code =>
134-
throw new NoSuchTableException(s"Database $db does not exist")
134+
throw new NoSuchTableException(Array(db))
135135
case Left(rethrow) =>
136136
throw rethrow
137137
case Right(_) => (db, tbl)
@@ -323,7 +323,11 @@ class ClickHouseCatalog extends TableCatalog
323323
(unwrap(oldIdent), unwrap(newIdent)) match {
324324
case (Some((oldDb, oldTbl)), Some((newDb, newTbl))) =>
325325
nodeClient.syncQueryOutputJSONEachRow(s"RENAME TABLE `$oldDb`.`$oldTbl` to `$newDb`.`$newTbl`") match {
326-
case Left(exception) => throw new NoSuchTableException(exception.getMessage, Some(exception))
326+
case Left(exception) => throw new NoSuchTableException(
327+
errorClass = "TABLE_OR_VIEW_NOT_FOUND",
328+
messageParameters = Map("relationName" -> oldIdent.toString),
329+
cause = Some(exception)
330+
)
327331
case Right(_) =>
328332
}
329333
case _ => throw CHClientException("Invalid table identifier")
@@ -343,13 +347,13 @@ class ClickHouseCatalog extends TableCatalog
343347
case Array(_) =>
344348
loadNamespaceMetadata(namespace)
345349
Array()
346-
case _ => throw new NoSuchNamespaceException(namespace.map(quoted).mkString("."))
350+
case _ => throw new NoSuchNamespaceException(namespace)
347351
}
348352

349353
@throws[NoSuchNamespaceException]
350354
override def loadNamespaceMetadata(namespace: Array[String]): util.Map[String, String] = namespace match {
351355
case Array(database) => queryDatabaseSpec(database).toJavaMap
352-
case _ => throw new NoSuchNamespaceException(namespace.map(quoted).mkString("."))
356+
case _ => throw new NoSuchNamespaceException(namespace)
353357
}
354358

355359
@throws[NamespaceAlreadyExistsException]

spark-4.0/clickhouse-spark/src/main/scala/com/clickhouse/spark/ClickHouseHelper.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ import scala.collection.JavaConverters._
4545
trait ClickHouseHelper extends Logging {
4646

4747
@volatile lazy val DEFAULT_ACTION_IF_NO_SUCH_DATABASE: String => Unit =
48-
(db: String) => throw new NoSuchNamespaceException(db)
48+
(db: String) => throw new NoSuchNamespaceException(Array(db))
4949

5050
@volatile lazy val DEFAULT_ACTION_IF_NO_SUCH_TABLE: (String, String) => Unit =
51-
(database, table) => throw new NoSuchTableException(s"$database.$table")
51+
(database, table) => throw new NoSuchTableException(database, table)
5252

5353
def unwrap(ident: Identifier): Option[(String, String)] = ident.namespace() match {
5454
case Array(database) => Some((database, ident.name()))

0 commit comments

Comments
 (0)