From 385866715f31ea4957315950a35990233920f50c Mon Sep 17 00:00:00 2001 From: Ian Streeter Date: Wed, 18 Sep 2024 09:44:17 +0100 Subject: [PATCH] Fix startup on missing existing table During startup, the loader tries to fetch details of an existing table. It only creates a new table if the previous table does not exist. But this was broken because we were not properly checking the response returned from BigQuery when fetching table details. If a table does not exist then the client returns a null, but does not throw an exception. --- .../processing/TableManager.scala | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/core/src/main/scala/com.snowplowanalytics.snowplow.bigquery/processing/TableManager.scala b/modules/core/src/main/scala/com.snowplowanalytics.snowplow.bigquery/processing/TableManager.scala index b541cdf5..b1275432 100644 --- a/modules/core/src/main/scala/com.snowplowanalytics.snowplow.bigquery/processing/TableManager.scala +++ b/modules/core/src/main/scala/com.snowplowanalytics.snowplow.bigquery/processing/TableManager.scala @@ -140,9 +140,14 @@ object TableManager { def tableExists: F[Boolean] = for { _ <- Logger[F].info(s"Attempting to fetch details of table ${config.dataset}.${config.table}...") - _ <- Sync[F].blocking(client.getTable(config.dataset, config.table)) - _ <- Logger[F].info("Successfully fetched details of table") - } yield true + attempt <- Sync[F].blocking(Option(client.getTable(config.dataset, config.table))) + result <- attempt match { + case Some(_) => + Logger[F].info("Successfully fetched details of table").as(true) + case None => + Logger[F].info("Tried to fetch details of existing table but it does not already exist").as(false) + } + } yield result def createTable: F[Unit] = { val tableInfo = atomicTableInfo(config)