Skip to content

Commit

Permalink
feat(bigquery): support column name character map in load jobs (#10425)
Browse files Browse the repository at this point in the history
internal issue: b/346834574
  • Loading branch information
shollyman authored Jun 26, 2024
1 parent b95805f commit b829327
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions bigquery/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ type LoadConfig struct {

// MediaOptions stores options for customizing media upload.
MediaOptions []googleapi.MediaOption

// Controls the behavior of column naming during a load job.
// For more information, see:
// https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#columnnamecharactermap
ColumnNameCharacterMap ColumnNameCharacterMap
}

func (l *LoadConfig) toBQ() (*bq.JobConfiguration, io.Reader) {
Expand All @@ -124,6 +129,7 @@ func (l *LoadConfig) toBQ() (*bq.JobConfiguration, io.Reader) {
HivePartitioningOptions: l.HivePartitioningOptions.toBQ(),
ReferenceFileSchemaUri: l.ReferenceFileSchemaURI,
CreateSession: l.CreateSession,
ColumnNameCharacterMap: string(l.ColumnNameCharacterMap),
},
JobTimeoutMs: l.JobTimeout.Milliseconds(),
}
Expand Down Expand Up @@ -153,6 +159,7 @@ func bqToLoadConfig(q *bq.JobConfiguration, c *Client) *LoadConfig {
HivePartitioningOptions: bqToHivePartitioningOptions(q.Load.HivePartitioningOptions),
ReferenceFileSchemaURI: q.Load.ReferenceFileSchemaUri,
CreateSession: q.Load.CreateSession,
ColumnNameCharacterMap: ColumnNameCharacterMap(q.Load.ColumnNameCharacterMap),
}
if q.JobTimeoutMs > 0 {
lc.JobTimeout = time.Duration(q.JobTimeoutMs) * time.Millisecond
Expand Down Expand Up @@ -238,3 +245,24 @@ var (
// StringTargetType indicates the preferred type is STRING when supported.
StringTargetType DecimalTargetType = "STRING"
)

// ColumnNameCharacterMap is used to specific column naming behavior for load jobs.
type ColumnNameCharacterMap string

var (

// UnspecifiedColumnNameCharacterMap is the unspecified default value.
UnspecifiedColumnNameCharacterMap ColumnNameCharacterMap = "COLUMN_NAME_CHARACTER_MAP_UNSPECIFIED"

// StrictColumnNameCharacterMap indicates support for flexible column names.
// Invalid column names will be rejected.
StrictColumnNameCharacterMap ColumnNameCharacterMap = "STRICT"

// V1ColumnNameCharacterMap indicates support for alphanumeric + underscore characters and names must start with a letter or underscore.
// Invalid column names will be normalized.
V1ColumnNameCharacterMap ColumnNameCharacterMap = "V1"

// V2ColumnNameCharacterMap indicates support for flexible column names.
// Invalid column names will be normalized.
V2ColumnNameCharacterMap ColumnNameCharacterMap = "V2"
)
2 changes: 2 additions & 0 deletions bigquery/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ func TestLoad(t *testing.T) {
Value: "session_id_1234567890",
},
},
ColumnNameCharacterMap: StrictColumnNameCharacterMap,
},
want: func() *bq.Job {
j := defaultLoadJob()
Expand All @@ -429,6 +430,7 @@ func TestLoad(t *testing.T) {
Value: "session_id_1234567890",
},
}
j.Configuration.Load.ColumnNameCharacterMap = "STRICT"
return j
}(),
},
Expand Down

0 comments on commit b829327

Please sign in to comment.