Skip to content
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

Making a INSERT query synchronous #58

Open
kylase opened this issue Mar 20, 2018 · 3 comments
Open

Making a INSERT query synchronous #58

kylase opened this issue Mar 20, 2018 · 3 comments
Labels

Comments

@kylase
Copy link

kylase commented Mar 20, 2018

Currently when an INSERT statement is run, the request will return a PrestoResult immediately, is there a way to make the query synchronous?

@ggreg
Copy link
Contributor

ggreg commented Mar 27, 2018

@kylase can you please share the code you're running?

@kylase
Copy link
Author

kylase commented Mar 28, 2018

The background of this issue is that we are using presto-python-client in Airflow to do INSERT query into Hive tables instead of using pyhive.

We were looking at changing Airflow's Presto hook to use presto-python-client instead of pyhive but realised the lack of SQLAlchemy compatibility which will affect pandas-related APIs in the hook.

So currently we are running the queries in PythonOperator as

 with prestodb.dbapi.connect(
        host=presto_conn.host,
        port=presto_conn.port,
        user=presto_conn.login,
        catalog=presto_conn.schema,
        schema=<schema>,
        isolation_level=transaction.IsolationLevel.AUTOCOMMIT,
) as conn:
        cur = conn.cursor()
        cur.execute(query)

where query is an INSERT INTO <table> SELECT ...

When this code is run in the operator, it exits immediately.

I would think that introducing SQLAlchemy compatibility would also help for #56?

@ggreg
Copy link
Contributor

ggreg commented Mar 28, 2018

SQL Alchemy compatibility is definitely a feature that this client will support. That is one of the goal of implement DBAPI2.

In your example, when the code exits the with blocks it should commit the transaction and wait for the query to complete. If it does not, it is a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants