GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Running a chain of statements that depend on each other · Issue #74 · googleapis/python-bigquery-sqlalchemy

This repository was archived by the owner on May 16, 2026. It is now read-only.
This repository was archived by the owner on May 16, 2026. It is now read-only.

Running a chain of statements that depend on each other #74

Copy link
Copy link
Closed
Closed
Running a chain of statements that depend on each other#74
Copy link
Labels
api: bigqueryIssues related to the googleapis/python-bigquery-sqlalchemy API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Description

@mistercrunch
mistercrunch
opened on Nov 7, 2020
Issue body actions
DECLARE d DATE DEFAULT CURRENT_DATE();
CREATE TEMP FUNCTION Add(x INT64, y INT64) AS (x + y);
SELECT Add(3, 4);

I'm having an issue running a chain of statements that depend on each other in a common session. I'm using a single connection and cursor behind the scene.

It appears that the statements are not chained and the session isn't persisted. Any clue on how to solve this?

Other DBAPI implementations allow this type of chaining, and using the same logic with this driver does not work properly.

Activity

  1. tswast commented on Nov 9, 2020

    @tswast
    tswast
    on Nov 9, 2020 via email
    Contributor
    More actions
    Do you know how this chain is being executed by the underlying DB-API? I recall that BigQuery didn't support scripting when I first implemented the DB-API connector. Perhaps this would be fixed by changing the executemany() function to issue the statements in one batch?
    …
    On Fri, Nov 6, 2020, 9:30 PM Maxime Beauchemin ***@***.***> wrote: [image: Screen Shot 2020-11-06 at 7 28 37 PM] <https://user-images.githubusercontent.com/487433/98430957-5503d680-2066-11eb-9583-7775aa2490fd.png> I'm having an issue running a chain of statements that depend on each other in a common session. I'm using a single connection and cursor behind the scene. It appears that the statements are not chained and the session isn't persisted. Any clue on how to solve this? Other DBAPI implementations allow this type of chaining, and using the same logic with this driver does not work properly. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#74>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAB4OA2OYVXJMJOMZYIWV7LSOS5PFANCNFSM4TNMHVJQ> .
  2. mistercrunch commented on Nov 9, 2020

    @mistercrunch
    mistercrunch
    on Nov 9, 2020
    ContributorAuthor
    More actions

    Do you know how this chain is being executed by the underlying DB-API?

    I'm not sure if you're asking about how we run it, or how the underlying DB-API in google-cloud-bigquery does it (?). Assuming the former, we open a connection object and a cursor object and cursor.execute the series of statements.

    Perhaps this would be fixed by changing the executemany() function to issue the statements in one batch?
    I think that executemany is a way to run the same SQL statement multiple times with different parameters (?) https://googleapis.dev/python/bigquery/latest/dbapi.html#google.cloud.bigquery.dbapi.Cursor.executemany

    Now I'm realizing the issue may be in google-cloud-bigquery, do you think I should open an issue there?

  3. tswast commented on Nov 9, 2020

    @tswast
    tswast
    on Nov 9, 2020
    Contributor
    More actions

    Yes, https://github.com/googleapis/python-bigquery would be the appropriate location for this issue.

    Are you calling execute once? Or once per statement?

    If once per statement, are there any transaction semantics you're using? The BigQuery API doesn't hold onto cursor/connection state, so we'll need some kind of additional information in order for the client to batch these up into a single request.

    Reacted by Maxime Beauchemin
  4. mistercrunch commented on Nov 10, 2020

    @mistercrunch
    mistercrunch
    on Nov 10, 2020
    ContributorAuthor
    More actions

    We're calling execute for each statement, most other DB-API driver's execute assumes a single statement. All other DB-API drivers we use in Apache Superset respond well to this approach

    so we'll need some kind of additional information in order for the client to batch these up into a single request

    Wondering what that may be. I saw the notion of job_id reading some source code in google-cloud-bigquery, but unclear as to how to get this to work.

  5. mistercrunch commented on Nov 10, 2020

    @mistercrunch
    mistercrunch
    on Nov 10, 2020
    ContributorAuthor
    More actions

    I opened an issue on python-bigquery with more details, and really appreciate all the help so far!

  6. tswast
    added
    api: bigqueryIssues related to the googleapis/python-bigquery-sqlalchemy API.
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    on Mar 23, 2021
  7. tswast commented on Mar 23, 2021

    @tswast
    tswast
    on Mar 23, 2021
    Contributor
    More actions

    Updating this issue from our discussion on the DB-API. Currently we workaround this by batching all statements in to a single query request. This triggers the BigQuery "scripting" path.

    The ideal solution is for the BigQuery backend to support true sessions for scripting. If/when they add support for sessions, we can make the update to the DB-API and test it with this SQLAlchemy connector.

  8. jimfulton
    closed this as completedon May 19, 2021
  9. mattalbr commented on Nov 6, 2024

    @mattalbr
    mattalbr
    on Nov 6, 2024
    More actions

    Sorry to drag up an old issue, but this is where I was looking to figure out how to write such a query using bigquery sqlalchemy.

    I'm assuming the SET/DECLARE statements need to be created using text(), but is there a good way to combine these SET/DECLAREs with a selectable at the end without compiling the selectable?

    Relatedly, is there a way to do a CREATE TEMP TABLE foo AS () and input a selectable?

    Happy to file a new issue along the lines of Document multi-statement query usage if that's easier!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: bigqueryIssues related to the googleapis/python-bigquery-sqlalchemy API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.