Skip to content

Commit

Permalink
Merge pull request #309 from dolthub/daylon/super-type
Browse files Browse the repository at this point in the history
Added a way for Doltgres to inject expressions
  • Loading branch information
Hydrocharged authored Feb 7, 2024
2 parents 429eb81 + aec3497 commit c057d23
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -2613,6 +2613,9 @@ type ColumnType struct {
// The base type string
Type string

// The base type if it has already been resolved
ResolvedType any

// Generic field options.
Null BoolVal
NotNull BoolVal
Expand Down Expand Up @@ -2771,17 +2774,19 @@ func (ct *ColumnType) merge(other ColumnType) error {

// Format returns a canonical string representation of the type and all relevant options
func (ct *ColumnType) Format(buf *TrackedBuffer) {
buf.Myprintf("%s", ct.Type)

if ct.Length != nil && ct.Scale != nil {
buf.Myprintf("(%v,%v)", ct.Length, ct.Scale)

} else if ct.Length != nil {
buf.Myprintf("(%v)", ct.Length)
}
if stringer, ok := ct.ResolvedType.(fmt.Stringer); ok {
buf.WriteString(stringer.String())
} else {
buf.Myprintf("%s", ct.Type)
if ct.Length != nil && ct.Scale != nil {
buf.Myprintf("(%v,%v)", ct.Length, ct.Scale)

if len(ct.EnumValues) > 0 {
buf.Myprintf("('%s')", strings.Join(ct.EnumValues, "', '"))
} else if ct.Length != nil {
buf.Myprintf("(%v)", ct.Length)
}
if len(ct.EnumValues) > 0 {
buf.Myprintf("('%s')", strings.Join(ct.EnumValues, "', '"))
}
}

opts := make([]string, 0, 16)
Expand Down Expand Up @@ -7224,3 +7229,25 @@ func (node *SrsAttribute) Format(buf *TrackedBuffer) {
buf.Myprintf("organization '%s' identified by %v\n", node.Organization, node.OrgID)
buf.Myprintf("description '%s'", node.Description)
}

// InjectedExpr allows bypassing AST analysis. This is used by projects that rely on Vitess, but may not implement
// MySQL's dialect.
type InjectedExpr struct {
Expression any
}

var _ Expr = InjectedExpr{}

func (d InjectedExpr) iExpr() {}

func (d InjectedExpr) replace(from, to Expr) bool {
return false
}

func (d InjectedExpr) Format(buf *TrackedBuffer) {
if stringer, ok := d.Expression.(fmt.Stringer); ok {
buf.WriteString(stringer.String())
} else {
buf.WriteString("InjectedExpr")
}
}

0 comments on commit c057d23

Please sign in to comment.