Skip to content

Commit

Permalink
bigquery: restore semantics of ForceZeroQuote
Browse files Browse the repository at this point in the history
Originally, ForceZeroQuote == true was sufficient to set the
quote character for CSV loading to '"'. on 2016-9-27, the logic
was modified incorrectly, so that both ForceZeroQuote == true and Quote
== "" were necessary. This CL restores the original semantics.

Change-Id: I790a5567085255f37064a38f8623109128c4a7f5
Reviewed-on: https://code-review.googlesource.com/8995
Reviewed-by: Michael McGreevy <[email protected]>
  • Loading branch information
jba committed Oct 31, 2016
1 parent f7f94a2 commit 7ee19e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions bigquery/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,19 @@ type FileConfig struct {
// default quotation character is the double quote ("), which is used if
// both Quote and ForceZeroQuote are unset.
// To specify that no character should be interpreted as a quotation
// character, set ForceZeroQuote to true and leave Quote unset.
// character, set ForceZeroQuote to true.
// Only used when reading data.
Quote string
ForceZeroQuote bool
}

// quote returns the CSV quote character, or nil if unset.
func (fc *FileConfig) quote() *string {
if !fc.ForceZeroQuote && fc.Quote == "" {
if fc.ForceZeroQuote {
quote := ""
return &quote
}
if fc.Quote == "" {
return nil
}
return &fc.Quote
Expand Down
4 changes: 2 additions & 2 deletions bigquery/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestQuote(t *testing.T) {
{"", false, nil},
{"", true, ptr("")},
{"-", false, ptr("-")},
{"-", true, ptr("-")}, // force ignored if quote is non-nil
{"-", true, ptr("")},
} {
fc := FileConfig{
Quote: test.quote,
Expand All @@ -44,7 +44,7 @@ func TestQuote(t *testing.T) {
t.Errorf("%+v\ngot %v\nwant %v", test, pretty.Value(got), pretty.Value(test.want))
}
if got != nil && test.want != nil && *got != *test.want {
t.Errorf("%+v: got %q, want %q", test, got, test.want)
t.Errorf("%+v: got %q, want %q", test, *got, *test.want)
}
}
}
Expand Down

0 comments on commit 7ee19e7

Please sign in to comment.