-
Notifications
You must be signed in to change notification settings - Fork 188
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
Feat!: Introduce Model linting #3787
base: main
Are you sure you want to change the base?
Conversation
cbdeab5
to
8f456d4
Compare
8f456d4
to
e60106e
Compare
e60106e
to
c90f22c
Compare
2c3e92e
to
7116a75
Compare
PS: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exciting stuff!
7116a75
to
f9c6ae2
Compare
f9c6ae2
to
7beea0b
Compare
sqlmesh/core/linter/rule.py
Outdated
self._name = name or self.__class__.__name__.lower() | ||
|
||
@abc.abstractmethod | ||
def check(self, model: Model) -> t.Optional[RuleViolation]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on this type signature it seems like rules can only check for a single violation within a model, but what if there are multiple violations of the same rule in a model? What gets shown to the end user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, my idea was that a RuleViolation
will be indeed singular per rule but if there's multiple violations we can store their context in a collection.
For instance, if we have a rule that detects a certain faulty pattern in a query, I thought it'd look somewhat odd to have N x RuleViolation(..., expr: exp.Expression)
instead of a single RuleViolation(..., exprs: t.List[exp.Expression])
; The former looks like it's more polluting for now and increases the complexity which we are now trying to avoid based on internal discussions.
How does that sound?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that probably works too.
@VaggelisD is it possible to create configurable rules, and if so, how is that done? |
Fixes #3753
This PR introduces a new interface for a general purpose
Model
linter:Rule
checks for a specific lint error; If a violation is found, aRuleViolation
is created with the proper contextRuleSet
s; EachRuleSet
acts as both a set and a mapping (rule class name -> rule type).Linter
applies theRuleSets
on the model and outputs warnings / raises errors depending on their severityThe linter configuration along with the default values is the following:
This is to preserve the behavior of
QueryRenderer
today; For this matter,validate_query
is deprecated and instead the corresponding checks are implemented as rules in the Linter.On a model granularity, rules can be ignored by the new
ignore_lints
attribute:Users can implement their own lint rules in a
linter/
directory by subclassingRule
; These will be automatically picked up at load time: