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

Commit

Permalink
Merge pull request #10 from laughingman7743/retrieve_query_id
Browse files Browse the repository at this point in the history
Add property to retrieve query_id (fix #9)
  • Loading branch information
laughingman7743 committed Mar 27, 2017
2 parents a2f0622 + d792e99 commit 292d170
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pyathenajdbc/cursor.py
Expand Up @@ -75,6 +75,12 @@ def description(self):
]
return self._description

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

def close(self):
self._meta_data = None
if self._result_set and not self._result_set.isClosed():
Expand Down
10 changes: 10 additions & 0 deletions tests/test_pyathenajdbc.py
Expand Up @@ -4,6 +4,7 @@
import contextlib
import os
import random
import re
import string
import unittest
from datetime import datetime, date
Expand Down Expand Up @@ -196,6 +197,14 @@ def test_description(self, cursor):
cursor.execute('SELECT 1 AS foobar FROM one_row')
self.assertEqual(cursor.description, [('foobar', 4, 11, None, 10, 0, 2)])

@with_cursor
def test_query_id(self, cursor):
cursor.execute('SELECT * from one_row')
# query_id is UUID v4
expected_pattern = \
r'^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'
self.assertTrue(re.match(expected_pattern, cursor.query_id))

@with_cursor
def test_complex(self, cursor):
# TODO DECIMAL type failed to fetch with java.lang.IndexOutOfBoundsException
Expand Down Expand Up @@ -311,6 +320,7 @@ def test_cursor_is_closed(self):
self.assertRaises(ProgrammingError, lambda: cursor.fetchmany())
self.assertRaises(ProgrammingError, lambda: cursor.fetchall())
self.assertRaises(ProgrammingError, lambda: cursor.cancel())
self.assertRaises(ProgrammingError, lambda: cursor.query_id)

def test_no_ops(self):
conn = self.connect()
Expand Down

0 comments on commit 292d170

Please sign in to comment.