googleapis / googleapis/google-cloud-go

bigquery: support constraints.Integer for QueryParameter

Open
#8,662 0 comments 1 reaction 2 assignees Claimed by @alvarowolfx View on GitHub
api: bigquery priority: p3 type: feature request
Dominant language
Go
Stars
4.5k
Forks
1.6k
Avg merge
1d 13h
Merged PRs (30d)
109

Description

**Is your feature request related to a problem? Please describe.**
When passing in a slice of query params, if you have a typed integer (in my case now a proto enum), BigQuery rejects the query as invalid for an Int64 field. e.g.

```go

type IntType int32

bigquery.QueryParam{
Name: "int_filter",
Value: []IntType{1, 2, 3}
}
```

**Describe the solution you'd like**
Now that generics are out and available in all supported Go versions, it should be trivial to transparently support variations with `constraints.Integer`. If you wanted to be extra careful, you could write your own version of the constraint to exclude `uint64` to prevent truly unsupported values through.

**Describe alternatives you've considered**
We're manually converting slices ourselves now.
```go
func toInt64Slice[E constraints.Integer](s []E) []int64 {
vals := make([]int64, len(s))
for i, v := range s {
vals[i] = int64(v)
}
return vals
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.