From ae9863ec1f138c290bcad79f86e16286bd32339f Mon Sep 17 00:00:00 2001 From: Nathan Villaescusa Date: Mon, 22 Apr 2024 21:46:09 -0700 Subject: [PATCH 1/3] [bigquery] Log if table name/dataset differ from expected --- 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..efbb192d6 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 types.TableIdentifier 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 [tableID.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() From ff3c75d30bc8e4a78fddec203584de3e1fc6780f Mon Sep 17 00:00:00 2001 From: Nathan Villaescusa Date: Mon, 22 Apr 2024 21:47:26 -0700 Subject: [PATCH 2/3] Change --- clients/bigquery/bigquery.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/bigquery/bigquery.go b/clients/bigquery/bigquery.go index efbb192d6..3856b0bd5 100644 --- a/clients/bigquery/bigquery.go +++ b/clients/bigquery/bigquery.go @@ -136,7 +136,7 @@ func tableRelName(fqName string) (string, error) { func (s *Store) putTable(ctx context.Context, dataset string, tableID types.TableIdentifier, rows []*Row) error { bqTableID, ok := tableID.(TableIdentifier) if !ok { - return fmt.Errorf("unable to cast types.TableIdentifier to BigQuery TableIdentifier") + return fmt.Errorf("unable to cast tableID to BigQuery TableIdentifier") } tableName := tableID.FullyQualifiedName() From c8ff308d8e304c461c8bbb7306de1e41548f6f52 Mon Sep 17 00:00:00 2001 From: Nathan Villaescusa Date: Mon, 22 Apr 2024 21:49:11 -0700 Subject: [PATCH 3/3] Update --- clients/bigquery/bigquery.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/bigquery/bigquery.go b/clients/bigquery/bigquery.go index 3856b0bd5..5de18e30f 100644 --- a/clients/bigquery/bigquery.go +++ b/clients/bigquery/bigquery.go @@ -155,7 +155,7 @@ func (s *Store) putTable(ctx context.Context, dataset string, tableID types.Tabl } if relTableName != bqTableID.Table() { - // TODO: Use [tableID.Table] instead of [relTableName]. + // TODO: Use [bqTableID.Table] instead of [relTableName]. slog.Error("BigQuery table name is different", slog.String("relTableName", relTableName), slog.String("bqTableID.Table", bqTableID.Table()),