From 2cd19f3fe984674c0358d2b28af6eee1c2705400 Mon Sep 17 00:00:00 2001 From: mzitnik Date: Wed, 10 Jul 2024 15:18:51 +0300 Subject: [PATCH] fix loadTable method --- .../xenon/clickhouse/ClickHouseCatalog.scala | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/spark-3.5/clickhouse-spark/src/main/scala/xenon/clickhouse/ClickHouseCatalog.scala b/spark-3.5/clickhouse-spark/src/main/scala/xenon/clickhouse/ClickHouseCatalog.scala index 9698e823..dc9d1a84 100644 --- a/spark-3.5/clickhouse-spark/src/main/scala/xenon/clickhouse/ClickHouseCatalog.scala +++ b/spark-3.5/clickhouse-spark/src/main/scala/xenon/clickhouse/ClickHouseCatalog.scala @@ -118,15 +118,25 @@ class ClickHouseCatalog extends TableCatalog val (database, table) = unwrap(ident) match { case None => throw new NoSuchTableException(ident) case Some((db, tbl)) => +// println(s"loadTable: $db, $tbl") nodeClient.syncQueryOutputJSONEachRow(s"SELECT * FROM `$db`.`$tbl` WHERE 1=0") match { - case Left(exception) if exception.code == UNKNOWN_TABLE.code => + case Left(exception) + if exception.code == UNKNOWN_TABLE.code => throw new NoSuchTableException(ident) // not sure if this check is necessary case Left(exception) if exception.code == UNKNOWN_DATABASE.code => throw new NoSuchTableException(s"Database $db does not exist") - case Left(rethrow) => + case Left (exception) if (exception.toString.indexOf("Code: 60. DB::Exception: Unknown table") > 0) => + throw new NoSuchTableException(ident) + case Left(rethrow) => { + val x : Int = rethrow.code +// println(s"loadTable error: $db, $tbl, $x, ($rethrow.code), [$rethrow]") throw rethrow - case Right(_) => (db, tbl) + } + case Right(_) => { +// println(s"loadTable: $db, $tbl, Right") + (db, tbl) + } } } implicit val _tz: ZoneId = tz.merge @@ -238,6 +248,7 @@ class ClickHouseCatalog extends TableCatalog table: String, settingsClause: String ): Unit = { + log.debug(s"createTable($clusterOpt, $engineExpr, $database, $table, $settingsClause)") val clusterClause = clusterOpt.map(c => s"ON CLUSTER $c").getOrElse("") nodeClient.syncQueryAndCheckOutputJSONEachRow( s"""CREATE TABLE `$database`.`$table` $clusterClause (