Skip to content

Commit

Permalink
feat(bigquery): support null marker for csv in external data config (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shollyman committed Jan 6, 2022
1 parent b1cf7f0 commit 132904a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bigquery/external.go
Expand Up @@ -219,6 +219,10 @@ type CSVOptions struct {
// The number of rows at the top of a CSV file that BigQuery will skip when
// reading data.
SkipLeadingRows int64

// An optional custom string that will represent a NULL
// value in CSV import data.
NullMarker string
}

func (o *CSVOptions) populateExternalDataConfig(c *bq.ExternalDataConfiguration) {
Expand All @@ -229,6 +233,7 @@ func (o *CSVOptions) populateExternalDataConfig(c *bq.ExternalDataConfiguration)
FieldDelimiter: o.FieldDelimiter,
Quote: o.quote(),
SkipLeadingRows: o.SkipLeadingRows,
NullMarker: o.NullMarker,
}
}

Expand Down Expand Up @@ -260,6 +265,7 @@ func bqToCSVOptions(q *bq.CsvOptions) *CSVOptions {
Encoding: Encoding(q.Encoding),
FieldDelimiter: q.FieldDelimiter,
SkipLeadingRows: q.SkipLeadingRows,
NullMarker: q.NullMarker,
}
o.setQuote(q.Quote)
return o
Expand Down
1 change: 1 addition & 0 deletions bigquery/external_test.go
Expand Up @@ -39,6 +39,7 @@ func TestExternalDataConfig(t *testing.T) {
FieldDelimiter: "f",
Quote: "q",
SkipLeadingRows: 3,
NullMarker: "marker",
},
},
{
Expand Down
2 changes: 2 additions & 0 deletions bigquery/file.go
Expand Up @@ -92,6 +92,7 @@ func (fc *FileConfig) populateLoadConfig(conf *bq.JobConfigurationLoad) {
conf.FieldDelimiter = fc.FieldDelimiter
conf.IgnoreUnknownValues = fc.IgnoreUnknownValues
conf.MaxBadRecords = fc.MaxBadRecords
conf.NullMarker = fc.NullMarker
if fc.Schema != nil {
conf.Schema = fc.Schema.toBQ()
}
Expand All @@ -118,6 +119,7 @@ func bqPopulateFileConfig(conf *bq.JobConfigurationLoad, fc *FileConfig) {
fc.AllowQuotedNewlines = conf.AllowQuotedNewlines
fc.Encoding = Encoding(conf.Encoding)
fc.FieldDelimiter = conf.FieldDelimiter
fc.CSVOptions.NullMarker = conf.NullMarker
fc.CSVOptions.setQuote(conf.Quote)
}

Expand Down
3 changes: 3 additions & 0 deletions bigquery/file_test.go
Expand Up @@ -39,6 +39,7 @@ var (
AllowJaggedRows: true,
AllowQuotedNewlines: true,
Encoding: UTF_8,
NullMarker: "marker",
},
}
)
Expand Down Expand Up @@ -71,6 +72,7 @@ func TestFileConfigPopulateLoadConfig(t *testing.T) {
Encoding: "UTF-8",
MaxBadRecords: 7,
IgnoreUnknownValues: true,
NullMarker: "marker",
Schema: &bq.TableSchema{
Fields: []*bq.TableFieldSchema{
bqStringFieldSchema(),
Expand Down Expand Up @@ -154,6 +156,7 @@ func TestFileConfigPopulateExternalDataConfig(t *testing.T) {
FieldDelimiter: "\t",
Quote: &hyphen,
SkipLeadingRows: 8,
NullMarker: "marker",
},
},
},
Expand Down

0 comments on commit 132904a

Please sign in to comment.