Skip to content

Support for query parameterization #384

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

Closed
dylanscott opened this issue Feb 17, 2024 · 4 comments · Fixed by #401
Closed

Support for query parameterization #384

dylanscott opened this issue Feb 17, 2024 · 4 comments · Fixed by #401
Assignees
Labels
api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@dylanscott
Copy link

I was wondering if there were plans to expose the ability to pass bound parameters (either named or qmark style) when constructing constructing a bigframes DataFrame e.g. via Session.read_gbq_query? My understanding is they would need to be thread through to the queryParameters field on the QueryJobConfig that gets constructed.

I realize it's probably a bit of a niche use-case since this is a code-based API but for context we were looking to integrate support for bigframes in a product that allows users to build Python notebook-based interactive apps which may be used by external/untrusted users (not the ones writing the app/code) and so our SQL functionality relies on using parameterization whenever these kinds of inputs are involved.

@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. label Feb 17, 2024
@tswast tswast added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Feb 26, 2024
@tswast
Copy link
Collaborator

tswast commented Feb 26, 2024

In pandas-gbq this is exposed via a generic "configuration" parameter, where the JobConfig REST object can be passed directly as a dictionary.

I suggest that read_gbq and read_gbq_query add the same configuration argument in BigQuery DataFrames.

@tswast
Copy link
Collaborator

tswast commented Mar 8, 2024

Draft PR: #401

@tswast
Copy link
Collaborator

tswast commented Mar 22, 2024

Expected usage will be the same as pandas-gbq. See: https://stackoverflow.com/a/62171130/101923

sql = """
    SELECT name
    FROM `bigquery-public-data.usa_names.usa_1910_current`
    WHERE state = @state
"""
query_config = {
    'query': {
        'parameterMode': 'NAMED',
        'queryParameters': [
            {
                'name': 'state',
                'parameterType': {'type': 'STRING'},
                'parameterValue': {'value': 'TX'}
            },
        ]
    }
}
df = pandas_gbq.read_gbq(sql, configuration=query_config)

@tswast
Copy link
Collaborator

tswast commented Mar 25, 2024

This has been released in version 1.0.0

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 googleapis/python-bigquery-dataframes API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants