Google-cloud-go: BigQuery: job.Config() panics when query parameter is bound to the empty string

Created on 19 Dec 2018  路  3Comments  路  Source: googleapis/google-cloud-go

Client

BigQuery

Describe Your Environment

At Google (CloudTop)

Expected Behavior

job.Config() should never panic.

Actual Behavior

job.Config() panics when a query parameter is set to the empty string, because the QueryParameter from BigQuery has a nil in the ParameterValue field:

runtime: running GoogleExitFunction

goroutine 1 [running]:
google3/third_party/golang/cloud/bigquery/bigquery.convertParamValue(0x0, 0xc00007f5c0, 0xc0003a3b98, 0x523a58, 0x40, 0xaac7e0)
    third_party/golang/cloud/bigquery/params.go:312 +0x25c
google3/third_party/golang/cloud/bigquery/bigquery.bqToQueryParameter(0xc0004f6370, 0xc000034400, 0xc0003a3c60, 0x0, 0x88, 0x98, 0xc000534320)
    third_party/golang/cloud/bigquery/params.go:275 +0x4d
google3/third_party/golang/cloud/bigquery/bigquery.bqToQueryConfig(0xc0001f8380, 0xc00000cb80, 0xba3960, 0xc000022110, 0xc0000343c0)
    third_party/golang/cloud/bigquery/query.go:229 +0x422
google3/third_party/golang/cloud/bigquery/bigquery.bqToJobConfig(0xc0001f8380, 0xc00000cb80, 0x0, 0xc0004dc400, 0x0, 0x0)
    third_party/golang/cloud/bigquery/job.go:110 +0x67
google3/third_party/golang/cloud/bigquery/bigquery.(*Job).Config(0xc0004dc400, 0xba3960, 0xc000022110, 0xc0000343c0, 0x0)
    third_party/golang/cloud/bigquery/job.go:96 +0x37
main.main()
    experimental/users/ammons/nil_query_parameter/main.go:43 +0x410

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x99d6cc]

To reproduce, run a query with a query parameter that's set to the empty string:

q := bq.Query(`SELECT x FROM UNNEST(["", "foo"]) AS x WHERE x = @foo`)
q.Parameters = []bigquery.QueryParameter{
    {Name: "foo", Value: ""},
}
job, err := q.Run(ctx)
if err != nil {
    log.Exitf("q.Run(_) failed: %v", err)
}
s, err := job.Wait(ctx)
if err != nil {
    log.Exitf("job.Wait(_) failed: %v", err)
}
if err := s.Err(); err != nil {
    log.Exitf("Status from job.Wait(_) had an error: %v", err)
}
    <the next line panics>
c, err := job.Config()
bigquery p2 bug

Most helpful comment

A little more information: I have also noticed that the client will return the wrong results for empty-string query parameters, because parameterValue is not set on the request.

You can verify this by inspecting bq show --format=prettyjson -j <job ID>. It will have

{
    "name": "foo",
    "parameterType": {
        "type": "STRING"
    },
},

instead of the expected

{
    "name": "foo",
    "parameterType": {
        "type": "STRING"
    },
    "parameterValue": {
        "value": ""
     }
},

And BigQuery treats the two differently (I guess the former means that the parameter is NULL). The bq command-line produces the expected result.

All 3 comments

A little more information: I have also noticed that the client will return the wrong results for empty-string query parameters, because parameterValue is not set on the request.

You can verify this by inspecting bq show --format=prettyjson -j <job ID>. It will have

{
    "name": "foo",
    "parameterType": {
        "type": "STRING"
    },
},

instead of the expected

{
    "name": "foo",
    "parameterType": {
        "type": "STRING"
    },
    "parameterValue": {
        "value": ""
     }
},

And BigQuery treats the two differently (I guess the former means that the parameter is NULL). The bq command-line produces the expected result.

I'm also encountering the same issue.

@tomoemon Please file a new bug, since this one is quite old.

Was this page helpful?
0 / 5 - 0 ratings