Skip to content

Commit

Permalink
Fix startup on missing existing table (#384)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
istreeter authored Sep 18, 2024
1 parent 5d5d7f5 commit 91594ba
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 91594ba

Please sign in to comment.