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: treat GENERATE_SERIES as a value table function #3463

Merged

Conversation

tunetheweb
Copy link
Member

@tunetheweb tunetheweb commented Jun 16, 2022

Brief summary of the change made

Fixes #3462

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

I uppercased value table values in common with other syntax

Pull Request checklist

  • Please confirm you have completed any of the necessary steps below.

  • Included test cases to demonstrate any code changes, which may be one or more of the following:

    • .yml rule test cases in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with tox -e generate-fixture-yml).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.
  • Added appropriate documentation for the change.

  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

@codecov
Copy link

codecov bot commented Jun 16, 2022

Codecov Report

Merging #3463 (3ab5402) into main (6e8ce43) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main     #3463   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          171       171           
  Lines        12898     12898           
=========================================
  Hits         12898     12898           
Impacted Files Coverage Δ
src/sqlfluff/core/rules/analysis/select.py 100.00% <100.00%> (ø)
src/sqlfluff/dialects/dialect_bigquery.py 100.00% <100.00%> (ø)
src/sqlfluff/dialects/dialect_postgres.py 100.00% <100.00%> (ø)

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 6e8ce43...3ab5402. Read the comment docs.

@tunetheweb
Copy link
Member Author

@alanmcruickshank another simple one that's good for v1.0.0 if you see this in time.

@@ -43,6 +43,18 @@ test_ignore_postgres_value_table_functions:
core:
dialect: postgres

test_ignore_postgres_value_table_functions_generate_series:
Copy link
Member

Choose a reason for hiding this comment

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

Would it be worth adding an opposite test, like a similar query but a different function name?

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't think we should put a random, gibberish function in can't think of a function that you could put in a FROM clause without it being a value table function.

Maybe all functions in FROM clauses should be value table functions rather than explicitly listing them? But let's keep this change simple since we're just about to release so that's out of scope for now.

@@ -134,7 +134,7 @@ def _has_value_table_function(table_expr, dialect):
# Other rules can increase whitespace in the function name, so use strip to
# remove
# See: https://github.com/sqlfluff/sqlfluff/issues/1304
if function_name.raw.lower().strip() in dialect.sets("value_table_functions"):
if function_name.raw.upper().strip() in dialect.sets("value_table_functions"):
Copy link
Member

Choose a reason for hiding this comment

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

Why did this need to change? Did we have dialects using both upper and lower-case to specify value table functions?

Copy link
Member Author

Choose a reason for hiding this comment

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

I noted above in the "Are there any other side effect..." section:

I uppercased value table values in common with other syntax

Basically, I personally just found it weird that other functions and keywords were in caps, but these were in lowercase.

I considered making it case insensitive but there's a (very slight) performance impact as have to create a new set, and even though the sets are small it's not worth it IMHO.

@barrywhart barrywhart merged commit 8aa74a4 into sqlfluff:main Jun 16, 2022
@tunetheweb tunetheweb deleted the 3462-postgres-generate-series-fix branch June 23, 2022 10:15
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.

L011 L025 mistakenly flagging GENERATE_SERIES parameters as an alias
2 participants