-
Notifications
You must be signed in to change notification settings - Fork 41
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
Issue while converting nil
SQL parameter to null
#193
Comments
Hi @esdrasbeleza! Thank you for reporting this. Yes, NULL values need special handling (like it's done in Nodejs connector or in Python driver). However, seems that Go driver handles it differently (I'm not a Go expert and may be wrong, though). @andrefurlan-db can you please take a look? |
I tried to read the code for Node.js and Python and implement the same behaviour in Go. query := `SELECT * FROM my_table
WHERE ISNULL(:SOME_FIELD) OR SOME_FIELD = :SOME_FIELD
LIMIT 10`
params := []interface{}{
sql.Named("SOME_FIELD", nil),
} Please check my PR! 🙏 |
…er to a query (#199) - When a `sql.NamedValue` has the field `Value` set to `nil`, the resulting `cli_service.TSparkParameter` will also have the value `nil` instead of `*cli_service.TSparkParameterValue{StringValue: *"%!s(<nil>"}`. - Add the type `SqlVoid`, following the conventions used in the [NodeJS connector](https://github.com/databricks/databricks-sql-nodejs/blob/main/lib/DBSQLParameter.ts#L43-L51) and the [Python driver](https://github.com/databricks/databricks-sql-python/blob/f6fd7a7956a4dbc78ad36b5e079fe8d74176a0f1/src/databricks/sql/parameters/native.py#L319-L323). Fix #193. --------- Signed-off-by: Esdras Beleza <esdras@esdrasbeleza.com> Signed-off-by: Levko Kravets <levko.ne@gmail.com> Signed-off-by: candiduslynx <candiduslynx@gmail.com> Co-authored-by: Levko Kravets <levko.ne@gmail.com> Co-authored-by: Mahdi Dibaiee <mdibaiee@pm.me> Co-authored-by: Alex Shcherbakov <candiduslynx@users.noreply.github.com>
I was trying to use a query like this. I expected my query to return all results if it's not filtered, and filter the result if there's a filter.
and then I pass
sql.Named("mmCode", code)
to my query.code
is a*string
. It can, of course, be nil.Expected behaviour
name
isnil
, then it would be converted toNULL
in SQL and trigger the first case in myWHERE
clause.name
is notnil
, then it would become a string and trigger the second case in myWHERE
clause.Actual behaviour
I noticed that the library tries to use
fmt.Sprintf("%s", param.Value)
in parameters.go. Ifparam.Value
isnil
, it becomes"%s(<nil>)"
and my query won't work.Workaround
I'm now manually creating my
WHERE
clause depending of the values I have for each filter parameter, but being able to useISNULL
would and injectnil
parameters make my code shorter and cleaner.I tried to write a PR myself, but I'm not familiar with the Spark parameters API.
The text was updated successfully, but these errors were encountered: