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

Postgres "ALTER TABLE" enhancement, and timestamp bug fix #1338

Merged

Conversation

WittierDinosaur
Copy link
Contributor

@WittierDinosaur WittierDinosaur commented Aug 31, 2021

The initial purpose of this PR was to enhance the functionality of ALTER TABLE is Postgres, to match https://www.postgresql.org/docs/13/sql-altertable.html

However, the PR also includes a bugfix, for the timestamp with time zone issue, as this was getting in the way of my testing. It also slightly expands the definition of Expression D in ANSI, to allow the following kind of expression:
timestamp 'epoch' + foo_timestamp * interval '1 second'

Fixes #1289, Fixes #1286, Fixes #1168, Fixes #1155

Are there any other side effects of this change that we should be aware of?

Expands ANSI definitions of Expression_D, and timestamp with time zone (this is ANSI standard though). All current ANSI tests pass.

Pull Request checklist

I have included a lot of test cases for alter table - though more may be required.
The only extra functionality needed is sequences, for which I haven't yet raised a ticket

Copy link
Member

@barrywhart barrywhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good. I'm seeing some linter failures. Can you address these? I think it'll be ready to merge at that point, assuming the build passes.

./src/sqlfluff/dialects/dialect_ansi.py:519:1: D212 Multi-line docstring summary should start at the first line
./src/sqlfluff/dialects/dialect_postgres.py:361:1: D212 Multi-line docstring summary should start at the first line
./src/sqlfluff/dialects/dialect_postgres.py:440:1: D212 Multi-line docstring summary should start at the first line
./src/sqlfluff/dialects/dialect_postgres.py:440:1: D415 First line should end with a period, question mark, or exclamation point
./src/sqlfluff/dialects/dialect_postgres.py:625:1: D212 Multi-line docstring summary should start at the first line
./src/sqlfluff/dialects/dialect_postgres.py:683:1: D200 One-line docstring should fit on one line with quotes
./src/sqlfluff/dialects/dialect_postgres.py:683:1: D212 Multi-line docstring summary should start at the first line
./src/sqlfluff/dialects/dialect_postgres.py:683:1: D415 First line should end with a period, question mark, or exclamation point
./src/sqlfluff/dialects/dialect_postgres.py:796:1: D200 One-line docstring should fit on one line with quotes
./src/sqlfluff/dialects/dialect_postgres.py:796:1: D212 Multi-line docstring summary should start at the first line
./src/sqlfluff/dialects/dialect_postgres.py:796:1: D415 First line should end with a period, question mark, or exclamation point
./src/sqlfluff/dialects/dialect_postgres.py:821:1: D200 One-line docstring should fit on one line with quotes
./src/sqlfluff/dialects/dialect_postgres.py:821:1: D212 Multi-line docstring summary should start at the first line
./src/sqlfluff/dialects/dialect_postgres.py:821:1: D415 First line should end with a period, question mark, or exclamation point
./src/sqlfluff/dialects/dialect_postgres.py:849:1: D200 One-line docstring should fit on one line with quotes
./src/sqlfluff/dialects/dialect_postgres.py:849:1: D212 Multi-line docstring summary should start at the first line
./src/sqlfluff/dialects/dialect_postgres.py:849:1: D415 First line should end with a period, question mark, or exclamation point
./src/sqlfluff/dialects/dialect_postgres.py:866:1: D200 One-line docstring should fit on one line with quotes
./src/sqlfluff/dialects/dialect_postgres.py:866:1: D212 Multi-line docstring summary should start at the first line
./src/sqlfluff/dialects/dialect_postgres.py:866:1: D415 First line should end with a period, question mark, or exclamation point

@codecov
Copy link

codecov bot commented Aug 31, 2021

Codecov Report

Merging #1338 (dbfe612) into main (c7620f4) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1338      +/-   ##
==========================================
+ Coverage   97.07%   97.10%   +0.03%     
==========================================
  Files         124      124              
  Lines        8541     8573      +32     
==========================================
+ Hits         8291     8325      +34     
+ Misses        250      248       -2     
Flag Coverage Δ
dbt018-py38 61.35% <100.00%> (+0.16%) ⬆️
dbt019-py38 61.35% <100.00%> (+0.16%) ⬆️
dbt020-py38 61.32% <100.00%> (+0.16%) ⬆️
py36 95.85% <100.00%> (+0.01%) ⬆️
py37 95.88% <100.00%> (+0.01%) ⬆️
py38 95.92% <100.00%> (+0.03%) ⬆️
py39 95.89% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/sqlfluff/dialects/dialect_ansi.py 100.00% <100.00%> (ø)
src/sqlfluff/dialects/dialect_postgres.py 100.00% <100.00%> (ø)
src/sqlfluff/core/linter/runner.py 94.68% <0.00%> (+2.12%) ⬆️

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 c7620f4...dbfe612. Read the comment docs.

@WittierDinosaur
Copy link
Contributor Author

Linter failures fixed, build passing

@tunetheweb
Copy link
Member

@WittierDinosaur can you checkout what's going on with the formatting changes to benchmarks/bench_002/bench_002_pearson_fix.sql - was this intentional?

@WittierDinosaur
Copy link
Contributor Author

@tunetheweb No, I'm not sure why that is happening. But I don't think it's been introduced by my code. The output is weird, but it passes the tox -e bench test. I think this issue was introduced somewhere else. I just ran tox before I committed, so the file was changed. I'm getting the same behaviour if I run tox -e bench when I checkout main. Can you verify it's happening on the main branch for you?

@tunetheweb
Copy link
Member

No I'm not getting it. Do you have a .sqlfluff file in your repo with different settings to the default?

Copy link
Member

@tunetheweb tunetheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Though as discussed can you try and figure out the benchmark change? Maybe a rogue .sqlfluff file?

test/fixtures/parser/ansi/select_true_and_not_false.yml Outdated Show resolved Hide resolved
test/fixtures/parser/postgres/postgres_select.sql Outdated Show resolved Hide resolved
test/fixtures/parser/postgres/postgres_alter_table.sql Outdated Show resolved Hide resolved
@WittierDinosaur
Copy link
Contributor Author

WittierDinosaur commented Sep 1, 2021

@tunetheweb I've just cloned sqlfluff's main fresh, pip installed tox, and the bench output is doing the same thing. I have no idea how to explain it. Surely nothing is cached outside of the project folder? Maybe an OS thing? I don't know.

@tunetheweb
Copy link
Member

@tunetheweb I've just cloned sqlfluff's main fresh, pip installed tox, and the bench output is doing the same thing. I have no idea how to explain it. Surely nothing is cached outside of the project folder? Maybe an OS thing? I don't know.

Weird! For now do you just wanna revert the changes in your branch and try your best not to check them in?

@WittierDinosaur
Copy link
Contributor Author

Can do, worried about them masking an issue though. Are you able to checkout my branch and see if tox -e bench does this for my branch on your machine?

@WittierDinosaur
Copy link
Contributor Author

Update - I got my flatmate to test on his machine. His steps were, git clone, pip install tox, tox -e bench, and the same thing happened on his machine

@tunetheweb
Copy link
Member

tunetheweb commented Sep 1, 2021

Actually you're right it DOES do this for me. Sorry for misleading you.

I've just never run bench when using tox. I normally just do the below (from the CONTRIBUTING.md file):

tox -e generate-fixture-yml,cov-init,py36,cov-report,linting

So never noticed this before. So we might as well commit it to avoid the issue in future for anyone else that runs this!

@WittierDinosaur
Copy link
Contributor Author

Thought I was going mad 😄 Okay, add in your edits, and check that not keyword then, commits inbound shortly. Also, we should raise this as a bug, i'm sure that's not the expected format

Copy link
Member

@tunetheweb tunetheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for this - and for working through the feedback.

@barrywhart you any further comments or happy to merge?

Copy link
Member

@barrywhart barrywhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! My only concern was the code linter stuff, and that's been addressed. Thanks!

@tunetheweb tunetheweb merged commit ab11418 into sqlfluff:main Sep 1, 2021
@Olaktal
Copy link

Olaktal commented Sep 13, 2021

Hello guys,
Sounds like it didn't solve my problem :(
Any idea ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants