Skip to content

Commit

Permalink
fix loadTable method
Browse files Browse the repository at this point in the history
  • Loading branch information
mzitnik committed Jul 10, 2024
1 parent bda4426 commit 2cd19f3
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 2cd19f3

Please sign in to comment.