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

Commit ce82f59

Browse files
Merge pull request #103 from laughingman7743/add_test_case_for_as_pandas_method
Add test case for as_pandas method
2 parents d693c59 + 1bb415a commit ce82f59

13 files changed

Lines changed: 265 additions & 55 deletions

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "pypi"
77
allow_prereleases = true
88

99
[packages]
10-
"e1839a8" = {path = ".", extras = ["sqlalchemy"], editable = true}
10+
"e1839a8" = {path = ".", extras = ["sqlalchemy", "pandas"], editable = true}
1111

1212
[dev-packages]
1313
awscli = "*"

Pipfile.lock

Lines changed: 57 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyathenajdbc/util.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import functools
55
import threading
6-
from datetime import datetime
76

87

98
def as_pandas(cursor, coerce_float=False):
@@ -39,20 +38,3 @@ def _wrapper(*args, **kwargs):
3938
return wrapped(*args, **kwargs)
4039

4140
return _wrapper
42-
43-
44-
def to_datetime(java_date):
45-
if not java_date:
46-
return None
47-
import jpype
48-
49-
cal = jpype.java.util.Calendar.getInstance()
50-
cal.setTime(java_date)
51-
return datetime(
52-
cal.get(jpype.java.util.Calendar.YEAR),
53-
cal.get(jpype.java.util.Calendar.MONTH) + 1,
54-
cal.get(jpype.java.util.Calendar.DAY_OF_MONTH),
55-
cal.get(jpype.java.util.Calendar.HOUR_OF_DAY),
56-
cal.get(jpype.java.util.Calendar.MINUTE),
57-
cal.get(jpype.java.util.Calendar.SECOND),
58-
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
true false
2+
false
3+

scripts/test_data/delete_test_data.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
aws s3 rm ${AWS_ATHENA_S3_STAGING_DIR}test_pyathena_jdbc/one_row/one_row.tsv
66
aws s3 rm ${AWS_ATHENA_S3_STAGING_DIR}test_pyathena_jdbc/one_row_complex/one_row_complex.tsv
77
aws s3 rm ${AWS_ATHENA_S3_STAGING_DIR}test_pyathena_jdbc/many_rows/many_rows.tsv
8+
aws s3 rm ${AWS_ATHENA_S3_STAGING_DIR}test_pyathena_jdbc/integer_na_values/integer_na_values.tsv
9+
aws s3 rm ${AWS_ATHENA_S3_STAGING_DIR}test_pyathena_jdbc/boolean_na_values/boolean_na_values.tsv
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 2
2+
1
3+

scripts/test_data/upload_test_data.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
aws s3 cp $(dirname $0)/one_row.tsv ${AWS_ATHENA_S3_STAGING_DIR}test_pyathena_jdbc/one_row/one_row.tsv
66
aws s3 cp $(dirname $0)/one_row_complex.tsv ${AWS_ATHENA_S3_STAGING_DIR}test_pyathena_jdbc/one_row_complex/one_row_complex.tsv
77
aws s3 cp $(dirname $0)/many_rows.tsv ${AWS_ATHENA_S3_STAGING_DIR}test_pyathena_jdbc/many_rows/many_rows.tsv
8+
aws s3 cp $(dirname $0)/integer_na_values.tsv ${AWS_ATHENA_S3_STAGING_DIR}test_pyathena_jdbc/integer_na_values/integer_na_values.tsv
9+
aws s3 cp $(dirname $0)/boolean_na_values.tsv ${AWS_ATHENA_S3_STAGING_DIR}test_pyathena_jdbc/boolean_na_values/boolean_na_values.tsv

tests/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,38 @@
11
# -*- coding: utf-8 -*-
2+
import os
3+
import random
4+
import string
5+
6+
from past.builtins.misc import xrange
27
from sqlalchemy.dialects import registry
38

49
registry.register("awsathena.jdbc", "pyathenajdbc.sqlalchemy_athena", "AthenaDialect")
10+
11+
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
12+
S3_PREFIX = "test_pyathena_jdbc"
13+
WORK_GROUP = "test-pyathena-jdbc"
14+
SCHEMA = "test_pyathena_jdbc_" + "".join(
15+
[random.choice(string.ascii_lowercase + string.digits) for i in xrange(10)]
16+
)
17+
18+
19+
class Env(object):
20+
def __init__(self):
21+
self.region_name = os.getenv("AWS_DEFAULT_REGION", None)
22+
assert (
23+
self.region_name
24+
), "Required environment variable `AWS_DEFAULT_REGION` not found."
25+
self.s3_staging_dir = os.getenv("AWS_ATHENA_S3_STAGING_DIR", None)
26+
assert (
27+
self.s3_staging_dir
28+
), "Required environment variable `AWS_ATHENA_S3_STAGING_DIR` not found."
29+
30+
31+
ENV = Env()
32+
33+
34+
class WithConnect(object):
35+
def connect(self, work_group=None):
36+
from pyathenajdbc import connect
37+
38+
return connect(schema_name=SCHEMA, work_group=work_group)

tests/conftest.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,12 @@
33

44
import contextlib
55
import os
6-
import random
7-
import string
86

97
import pytest
10-
from past.builtins.misc import xrange
118

129
from pyathenajdbc import connect
13-
from tests.util import Env, read_query
14-
15-
ENV = Env()
16-
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
17-
S3_PREFIX = "test_pyathena_jdbc"
18-
WORK_GROUP = "test-pyathena-jdbc"
19-
SCHEMA = "test_pyathena_jdbc_" + "".join(
20-
[random.choice(string.ascii_lowercase + string.digits) for i in xrange(10)]
21-
)
10+
from tests import BASE_PATH, ENV, S3_PREFIX, SCHEMA
11+
from tests.util import read_query
2212

2313

2414
@pytest.fixture(scope="session", autouse=True)
@@ -54,12 +44,24 @@ def _create_table(cursor):
5444
location_one_row_complex = "{0}{1}/{2}/".format(
5545
ENV.s3_staging_dir, S3_PREFIX, "one_row_complex"
5646
)
47+
location_partition_table = "{0}{1}/{2}/".format(
48+
ENV.s3_staging_dir, S3_PREFIX, "partition_table"
49+
)
50+
location_integer_na_values = "{0}{1}/{2}/".format(
51+
ENV.s3_staging_dir, S3_PREFIX, "integer_na_values"
52+
)
53+
location_boolean_na_values = "{0}{1}/{2}/".format(
54+
ENV.s3_staging_dir, S3_PREFIX, "boolean_na_values"
55+
)
5756
for q in read_query(os.path.join(BASE_PATH, "sql", "create_table.sql")):
5857
cursor.execute(
5958
q.format(
6059
schema=SCHEMA,
6160
location_one_row=location_one_row,
6261
location_many_rows=location_many_rows,
6362
location_one_row_complex=location_one_row_complex,
63+
location_partition_table=location_partition_table,
64+
location_integer_na_values=location_integer_na_values,
65+
location_boolean_na_values=location_boolean_na_values,
6466
)
6567
)

tests/sql/create_table.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,27 @@ CREATE EXTERNAL TABLE IF NOT EXISTS {schema}.one_row_complex (
3030
)
3131
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' STORED AS TEXTFILE
3232
LOCATION '{location_one_row_complex}';
33+
34+
DROP TABLE IF EXISTS {schema}.partition_table;
35+
CREATE EXTERNAL TABLE IF NOT EXISTS {schema}.partition_table (
36+
a STRING
37+
)
38+
PARTITIONED BY (b INT)
39+
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' STORED AS TEXTFILE
40+
LOCATION '{location_partition_table}';
41+
42+
DROP TABLE IF EXISTS {schema}.integer_na_values;
43+
CREATE EXTERNAL TABLE IF NOT EXISTS {schema}.integer_na_values (
44+
a INT,
45+
b INT
46+
)
47+
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' STORED AS TEXTFILE
48+
LOCATION '{location_integer_na_values}';
49+
50+
DROP TABLE IF EXISTS {schema}.boolean_na_values;
51+
CREATE EXTERNAL TABLE IF NOT EXISTS {schema}.boolean_na_values (
52+
a BOOLEAN,
53+
b BOOLEAN
54+
)
55+
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' STORED AS TEXTFILE
56+
LOCATION '{location_boolean_na_values}';

0 commit comments

Comments
 (0)