Skip to content

Conversation

@Hydrocharged
Copy link
Contributor

@Hydrocharged Hydrocharged commented Nov 13, 2025

@Hydrocharged Hydrocharged requested a review from zachmu November 13, 2025 15:55
@Hydrocharged
Copy link
Contributor Author

Also, right now tests are going to fail since they don't include the noop package so the global interface variable is nil, but that's irrelevant to what should be checked right now.

Copy link
Member

@zachmu zachmu left a 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

@Hydrocharged Hydrocharged changed the title Hooks example Explicit Analyzer/Builder Overrides Dec 1, 2025
Copy link
Member

@zachmu zachmu left a 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.


// BuilderOverrides contains functions and variables that can replace, supplement, or override functionality within the
// builder.
type BuilderOverrides struct {
Copy link
Member

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)
Copy link
Member

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.

Copy link
Member

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?

Copy link
Member

@zachmu zachmu left a 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(
Copy link
Member

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 {
Copy link
Member

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()
Copy link
Member

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 {
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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 ""
Copy link
Member

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

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.

3 participants