Skip to content

Named parameters support#200

Closed
mattdeekay wants to merge 7 commits into
databricks:parameterized-queriesfrom
mattdeekay:named-parameters
Closed

Named parameters support#200
mattdeekay wants to merge 7 commits into
databricks:parameterized-queriesfrom
mattdeekay:named-parameters

Conversation

@mattdeekay

Copy link
Copy Markdown
Contributor

Supports server-side named query parameterization. Client will need to call execute like this:

cursor.execute('SELECT :param_a FROM samples', {"param_a": "some_value"})

This removes client-side query injection that was a facade for query parameterization while the server-side support was still under development.

Signed-off-by: Matthew Kim <11141331+mattdeekay@users.noreply.github.com>
Signed-off-by: Matthew Kim <11141331+mattdeekay@users.noreply.github.com>
Signed-off-by: Matthew Kim <11141331+mattdeekay@users.noreply.github.com>
Signed-off-by: Matthew Kim <11141331+mattdeekay@users.noreply.github.com>
Signed-off-by: Matthew Kim <11141331+mattdeekay@users.noreply.github.com>
Signed-off-by: Matthew Kim <11141331+mattdeekay@users.noreply.github.com>
Signed-off-by: Matthew Kim <11141331+mattdeekay@users.noreply.github.com>

@andrefurlan-db andrefurlan-db left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make sure that parameterized query support is consistent across all drivers/connectors. @rcypher-databricks needs to review and make sure it is. Specially data type handling stuff

)

def execute(
self, operation: str, parameters: Optional[Dict[str, str]] = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we allowed users to do this I think we should continue to support it, but instead of injecting the parameter values in the driver we should convert to the format expected by the backend and pass it on.

return spark_params

@staticmethod
def get_type_and_value(value: Any) -> (str, TSparkParameterValue):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to have more comprehensive handling of types. There needs to be a way for a user to specify the desired sql type of the parameter value.

@susodapop

Copy link
Copy Markdown
Contributor

Closing as this was implemented in #217

@susodapop susodapop closed this Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants