-
-
Notifications
You must be signed in to change notification settings - Fork 237
Explicit Analyzer/Builder Overrides #3303
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
base: main
Are you sure you want to change the base?
Conversation
|
Also, right now tests are going to fail since they don't include the |
zachmu
left a comment
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.
General idea is sound, but let's avoid introducing more globals if we can help it
7830530 to
97ca0b8
Compare
zachmu
left a comment
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.
My main comment is don't put this new information in the context in order to get it to where it needs to go in non-mainline parse contexts. The catalog is a better target for that.
Otherwise I think this plan seems sound.
I think the hooks stuff is harmless enough to leave in with this batch of changes.
sql/planbuilder/builder.go
Outdated
|
|
||
| // BuilderOverrides contains functions and variables that can replace, supplement, or override functionality within the | ||
| // builder. | ||
| type BuilderOverrides 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.
No reason for this to be a struct type, just declare an interface with this method
| err := sql.ErrTableColumnNotFound.New(tblName, colName) | ||
| b.handleErr(err) | ||
| } else if b.overrides.ParseTableAsColumn != nil && inScope.hasTable(colName) { | ||
| scopeTableCols := inScope.resolveColumnAsTable(dbName, colName) |
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.
This logic should probably be entirely in the override handler. Would require exporting some methods from scope and other objects but that's fine.
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.
Going to address this on a future pass?
97ca0b8 to
843c878
Compare
zachmu
left a comment
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.
Looking a lot better, thanks for the changes.
The only additional structural change you should make is to make ExtensionHook into an interface rather than separate structs with func fields.
| ctx, span := s.tracer.Start(ctx, "query") | ||
|
|
||
| context := s.ctxFactory( | ||
| createdCtx := s.ctxFactory( |
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.
Probably just revert this file
| } | ||
|
|
||
| // CreateTable contains hooks related to CREATE TABLE statements. These will take a *plan.CreateTable. | ||
| type CreateTable 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.
These are pretty redundant after the latest refactoring. Seems like an ExecutionHook interface with these two methods would satisfy all these without the repetition. And in general, whenever you func fields in a struct, that's a good sign it should be an interface already.
| // It defaults to MysqlParser. | ||
| var GlobalParser Parser = NewMysqlParser() | ||
| // DefaultMySQLParser is the default MySQL parser. | ||
| var DefaultMySQLParser Parser = NewMysqlParser() |
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.
Aren't these still DefaultParser and DefaultSchemaFormatter? Or are they only referenced in situations where it's clear they're the MySQL one?
|
|
||
| // New takes ctx, catalog, event scheduler, and parser. If the parser is nil, then the default parser is used (which | ||
| // will be the MySQL parser unless modified). | ||
| func New(ctx *sql.Context, cat sql.Catalog, es sql.EventScheduler) *Builder { |
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.
Comment needs an update. Also it seems like the event scheduler should probably live on the catalog too at this point but that's for another day.
| return nil, fmt.Errorf("DefaultStringToExpression expected *sqlparser.AliasedExpr but received %T", parserSelect.SelectExprs[0]) | ||
| } | ||
| proj, _, err := Parse(ctx, nil, fmt.Sprintf("SELECT %s", aliasedExpr.Expr)) | ||
| // TODO: this needs to take a catalog |
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.
Apparently this doesn't break Doltgres? Where is it even used?
| err := sql.ErrTableColumnNotFound.New(tblName, colName) | ||
| b.handleErr(err) | ||
| } else if b.overrides.ParseTableAsColumn != nil && inScope.hasTable(colName) { | ||
| scopeTableCols := inScope.resolveColumnAsTable(dbName, colName) |
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.
Going to address this on a future pass?
| // and column definition statements in order and the collation and character set names for the table | ||
| func GenerateCreateTableStatement(tblName string, colStmts []string, temp, autoInc, tblCharsetName, tblCollName, comment string) string { | ||
| return GlobalSchemaFormatter.GenerateCreateTableStatement(tblName, colStmts, temp, autoInc, tblCharsetName, tblCollName, comment) | ||
| return "" |
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.
Did you mean to leave this like it is?
Either delete if they're now unused, or revert
Related PRs: