Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion memory/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func stripTblNames(e sql.Expression) (sql.Expression, transform.TreeIdentity, er
case *expression.GetField:
// strip table names
ne := expression.NewGetField(e.Index(), e.Type(), e.Name(), e.IsNullable())
ne = ne.WithQuotedNames(sql.GlobalParser, e.IsQuotedIdentifier())
ne = ne.WithQuotedNames(sql.GlobalSchemaFormatter, e.IsQuotedIdentifier())
return ne, transform.NewTree, nil
default:
}
Expand Down
19 changes: 11 additions & 8 deletions sql/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,15 @@ func (ab *Builder) Build() *Analyzer {
}

return &Analyzer{
Debug: debug || ab.debug,
Verbose: verbose,
contextStack: make([]string, 0),
Batches: batches,
Catalog: NewCatalog(ab.provider),
Coster: memo.NewDefaultCoster(),
ExecBuilder: rowexec.DefaultBuilder,
Parser: sql.GlobalParser,
Debug: debug || ab.debug,
Verbose: verbose,
contextStack: make([]string, 0),
Batches: batches,
Catalog: NewCatalog(ab.provider),
Coster: memo.NewDefaultCoster(),
ExecBuilder: rowexec.DefaultBuilder,
Parser: sql.GlobalParser,
SchemaFormatter: sql.GlobalSchemaFormatter,
}
}

Expand All @@ -296,6 +297,8 @@ type Analyzer struct {
Runner StatementRunner
// Parser is the parser used to parse SQL statements.
Parser sql.Parser
// SchemaFormatter is used to format the schema of a node to a string.
SchemaFormatter sql.SchemaFormatter
}

// NewDefault creates a default Analyzer instance with all default Rules and configuration.
Expand Down
10 changes: 5 additions & 5 deletions sql/analyzer/resolve_column_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func quoteDefaultColumnValueNames(ctx *sql.Context, a *Analyzer, n sql.Node, _ *
switch node := n.(type) {
case *plan.AlterDefaultSet:
eWrapper := expression.WrapExpression(node.Default)
newExpr, same, err := quoteIdentifiers(a.Parser, eWrapper)
newExpr, same, err := quoteIdentifiers(a.SchemaFormatter, eWrapper)
if err != nil {
return node, transform.SameTree, err
}
Expand All @@ -335,7 +335,7 @@ func quoteDefaultColumnValueNames(ctx *sql.Context, a *Analyzer, n sql.Node, _ *
return e, transform.SameTree, nil
}

return quoteIdentifiers(a.Parser, eWrapper)
return quoteIdentifiers(a.SchemaFormatter, eWrapper)
})
case *plan.ResolvedTable:
ct, ok := node.Table.(*information_schema.ColumnsTable)
Expand All @@ -354,7 +354,7 @@ func quoteDefaultColumnValueNames(ctx *sql.Context, a *Analyzer, n sql.Node, _ *
return e, transform.SameTree, nil
}

return quoteIdentifiers(a.Parser, eWrapper)
return quoteIdentifiers(a.SchemaFormatter, eWrapper)
})

if err != nil {
Expand All @@ -376,7 +376,7 @@ func quoteDefaultColumnValueNames(ctx *sql.Context, a *Analyzer, n sql.Node, _ *
})
}

func quoteIdentifiers(parser sql.Parser, wrap *expression.Wrapper) (sql.Expression, transform.TreeIdentity, error) {
func quoteIdentifiers(schemaFormatter sql.SchemaFormatter, wrap *expression.Wrapper) (sql.Expression, transform.TreeIdentity, error) {
newDefault, ok := wrap.Unwrap().(*sql.ColumnDefaultValue)
if !ok {
return wrap, transform.SameTree, nil
Expand All @@ -388,7 +388,7 @@ func quoteIdentifiers(parser sql.Parser, wrap *expression.Wrapper) (sql.Expressi

newExpr, same, err := transform.Expr(newDefault.Expr, func(expr sql.Expression) (sql.Expression, transform.TreeIdentity, error) {
if e, isGf := expr.(*expression.GetField); isGf {
return e.WithQuotedNames(parser, true), transform.NewTree, nil
return e.WithQuotedNames(schemaFormatter, true), transform.NewTree, nil
}
return expr, transform.SameTree, nil
})
Expand Down
2 changes: 1 addition & 1 deletion sql/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ func GetAuthorizationHandlerFactory() AuthorizationHandlerFactory {
if globalAuthorizationHandlerFactory != nil {
return globalAuthorizationHandlerFactory
}
return emptyAuthorizationHandlerFactory{}
return NoopAuthorizationHandlerFactory{}
}
64 changes: 0 additions & 64 deletions sql/auth_empty.go

This file was deleted.

64 changes: 64 additions & 0 deletions sql/auth_noop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2024 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package sql

import (
ast "github.com/dolthub/vitess/go/vt/sqlparser"
)

// NoopAuthorizationHandlerFactory is the AuthorizationHandlerFactory for emptyAuthorizationHandler.
type NoopAuthorizationHandlerFactory struct{}

var _ AuthorizationHandlerFactory = NoopAuthorizationHandlerFactory{}

// CreateHandler implements the AuthorizationHandlerFactory interface.
func (NoopAuthorizationHandlerFactory) CreateHandler(cat Catalog) AuthorizationHandler {
return NoopAuthorizationHandler{}
}

// NoopAuthorizationHandler will always return a "true" result.
type NoopAuthorizationHandler struct{}

var _ AuthorizationHandler = NoopAuthorizationHandler{}

// NewQueryState implements the AuthorizationHandler interface.
func (NoopAuthorizationHandler) NewQueryState(ctx *Context) AuthorizationQueryState {
return nil
}

// HandleAuth implements the AuthorizationHandler interface.
func (NoopAuthorizationHandler) HandleAuth(ctx *Context, aqs AuthorizationQueryState, auth ast.AuthInformation) error {
return nil
}

// HandleAuthNode implements the AuthorizationHandler interface.
func (NoopAuthorizationHandler) HandleAuthNode(ctx *Context, state AuthorizationQueryState, node AuthorizationCheckerNode) error {
return nil
}

// CheckDatabase implements the AuthorizationHandler interface.
func (NoopAuthorizationHandler) CheckDatabase(ctx *Context, aqs AuthorizationQueryState, dbName string) error {
return nil
}

// CheckSchema implements the AuthorizationHandler interface.
func (NoopAuthorizationHandler) CheckSchema(ctx *Context, aqs AuthorizationQueryState, dbName string, schemaName string) error {
return nil
}

// CheckTable implements the AuthorizationHandler interface.
func (NoopAuthorizationHandler) CheckTable(ctx *Context, aqs AuthorizationQueryState, dbName string, schemaName string, tableName string) error {
return nil
}
10 changes: 5 additions & 5 deletions sql/expression/get_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type GetField struct {
fieldType2 sql.Type2
nullable bool

// parser is the parser used to parse the expression and print it
parser sql.Parser
// schemaFormatter is the schemaFormatter used to quote field names
schemaFormatter sql.SchemaFormatter

// quoteName indicates whether the field name should be quoted when printed with String()
quoteName bool
Expand Down Expand Up @@ -170,7 +170,7 @@ func (p *GetField) String() string {
// stripped away. The output of this method is load-bearing in many places of analysis and execution.
if p.table == "" {
if p.quoteName {
return p.parser.QuoteIdentifier(p.name)
return p.schemaFormatter.QuoteIdentifier(p.name)
}
return p.name
}
Expand All @@ -197,10 +197,10 @@ func (p *GetField) WithIndex(n int) sql.Expression {
}

// WithQuotedNames returns a copy of this expression with the backtick names flag set to the given value.
func (p *GetField) WithQuotedNames(parser sql.Parser, quoteNames bool) *GetField {
func (p *GetField) WithQuotedNames(formatter sql.SchemaFormatter, quoteNames bool) *GetField {
p2 := *p
p2.quoteName = quoteNames
p2.parser = parser
p2.schemaFormatter = formatter
return &p2
}

Expand Down
Loading
Loading