cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Paramter Type while Executing Rest API of Execute a SQL statement POST /api/2.0/sql/statements/

A4Ashish
New Contributor II

Hi,
So previously I was using Old Preview Databricks API version. Now I have switched to v1 of the API which usage 
Execute a SQL statement POST /api/2.0/sql/statements/

I wanted to know how to pass the parameter class when my value is list of string for Eg
OLD Method
SQL - Select * from Table where columnName in ({{someName}})
parameter - new ParametersList {Name = "someName", Value = someNameList, Type = "enum", MultiValuesOptions = new MultiValuesListParameter { Prefix = "", Suffix = "", Separator = "," }, EnumOptions = string.Join("\n", someNameList)}

Now I need to convert this in new Databricks API
SQL - Select * from Table where columnName in (:someName)
parameter - new ParametersList {Name = "someName", Value = someNameList, Type = "string")}

this new parameter structure I go from the official link here 
Execute a SQL statement | Statement Execution API | REST API reference | Azure Databricks

Im not sure how to pass this parameter as the request is getting Bad request in response, I mainly wanted to know what to give Type when Value is a list

2 REPLIES 2

szymon_dybczak
Contributor III

Hi @A4Ashish ,

Currently complex data types are not supported in parameters. Have a look at below snippet from documentation:

https://docs.databricks.com/api/workspace/statementexecution/executestatement

"If the type is given, parameters will be checked for type correctness according to the given type. A value is correct if the provided string can be converted to the requested type using the cast function. The exact semantics are described in the section cast function of the SQL language reference."

So, according to documentation the only valid values are ones that can be casted to the target type using cast function. Now, take a look on below matrix from cast function documentation. As you can see, you cannot cast string to array using cast function, thus you cannot use it in this API.

Screenshot_20240826-212945.png

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group