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

Add sql backend + sqlfluff linter #20854

Merged
merged 37 commits into from May 10, 2024
Merged

Conversation

grihabor
Copy link
Contributor

No description provided.

Copy link
Member

@kaos kaos left a comment

Choose a reason for hiding this comment

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

lgtm bar some nits.

Also miss some file headers, which I think will be added if you run pants fmt (or maybe pants fix?) by the preamble backend.

src/python/pants/backend/sql/tailor.py Outdated Show resolved Hide resolved
src/python/pants/backend/sql/tailor.py Outdated Show resolved Hide resolved
src/python/pants/backend/sql/target_types.py Outdated Show resolved Hide resolved
src/python/pants/backend/sql/target_types.py Outdated Show resolved Hide resolved
@grihabor grihabor marked this pull request as ready for review April 29, 2024 09:35
Copy link
Contributor Author

@grihabor grihabor left a comment

Choose a reason for hiding this comment

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

Thanks for an early review!

Fixed the issues

src/python/pants/backend/sql/target_types.py Outdated Show resolved Hide resolved
src/python/pants/backend/sql/tailor.py Outdated Show resolved Hide resolved
src/python/pants/backend/sql/tailor.py Outdated Show resolved Hide resolved
src/python/pants/backend/sql/target_types.py Outdated Show resolved Hide resolved
@grihabor
Copy link
Contributor Author

How do I make sure the tests only run for python>=3.8?

src/python/pants/backend/sql/target_types.py Outdated Show resolved Hide resolved
@kaos
Copy link
Member

kaos commented Apr 29, 2024

How do I make sure the tests only run for python>=3.8?

Look at how these have been applied:
https://github.com/pantsbuild/pants/blob/main/src/python/pants/testutil/python_interpreter_selection.py

@cburroughs
Copy link
Contributor

oh, for Sqlfluff, yeah! 🎉

@grihabor grihabor changed the title Add sql backend Add sql backend + sqlfluff linter Apr 29, 2024
@kaos
Copy link
Member

kaos commented May 6, 2024

Would be great with a few more lines of docs, describing at least briefly how to enable and use this backend :)
(I think that there are two backends to enable could trip at least new users up..)

@grihabor
Copy link
Contributor Author

grihabor commented May 6, 2024

@kaos Sure, added the docs

Copy link
Member

@kaos kaos left a comment

Choose a reason for hiding this comment

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

Thanks!

@benjyw
Copy link
Sponsor Contributor

benjyw commented May 6, 2024

Thanks for this @grihabor, exciting to have a new useful backend like this.

I do have one comment which may not be immediately actionable: I wonder if we actually need targets at all for this sort of backend? It seems like we could just treat all *.sql files appropriately and not have explicit targets (even tailored ones) at all.

That said, it would be the first time we'd done something like that, and there may be gotchas, so I don't expect you to make that change. But as I think we should be moving towards that sort of paradigm in the future, this backend might be a good place to experiment with it when we start looking into it.

@grihabor
Copy link
Contributor Author

grihabor commented May 6, 2024

Thank you for review!

I wonder if we actually need targets at all for this sort of backend?

I don't know, I just did it similar to other backends. Right now we're using this as a plugin and the .sql is actually a python template string which we render in the application. I'm thinking about moving sql rendering directly into pants in the future, so that the application consumes ready to go sql without templating, so I will probably need some codegen with jinja for sql, but I'm not sure it's a good idea yet.

@kaos
Copy link
Member

kaos commented May 7, 2024

Thanks for this @grihabor, exciting to have a new useful backend like this.

I do have one comment which may not be immediately actionable: I wonder if we actually need targets at all for this sort of backend? It seems like we could just treat all *.sql files appropriately and not have explicit targets (even tailored ones) at all.

That said, it would be the first time we'd done something like that, and there may be gotchas, so I don't expect you to make that change. But as I think we should be moving towards that sort of paradigm in the future, this backend might be a good place to experiment with it when we start looking into it.

Ah, right. This is an excellent comment, and also not accurate, as we do have the yamllint backend which does just that (being a target-less linter)

Sorry for not running on all cylinders here.. failing to make this connection myself.

@kaos
Copy link
Member

kaos commented May 7, 2024

yamllint was added in #17821

@kaos
Copy link
Member

kaos commented May 7, 2024

to be clear, I'm fine keeping this as-is for now as well.. just good to be aware of the alternative to consider going forward :)

@huonw
Copy link
Contributor

huonw commented May 8, 2024

Thanks for the contribution.

When you have a chance, please merge main (or rebase onto it) and add some release notes to docs/notes/2.22.x.md (maybe in a #### NEW: SQL section). See #20888 for more info.

@grihabor
Copy link
Contributor Author

grihabor commented May 8, 2024

add some release notes

@huonw Here you go bb28732

docs/notes/2.22.x.md Outdated Show resolved Hide resolved
Copy link
Member

@kaos kaos 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, thanks!

Let's get this in so we can start iterate on it, if needed :)

@kaos kaos merged commit 16496a6 into pantsbuild:main May 10, 2024
25 checks passed
@ndellosa95
Copy link
Contributor

Looks good, thanks!

Let's get this in so we can start iterate on it, if needed :)

Just saw this and did a double take because I also have a sqlfluff backend in an in-repo plugin designed to work with dbt. We can definitely reconcile what's here and what we have though.

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

Successfully merging this pull request may close these issues.

None yet

6 participants