Skip to content

Commit 132904a

Browse files
authored
feat(bigquery): support null marker for csv in external data config (#5287)
1 parent b1cf7f0 commit 132904a

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

Diff for: bigquery/external.go

+6
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ type CSVOptions struct {
219219
// The number of rows at the top of a CSV file that BigQuery will skip when
220220
// reading data.
221221
SkipLeadingRows int64
222+
223+
// An optional custom string that will represent a NULL
224+
// value in CSV import data.
225+
NullMarker string
222226
}
223227

224228
func (o *CSVOptions) populateExternalDataConfig(c *bq.ExternalDataConfiguration) {
@@ -229,6 +233,7 @@ func (o *CSVOptions) populateExternalDataConfig(c *bq.ExternalDataConfiguration)
229233
FieldDelimiter: o.FieldDelimiter,
230234
Quote: o.quote(),
231235
SkipLeadingRows: o.SkipLeadingRows,
236+
NullMarker: o.NullMarker,
232237
}
233238
}
234239

@@ -260,6 +265,7 @@ func bqToCSVOptions(q *bq.CsvOptions) *CSVOptions {
260265
Encoding: Encoding(q.Encoding),
261266
FieldDelimiter: q.FieldDelimiter,
262267
SkipLeadingRows: q.SkipLeadingRows,
268+
NullMarker: q.NullMarker,
263269
}
264270
o.setQuote(q.Quote)
265271
return o

Diff for: bigquery/external_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func TestExternalDataConfig(t *testing.T) {
3939
FieldDelimiter: "f",
4040
Quote: "q",
4141
SkipLeadingRows: 3,
42+
NullMarker: "marker",
4243
},
4344
},
4445
{

Diff for: bigquery/file.go

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func (fc *FileConfig) populateLoadConfig(conf *bq.JobConfigurationLoad) {
9292
conf.FieldDelimiter = fc.FieldDelimiter
9393
conf.IgnoreUnknownValues = fc.IgnoreUnknownValues
9494
conf.MaxBadRecords = fc.MaxBadRecords
95+
conf.NullMarker = fc.NullMarker
9596
if fc.Schema != nil {
9697
conf.Schema = fc.Schema.toBQ()
9798
}
@@ -118,6 +119,7 @@ func bqPopulateFileConfig(conf *bq.JobConfigurationLoad, fc *FileConfig) {
118119
fc.AllowQuotedNewlines = conf.AllowQuotedNewlines
119120
fc.Encoding = Encoding(conf.Encoding)
120121
fc.FieldDelimiter = conf.FieldDelimiter
122+
fc.CSVOptions.NullMarker = conf.NullMarker
121123
fc.CSVOptions.setQuote(conf.Quote)
122124
}
123125

Diff for: bigquery/file_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var (
3939
AllowJaggedRows: true,
4040
AllowQuotedNewlines: true,
4141
Encoding: UTF_8,
42+
NullMarker: "marker",
4243
},
4344
}
4445
)
@@ -71,6 +72,7 @@ func TestFileConfigPopulateLoadConfig(t *testing.T) {
7172
Encoding: "UTF-8",
7273
MaxBadRecords: 7,
7374
IgnoreUnknownValues: true,
75+
NullMarker: "marker",
7476
Schema: &bq.TableSchema{
7577
Fields: []*bq.TableFieldSchema{
7678
bqStringFieldSchema(),
@@ -154,6 +156,7 @@ func TestFileConfigPopulateExternalDataConfig(t *testing.T) {
154156
FieldDelimiter: "\t",
155157
Quote: &hyphen,
156158
SkipLeadingRows: 8,
159+
NullMarker: "marker",
157160
},
158161
},
159162
},

0 commit comments

Comments
 (0)