Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bigquery): export HivePartitioningOptions in load job configurations #3877

Merged
merged 6 commits into from Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions bigquery/load.go
Expand Up @@ -65,6 +65,10 @@ type LoadConfig struct {
// For ingestion from datastore backups, ProjectionFields governs which fields
// are projected from the backup. The default behavior projects all fields.
ProjectionFields []string

// HivePartitioningOptions allows use of Hive partitioning based on the
// layout of objects in Google Cloud Storage.
shollyman marked this conversation as resolved.
Show resolved Hide resolved
HivePartitioningOptions *HivePartitioningOptions
}

func (l *LoadConfig) toBQ() (*bq.JobConfiguration, io.Reader) {
Expand All @@ -83,6 +87,9 @@ func (l *LoadConfig) toBQ() (*bq.JobConfiguration, io.Reader) {
ProjectionFields: l.ProjectionFields,
},
}
if l.HivePartitioningOptions != nil {
config.Load.HivePartitioningOptions = l.HivePartitioningOptions.toBQ()
shollyman marked this conversation as resolved.
Show resolved Hide resolved
}
media := l.Src.populateLoadConfig(config.Load)
return config, media
}
Expand Down Expand Up @@ -111,6 +118,9 @@ func bqToLoadConfig(q *bq.JobConfiguration, c *Client) *LoadConfig {
fc = &s.FileConfig
lc.Src = s
}
if q.Load.HivePartitioningOptions != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this still needs an update?

lc.HivePartitioningOptions = bqToHivePartitioningOptions(q.Load.HivePartitioningOptions)
}
bqPopulateFileConfig(q.Load, fc)
return lc
}
Expand Down
25 changes: 25 additions & 0 deletions bigquery/load_test.go
Expand Up @@ -342,6 +342,31 @@ func TestLoad(t *testing.T) {
return j
}(),
},
{
dst: c.Dataset("dataset-id").Table("table-id"),
src: func() *GCSReference {
g := NewGCSReference("uri")
g.SourceFormat = Parquet
return g
}(),
config: LoadConfig{
HivePartitioningOptions: &HivePartitioningOptions{
Mode: CustomHivePartitioningMode,
SourceURIPrefix: "source_uri",
RequirePartitionFilter: true,
},
},
want: func() *bq.Job {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯

This took me a second.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have no idea how much I wish we weren't in the business of mapping back and forth to discovery representations for complex resources like job configs.

j := defaultLoadJob()
j.Configuration.Load.SourceFormat = "PARQUET"
j.Configuration.Load.HivePartitioningOptions = &bq.HivePartitioningOptions{
Mode: "CUSTOM",
RequirePartitionFilter: true,
SourceUriPrefix: "source_uri",
}
return j
}(),
},
}

for i, tc := range testCases {
Expand Down