Skip to content

Conversation

rogalski
Copy link
Contributor

@rogalski rogalski commented Oct 24, 2024

Brief summary of the change made

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

No.

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.

Dot notation is incompatible with this check.
Copy link
Contributor

github-actions bot commented Oct 24, 2024

Coverage Results ✅

Name    Stmts   Miss  Cover   Missing
-------------------------------------
TOTAL   18665      0   100%

236 files skipped due to complete coverage.

@alanmcruickshank
Copy link
Member

This feels like quite an extreme fix. I think there should be a better way of resolving this.

In the original issue the table name is there:

select
        pj.hash_key,
        pj.snapshot_date,
        trim(cast(pj.metadata_super."amount" as numeric))                                       as amount,
        ...
    from w_parse_json as pj

It's just qualified more than once (although that's Redshift). With the Athena example, I think it would be enough to only flag issues with the rule if there's more than one table in the query - at which point we should already expect that the first identifier should be the table name.

On interesting variant would be to just change the error message slightly, to indicate that if it's in Redshift or Athena - and it's a structured access type - we recommend having the table name as the first element.

Thoughts?

@rogalski
Copy link
Contributor Author

This feels like quite an extreme fix. I think there should be a better way of resolving this.

In the original issue the table name is there:

select
        pj.hash_key,
        pj.snapshot_date,
        trim(cast(pj.metadata_super."amount" as numeric))                                       as amount,
        ...
    from w_parse_json as pj

It's just qualified more than once (although that's Redshift). With the Athena example, I think it would be enough to only flag issues with the rule if there's more than one table in the query - at which point we should already expect that the first identifier should be the table name.

On interesting variant would be to just change the error message slightly, to indicate that if it's in Redshift or Athena - and it's a structured access type - we recommend having the table name as the first element.

Thoughts?

Alternatives which I was considering were to skip rule if query contains only one table reference (effectively assuming that columns are unqualified), or maybe skip rule if query contains one unaliased table reference.

This effectively solves both athena and redshift but was not consistent with repository main.

At the same time it's more fundamental rework - so let's get agreement that it's a valid direction before starting implementation.

@rogalski
Copy link
Contributor Author

@alanmcruickshank it ended up being a fairly modest uplift. I am happy with the essence of the fix, test cases / docs possibly can be refined.

@rogalski rogalski changed the title RF01: disable in Athena RF01: refine support for dialects with dot access Oct 27, 2024
@rogalski rogalski changed the title RF01: refine support for dialects with dot access RF01: refine support for dialects with dot access syntax Oct 27, 2024
@rogalski
Copy link
Contributor Author

I squeezed in for #6402 since it was somewhat close to touched code regions.

Copy link
Member

@alanmcruickshank alanmcruickshank left a comment

Choose a reason for hiding this comment

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

Nice. Looks good I think 👍 .

Well done for fitting in that other relevant issue too.

@alanmcruickshank alanmcruickshank added this pull request to the merge queue Oct 29, 2024
Merged via the queue into sqlfluff:main with commit b8d9c2b Oct 29, 2024
28 checks passed
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.

Support Request: RF01 rule
2 participants