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

Changed date and datetime type conversions to use literal values in all cases (fix #126) #127

Merged
merged 4 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions pyathena/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,11 @@ def _format_default(formatter, escaper, val):


def _format_date(formatter, escaper, val):
if escaper is _escape_presto:
return "date'{0}'".format(val.strftime("%Y-%m-%d"))
else:
return "'{0}'".format(val.strftime("%Y-%m-%d"))
return "DATE '{0}'".format(val.strftime("%Y-%m-%d"))


def _format_datetime(formatter, escaper, val):
if escaper is _escape_presto:
return "timestamp'{0}'".format(val.strftime('%Y-%m-%d %H:%M:%S.%f')[:-3])
else:
return "'{0}'".format(val.strftime('%Y-%m-%d %H:%M:%S.%f')[:-3])
return "TIMESTAMP '{0}'".format(val.strftime('%Y-%m-%d %H:%M:%S.%f')[:-3])


def _format_bool(formatter, escaper, val):
Expand Down
14 changes: 7 additions & 7 deletions tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def format(self, operation, parameters=None):
def test_add_partition(self):
expected = """
ALTER TABLE test_table
ADD PARTITION (dt='2017-01-01', hour=1)
ADD PARTITION (dt=DATE '2017-01-01', hour=1)
""".strip()

actual = self.format("""
Expand All @@ -34,7 +34,7 @@ def test_add_partition(self):
def test_drop_partition(self):
expected = """
ALTER TABLE test_table
DROP PARTITION (dt='2017-01-01', hour=1)
DROP PARTITION (dt=DATE '2017-01-01', hour=1)
""".strip()

actual = self.format("""
Expand All @@ -61,8 +61,8 @@ def test_format_datetime(self):
expected = """
SELECT *
FROM test_table
WHERE col_timestamp >= timestamp'2017-01-01 12:00:00.000'
AND col_timestamp <= timestamp'2017-01-02 06:00:00.000'
WHERE col_timestamp >= TIMESTAMP '2017-01-01 12:00:00.000'
AND col_timestamp <= TIMESTAMP '2017-01-02 06:00:00.000'
""".strip()

actual = self.format("""
Expand All @@ -77,7 +77,7 @@ def test_format_date(self):
expected = """
SELECT *
FROM test_table
WHERE col_date between date'2017-01-01' and date'2017-01-02'
WHERE col_date between DATE '2017-01-01' and DATE '2017-01-02'
""".strip()

actual = self.format("""
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_format_datetime_list(self):
SELECT *
FROM test_table
WHERE col_timestamp IN
(timestamp'2017-01-01 12:00:00.000', timestamp'2017-01-02 06:00:00.000')
(TIMESTAMP '2017-01-01 12:00:00.000', TIMESTAMP '2017-01-02 06:00:00.000')
""".strip()

actual = self.format("""
Expand All @@ -205,7 +205,7 @@ def test_format_date_list(self):
expected = """
SELECT *
FROM test_table
WHERE col_date IN (date'2017-01-01', date'2017-01-02')
WHERE col_date IN (DATE '2017-01-01', DATE '2017-01-02')
""".strip()

actual = self.format("""
Expand Down