Skip to content

Commit

Permalink
Replace invalid character - to _ in BigQuery Table ID (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
ginokent committed Jul 25, 2022
1 parent 6664d3d commit 229afd6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,18 @@ func generateImportPackagesCode(importPackages []string) (generatedCode string)
}

func generateTableSchemaCode(ctx context.Context, table *bigquery.Table) (generatedCode string, importPackages []string, err error) {
if len(table.TableID) == 0 {
tableID := table.TableID
if len(tableID) == 0 {
return "", nil, fmt.Errorf("*bigquery.Table.TableID is empty. *bigquery.Table struct dump: %#v", table)
}
structName := capitalizeInitial(table.TableID)

if strings.Contains(tableID, "-") {
replaced := strings.ReplaceAll(tableID, "-", "_")
warnln(fmt.Sprintf("tableID `%s` contains invalid character `-`. replacing `%s` to `%s`", tableID, tableID, replaced))
tableID = replaced
}

structName := capitalizeInitial(tableID)

var md *bigquery.TableMetadata
md, err = table.Metadata(ctx)
Expand Down

0 comments on commit 229afd6

Please sign in to comment.