Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Return the Query ID after execute query in Athena #9

Closed
phamhoangtuan opened this issue Mar 22, 2017 · 4 comments
Closed

Return the Query ID after execute query in Athena #9

phamhoangtuan opened this issue Mar 22, 2017 · 4 comments
Assignees

Comments

@phamhoangtuan
Copy link

  • Purpose: Get the query ID to search for the file in S3, download that file and add data to our DB.
  • Current situation: We have no way to retrieve the query ID after execute the query. We need to search for the latest file in S3 and download that file.
  • Proposed approach: Have a function, maybe called getQueryID in cursor to return the executed query ID.
@tewfik-ghariani
Copy link

tewfik-ghariani commented Mar 23, 2017

Hello,
As a matter of fact, there is a method to retrieve the query ID. It is already mentioned in the official documentation of Athena JDBC driver and it is functional within PyAthenajdbc module.

It consists in specifying the log_path option in the connection method

jdbc
log

Example

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
athena_jdbc_driver_path = BASE_DIR + "/lib/static/AthenaJDBC.jar"
log_path = BASE_DIR + "/lib/static/queries.log"



conn = pyathenajdbc.connect(
                              s3_staging_dir="s3://athena",
                              access_key=access_key_id,
                              secret_key=secret_key_id,
                              region_name="us-east-1",
                              log_path=log_path,
                              driver_path=athena_jdbc_driver_path
                              )

@laughingman7743
Copy link
Owner

laughingman7743 commented Mar 23, 2017

I think that it can be realized with the following simple implementation.

    @property
    def query_id(self):
        if not self.has_result_set:
            raise ProgrammingError('No result set.')
        return self._result_set.getClient().getQueryId()

I will check on the weekend.
Thanks,

@laughingman7743
Copy link
Owner

I added a property to retrieve the query_id to the cursor object with the following pull request.
#10

Please check it.

@laughingman7743 laughingman7743 self-assigned this Mar 25, 2017
laughingman7743 pushed a commit that referenced this issue Mar 27, 2017
Add property to retrieve query_id (fix #9)
@miltoneck
Copy link

so... that's gone?
is there a different way of doing this?
or where did the getClient() property go?

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

No branches or pull requests

4 participants