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

Conversation

laughingman7743
Copy link
Owner

@laughingman7743 laughingman7743 commented Mar 21, 2020

TODO:

  • Unit test.

@laughingman7743
Copy link
Owner Author

_______________ TestDefaultParameterFormatter.test_add_partition _______________
self = <tests.test_formatter.TestDefaultParameterFormatter testMethod=test_add_partition>
    def test_add_partition(self):
        expected = """
        ALTER TABLE test_table
        ADD PARTITION (dt='2017-01-01', hour=1)
        """.strip()

        actual = self.format("""
        ALTER TABLE test_table
        ADD PARTITION (dt=%(dt)s, hour=%(hour)d)
        """, {'dt': date(2017, 1, 1), 'hour': 1})
>       self.assertEqual(actual, expected)
E       AssertionError: "ALTE[19 chars]n        ADD PARTITION (dt=CAST('2017-01-01' AS DATE), hour=1)" != "ALTE[19 chars]n        ADD PARTITION (dt='2017-01-01', hour=1)"
E         ALTER TABLE test_table
E       -         ADD PARTITION (dt=CAST('2017-01-01' AS DATE), hour=1)?                           -----            ---------
E       +         ADD PARTITION (dt='2017-01-01', hour=1)

@laughingman7743
Copy link
Owner Author

laughingman7743 commented Mar 21, 2020

CREATE EXTERNAL TABLE IF NOT EXISTS date_partition_table (
    a STRING
)
PARTITIONED BY (b DATE)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' STORED AS TEXTFILE
LOCATION 's3://BUCKET/path/to/';

A partition can be added with the following ALTER statement.
ALTER table date_partition_table ADD PARTITION (b=date '2017-01-01');

An error occurred in the following ALTER statement.
ALTER table date_partition_table ADD PARTITION (b=CAST('2017-01-01' AS DATE));
line 1:38: missing 'column' at 'partition' (service: amazonathena; status code: 400; error code: invalidrequestexception;

@laughingman7743
Copy link
Owner Author

laughingman7743 commented Mar 21, 2020

In all cases, it may be better to convert to date '2020-01-01 'or timestamp '2020-01-01 00:00:00.000' using a literal value.

@codecov
Copy link

codecov bot commented Mar 21, 2020

Codecov Report

Merging #127 into master will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #127      +/-   ##
==========================================
+ Coverage   93.46%   93.51%   +0.05%     
==========================================
  Files          14       14              
  Lines        1361     1357       -4     
==========================================
- Hits         1272     1269       -3     
+ Misses         89       88       -1     
Impacted Files Coverage Δ
pyathena/formatter.py 96.15% <100.00%> (+1.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 356b609...d13b720. Read the comment docs.

@laughingman7743 laughingman7743 changed the title Changed to use CAST function in date and datetime type conversion (fix #126) Changed date and datetime type conversions to use literal values in all cases (fix #126) Mar 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant