diff --git a/internal/compiler/compat.go b/internal/compiler/compat.go index ef8c522541..9a443c3b73 100644 --- a/internal/compiler/compat.go +++ b/internal/compiler/compat.go @@ -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: @@ -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 @@ -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) { diff --git a/internal/compiler/to_column.go b/internal/compiler/to_column.go index 14dee0ac2f..5d3153de4e 100644 --- a/internal/compiler/to_column.go +++ b/internal/compiler/to_column.go @@ -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 diff --git a/internal/engine/dolphin/convert.go b/internal/engine/dolphin/convert.go index 744eb538e8..04da047765 100644 --- a/internal/engine/dolphin/convert.go +++ b/internal/engine/dolphin/convert.go @@ -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 { diff --git a/internal/sql/astutils/join.go b/internal/sql/astutils/join.go index 7d2f7829b6..2757e08754 100644 --- a/internal/sql/astutils/join.go +++ b/internal/sql/astutils/join.go @@ -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)