Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bigquery: Support math/big.Int as parameter type #4703

Closed
Thomasdezeeuw opened this issue Aug 31, 2021 · 5 comments
Closed

bigquery: Support math/big.Int as parameter type #4703

Thomasdezeeuw opened this issue Aug 31, 2021 · 5 comments
Assignees
Labels
api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@Thomasdezeeuw
Copy link

I'm using QueryParameter to send parameters along with my query. On the BigQuery side I'm using BIGNUMERIC(32) (no precision, i.e. an integer) as type. Normally you would use int64 as type, however my input doesn't fit in 64 bits. I tried using big.Rat but BigQuery doesn't allow silent truncation (and rightfully so).

Go has nice package for large numbers: math/big, which is already partially support through big.Rat. However big.Int doesn't seem to be supported. Is it possible for this client to support big.Int? I'm will to give it a go if it's an acceptable change (and someone can point into the right direction w.r.t. the code).

@Thomasdezeeuw Thomasdezeeuw added the triage me I really want to be triaged. label Aug 31, 2021
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the BigQuery API. label Aug 31, 2021
@shollyman
Copy link
Contributor

I'll need to look at this. The issue is we try to determine the bigquery type from the go type. Clearly we need to consider another mechanism for the user to explicitly provide the destination BQ type.

@shollyman shollyman added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed triage me I really want to be triaged. labels Sep 13, 2021
@Thomasdezeeuw
Copy link
Author

@shollyman maybe this should be another issue, but I would also be happy to provide/receive the value as a string as send to/returned by BigQuery (as I assume underneath it's all HTTP anyway, right?). I know it doesn't really fit the current API, but could that be a (future) possibility?

@alvarowolfx
Copy link
Contributor

alvarowolfx commented Oct 10, 2022

@Thomasdezeeuw recently we merged some work to add support for explicit typed query parameters. Although right now you can't pass a big.Int directly, you can convert it to a string and explicitly inform the type. Here is an example:

ctx := context.Background()
client, err := bigquery.NewClient(ctx, "project-id")
if err != nil {
	// TODO: Handle error.
}
bigIntParam := big.NewInt(1234567890123456789)
q := client.Query("select name, price from product where price > @bigint")
q.Parameters = []bigquery.QueryParameter{
	{
		Name: "bigint", 
		Value: &QueryParameterValue{
			Type: StandardSQLDataType{
				TypeKind: "BIGNUMERIC",
			},
			Value: bigIntParam.String(),
		},
	},
}

Do you think this solves your issue ?

@Thomasdezeeuw
Copy link
Author

@alvarowolfx yes that works. We just switched to that API for #4704, I forgot to mention it here.

I'm ok with closing this issue.

@alvarowolfx
Copy link
Contributor

Awesome, thanks for the feedback @Thomasdezeeuw and I'm gonna close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

3 participants