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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(normalized): table and column names should not be normalized
fix(normalized): table and column names should not be normalized
  • Loading branch information
Ahmad Berahman committed Aug 1, 2024
commit df7921661b4756c81ab2d2cf8b7de608085ed2b9
2 changes: 1 addition & 1 deletion internal/codegen/golang/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func argName(name string) string {
out := ""
for i, p := range strings.Split(name, "_") {
if i == 0 {
out += strings.ToLower(p)
out += p
} else if p == "id" {
out += "ID"
} else {
Expand Down
23 changes: 9 additions & 14 deletions internal/engine/dolphin/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dolphin

import (
"log"
"strings"

pcast "github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pingcap/tidb/pkg/parser/mysql"
Expand All @@ -25,12 +24,8 @@ func todo(n pcast.Node) *ast.TODO {
return &ast.TODO{}
}

func identifier(id string) string {
return strings.ToLower(id)
}

func NewIdentifier(t string) *ast.String {
return &ast.String{Str: identifier(t)}
return &ast.String{Str: t}
}

func (c *cc) convertAlterTableStmt(n *pcast.AlterTableStmt) ast.Node {
Expand Down Expand Up @@ -122,7 +117,7 @@ func (c *cc) convertAlterTableStmt(n *pcast.AlterTableStmt) ast.Node {
}

func (c *cc) convertAssignment(n *pcast.Assignment) *ast.ResTarget {
name := identifier(n.Column.Name.String())
name := n.Column.Name.String()
return &ast.ResTarget{
Name: &name,
Val: c.convert(n.Expr),
Expand Down Expand Up @@ -250,7 +245,7 @@ func convertColumnDef(def *pcast.ColumnDef) *ast.ColumnDef {
}
}
columnDef := ast.ColumnDef{
Colname: def.Name.String(),
Colname: def.Name.Name.O,
TypeName: &ast.TypeName{Name: types.TypeToStr(def.Tp.GetType(), def.Tp.GetCharset())},
IsNotNull: isNotNull(def),
IsUnsigned: isUnsigned(def),
Expand Down Expand Up @@ -285,7 +280,7 @@ func (c *cc) convertColumnNameExpr(n *pcast.ColumnNameExpr) *ast.ColumnRef {
func (c *cc) convertColumnNames(cols []*pcast.ColumnName) *ast.List {
list := &ast.List{Items: []ast.Node{}}
for i := range cols {
name := identifier(cols[i].Name.String())
name := cols[i].Name.String()
list.Items = append(list.Items, &ast.ResTarget{
Name: &name,
})
Expand Down Expand Up @@ -350,7 +345,7 @@ func (c *cc) convertFieldList(n *pcast.FieldList) *ast.List {

func (c *cc) convertFuncCallExpr(n *pcast.FuncCallExpr) ast.Node {
schema := n.Schema.String()
name := strings.ToLower(n.FnName.String())
name := n.FnName.String()

// TODO: Deprecate the usage of Funcname
items := []ast.Node{}
Expand Down Expand Up @@ -454,7 +449,7 @@ func (c *cc) convertSelectField(n *pcast.SelectField) *ast.ResTarget {
}
var name *string
if n.AsName.O != "" {
asname := identifier(n.AsName.O)
asname := n.AsName.O
name = &asname
}
return &ast.ResTarget{
Expand Down Expand Up @@ -630,7 +625,7 @@ func (c *cc) convertAdminStmt(n *pcast.AdminStmt) ast.Node {
}

func (c *cc) convertAggregateFuncExpr(n *pcast.AggregateFuncExpr) *ast.FuncCall {
name := strings.ToLower(n.F)
name := n.F
fn := &ast.FuncCall{
Func: &ast.FuncName{
Name: name,
Expand Down Expand Up @@ -1289,8 +1284,8 @@ func (c *cc) convertSplitRegionStmt(n *pcast.SplitRegionStmt) ast.Node {
}

func (c *cc) convertTableName(n *pcast.TableName) *ast.RangeVar {
schema := identifier(n.Schema.String())
rel := identifier(n.Name.String())
schema := n.Schema.String()
rel := n.Name.String()
return &ast.RangeVar{
Schemaname: &schema,
Relname: &rel,
Expand Down
4 changes: 2 additions & 2 deletions internal/engine/dolphin/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

func parseTableName(n *pcast.TableName) *ast.TableName {
return &ast.TableName{
Schema: identifier(n.Schema.String()),
Name: identifier(n.Name.String()),
Schema: n.Schema.String(),
Name: n.Name.String(),
}
}

Expand Down