Skip to content
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

Implement cast function parser for MySQL #2020

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 12 additions & 9 deletions internal/compiler/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ type Relation struct {
}

func parseRelation(node ast.Node) (*Relation, error) {
switch n := node.(type) {

case *ast.List:
if n, ok := node.(*ast.List); ok && n != nil {
parts := stringSlice(n)
switch len(parts) {
case 1:
Expand All @@ -54,8 +52,9 @@ func parseRelation(node ast.Node) (*Relation, error) {
default:
return nil, fmt.Errorf("invalid name: %s", astutils.Join(n, "."))
}
}

case *ast.RangeVar:
if n, ok := node.(*ast.RangeVar); ok && n != nil {
name := Relation{}
if n.Catalogname != nil {
name.Catalog = *n.Catalogname
Expand All @@ -67,13 +66,17 @@ func parseRelation(node ast.Node) (*Relation, error) {
name.Name = *n.Relname
}
return &name, nil
}

case *ast.TypeName:
return parseRelation(n.Names)

default:
return nil, fmt.Errorf("unexpected node type: %T", n)
if n, ok := node.(*ast.TypeName); ok && n != nil {
if n.Names != nil {
return parseRelation(n.Names)
} else {
return &Relation{Name: n.Name}, nil
}
}

return nil, fmt.Errorf("unexpected node type: %T", node)
}

func ParseTableName(node ast.Node) (*ast.TableName, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/to_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func isArray(n *ast.TypeName) bool {
if n == nil {
if n == nil || n.ArrayBounds == nil {
return false
}
return len(n.ArrayBounds.Items) > 0
Expand Down
5 changes: 4 additions & 1 deletion internal/engine/dolphin/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,10 @@ func (c *cc) convertFrameClause(n *pcast.FrameClause) ast.Node {
}

func (c *cc) convertFuncCastExpr(n *pcast.FuncCastExpr) ast.Node {
return todo(n)
return &ast.TypeCast{
Arg: c.convert(n.Expr),
TypeName: &ast.TypeName{Name: types.TypeStr(n.Tp.GetType())},
}
}

func (c *cc) convertGetFormatSelectorExpr(n *pcast.GetFormatSelectorExpr) ast.Node {
Expand Down
6 changes: 5 additions & 1 deletion internal/sql/astutils/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import (
)

func Join(list *ast.List, sep string) string {
items := []string{}
if list == nil {
return ""
}

var items []string
for _, item := range list.Items {
if n, ok := item.(*ast.String); ok {
items = append(items, n.Str)
Expand Down