-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
schemadiff: validate views' referenced columns via semantics #12565
schemadiff: validate views' referenced columns via semantics #12565
Conversation
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…t views reading from DUAL Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
… expression in DUAL Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
are any more reviews required from @vitessio/query-serving ? |
go/vt/schemadiff/errors.go
Outdated
switch { | ||
case e.Column == "": | ||
return fmt.Sprintf("view %s references non-existent table %s", sqlescape.EscapeID(e.View), sqlescape.EscapeID(e.Table)) | ||
case e.Table != "": | ||
return fmt.Sprintf("view %s references non-existent column %s.%s", sqlescape.EscapeID(e.View), sqlescape.EscapeID(e.Table), sqlescape.EscapeID(e.Column)) | ||
case e.Ambiguous: | ||
return fmt.Sprintf("view %s references unqualified but non unique column %s", sqlescape.EscapeID(e.View), sqlescape.EscapeID(e.Column)) | ||
default: | ||
return fmt.Sprintf("view %s references unqualified but non-existent column %s", sqlescape.EscapeID(e.View), sqlescape.EscapeID(e.Column)) |
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.
the error message looks very fragile based on what struct fields are set.
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.
can we also create the message ahead of time, when the struct is created?
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.
I think that’s actually the wrong pattern. The core is the structured error and the string format is just a detail here.
The structured error removes the issue of string being brittle because anyone wants more details doesn’t look at the string at all.
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.
can we also create the message ahead of time, when the struct is created?
Id' like to avoid that right now in the context of this PR, because that would require us to rewrite all error handling.
Also, I'm really not sure, because we want to be able to create errors using various combination of fields. We don't have a single "constructor" ; we'd need different New*()
function for any combination of fields.
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.
the error message looks very fragile based on what struct fields are set.
I can rewrite that to be more clear
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.
I was able to simplify InvalidColumnReferencedInViewError
by removing unused Table
field and subsequent error message generation cases.
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.
@harshit-gangal allocating the string is also wasteful since when using structured errors it is never used. So I don’t think we should do that.
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.
At the MySQL protocol level, error strings are transferred over the wire, so we might be generating them eventually.
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.
@harshit-gangal this is never used for MySQL level errors. But even then, we’d allocate when needed and not always so then it’s imho still an improvement.
It also improved the ergonomics imho since it’s now easier to create a structured error then.
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
PR seems to suffer a cyclic import path. |
go/vt/schemadiff/semantics.go
Outdated
semantics.FakeSI | ||
} | ||
|
||
func newDeclarativeSchemaInformation() *declarativeSchemaInformation { | ||
return &declarativeSchemaInformation{ | ||
semantics.FakeSI{ | ||
Tables: make(map[string]*vindexes.Table), | ||
}, |
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.
FakeSI is for testing, better to take the field from there and create your own full struct.
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.
fixed
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.
2 comments. Overall looks good.
…formation Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
go/vt/schemadiff/schema.go
Outdated
return errs.AggrError(vterrors.Aggregate) | ||
} | ||
|
||
// getTableColumnNames returns the names of columns in given table. |
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.
// getTableColumnNames returns the names of columns in given table. | |
// getEntityColumnNames returns the names of columns in given table. |
…ndencies Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Depends on #12663 to solve import loop |
…-view-columns-semantics Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Merged |
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
only merge this after #12663 is merged. |
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
An altrnative to #12147, that uses
go/vt/vtgate/semantics
to validate view column references.Description
Up till now,
schemadiff
views validation and analysis was limited to:As of this PR,
schemadiff
also validates columns used and returned by views:SELECT
and inWHERE
clause do in fact exist in tables/views referenced by the view. Error when an unknown column is encountered.create view v as select t.* from t, t2 ...
) or unqualified (create view v as select * from t1,t2
) ; infer list of columns ; support cascaded views based on star expression views.Plenty tests added to validate behavior.
Joint with @dbussink and based on his preliminary work.
Related Issue(s)
Checklist
Deployment Notes