From 2108647589c3fe6e654cc91f51d959eb089b2684 Mon Sep 17 00:00:00 2001 From: Nathan <148575555+nathan-artie@users.noreply.github.com> Date: Mon, 22 Apr 2024 21:56:38 -0700 Subject: [PATCH] [bigquery] Log if table name/dataset differ from expected (#490) --- clients/bigquery/bigquery.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/clients/bigquery/bigquery.go b/clients/bigquery/bigquery.go index bc668c724..5de18e30f 100644 --- a/clients/bigquery/bigquery.go +++ b/clients/bigquery/bigquery.go @@ -134,14 +134,35 @@ func tableRelName(fqName string) (string, error) { } func (s *Store) putTable(ctx context.Context, dataset string, tableID types.TableIdentifier, rows []*Row) error { - // TODO: [tableID] has [Dataset] on it, don't need to pass it along. + bqTableID, ok := tableID.(TableIdentifier) + if !ok { + return fmt.Errorf("unable to cast tableID to BigQuery TableIdentifier") + } + tableName := tableID.FullyQualifiedName() - // TODO: Can probably do `tableName := tableID.Table()` here. relTableName, err := tableRelName(tableName) if err != nil { return fmt.Errorf("failed to get table name: %w", err) } + if dataset != bqTableID.Dataset() { + // TODO: [tableID] has [Dataset] on it, don't need to pass it along. + slog.Error("BigQuery dataset is different", + slog.String("dataset", dataset), + slog.String("bqTableID.Dataset", bqTableID.Dataset()), + slog.String("fqn", tableName), + ) + } + + if relTableName != bqTableID.Table() { + // TODO: Use [bqTableID.Table] instead of [relTableName]. + slog.Error("BigQuery table name is different", + slog.String("relTableName", relTableName), + slog.String("bqTableID.Table", bqTableID.Table()), + slog.String("fqn", tableName), + ) + } + client := s.GetClient(ctx) defer client.Close()