convert.go 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754
  1. package dolphin
  2. import (
  3. "fmt"
  4. "log"
  5. "strings"
  6. pcast "github.com/pingcap/parser/ast"
  7. "github.com/pingcap/parser/opcode"
  8. driver "github.com/pingcap/parser/test_driver"
  9. "github.com/pingcap/parser/types"
  10. "github.com/kyleconroy/sqlc/internal/debug"
  11. "github.com/kyleconroy/sqlc/internal/sql/ast"
  12. )
  13. type cc struct {
  14. paramCount int
  15. }
  16. func todo(n pcast.Node) *ast.TODO {
  17. if debug.Active {
  18. log.Printf("dolphin.convert: Unknown node type %T\n", n)
  19. }
  20. return &ast.TODO{}
  21. }
  22. func identifier(id string) string {
  23. return strings.ToLower(id)
  24. }
  25. func NewIdentifer(t string) *ast.String {
  26. return &ast.String{Str: identifier(t)}
  27. }
  28. func (c *cc) convertAlterTableStmt(n *pcast.AlterTableStmt) ast.Node {
  29. alt := &ast.AlterTableStmt{
  30. Table: parseTableName(n.Table),
  31. Cmds: &ast.List{},
  32. }
  33. for _, spec := range n.Specs {
  34. switch spec.Tp {
  35. case pcast.AlterTableAddColumns:
  36. for _, def := range spec.NewColumns {
  37. name := def.Name.String()
  38. columnDef := ast.ColumnDef{
  39. Colname: def.Name.String(),
  40. TypeName: &ast.TypeName{Name: types.TypeStr(def.Tp.Tp)},
  41. IsNotNull: isNotNull(def),
  42. }
  43. if def.Tp.Flen >= 0 {
  44. length := def.Tp.Flen
  45. columnDef.Length = &length
  46. }
  47. alt.Cmds.Items = append(alt.Cmds.Items, &ast.AlterTableCmd{
  48. Name: &name,
  49. Subtype: ast.AT_AddColumn,
  50. Def: &columnDef,
  51. })
  52. }
  53. case pcast.AlterTableDropColumn:
  54. name := spec.OldColumnName.String()
  55. alt.Cmds.Items = append(alt.Cmds.Items, &ast.AlterTableCmd{
  56. Name: &name,
  57. Subtype: ast.AT_DropColumn,
  58. MissingOk: spec.IfExists,
  59. })
  60. case pcast.AlterTableChangeColumn:
  61. // spew.Dump("change column", spec)
  62. case pcast.AlterTableModifyColumn:
  63. for _, def := range spec.NewColumns {
  64. name := def.Name.String()
  65. columnDef := ast.ColumnDef{
  66. Colname: def.Name.String(),
  67. TypeName: &ast.TypeName{Name: types.TypeStr(def.Tp.Tp)},
  68. IsNotNull: isNotNull(def),
  69. }
  70. if def.Tp.Flen >= 0 {
  71. length := def.Tp.Flen
  72. columnDef.Length = &length
  73. }
  74. alt.Cmds.Items = append(alt.Cmds.Items, &ast.AlterTableCmd{
  75. Name: &name,
  76. Subtype: ast.AT_DropColumn,
  77. })
  78. alt.Cmds.Items = append(alt.Cmds.Items, &ast.AlterTableCmd{
  79. Name: &name,
  80. Subtype: ast.AT_AddColumn,
  81. Def: &columnDef,
  82. })
  83. }
  84. case pcast.AlterTableAlterColumn:
  85. // spew.Dump("alter column", spec)
  86. case pcast.AlterTableAddConstraint:
  87. // spew.Dump("add const", spec)
  88. case pcast.AlterTableRenameColumn:
  89. // TODO: Returning here may be incorrect if there are multiple specs
  90. oldName := spec.OldColumnName.String()
  91. newName := spec.NewColumnName.String()
  92. return &ast.RenameColumnStmt{
  93. Table: parseTableName(n.Table),
  94. Col: &ast.ColumnRef{Name: oldName},
  95. NewName: &newName,
  96. }
  97. case pcast.AlterTableRenameTable:
  98. // TODO: Returning here may be incorrect if there are multiple specs
  99. return &ast.RenameTableStmt{
  100. Table: parseTableName(n.Table),
  101. NewName: &parseTableName(spec.NewTable).Name,
  102. }
  103. default:
  104. if debug.Active {
  105. fmt.Printf("dolphin.convert: Unknown alter table cmd %v\n", spec.Tp)
  106. }
  107. continue
  108. }
  109. }
  110. return alt
  111. }
  112. func (c *cc) convertAssignment(n *pcast.Assignment) *ast.ResTarget {
  113. name := identifier(n.Column.Name.String())
  114. return &ast.ResTarget{
  115. Name: &name,
  116. Val: c.convert(n.Expr),
  117. }
  118. }
  119. // TODO: These codes should be defined in the sql/lang package
  120. func opToName(o opcode.Op) string {
  121. switch o {
  122. // case opcode.And:
  123. // case opcode.BitNeg:
  124. // case opcode.Case:
  125. // case opcode.Div:
  126. case opcode.EQ:
  127. return "="
  128. case opcode.GE:
  129. return ">="
  130. case opcode.GT:
  131. return ">"
  132. // case opcode.In:
  133. case opcode.IntDiv:
  134. return "/"
  135. // case opcode.IsFalsity:
  136. // case opcode.IsNull:
  137. // case opcode.IsTruth:
  138. case opcode.LE:
  139. return "<="
  140. case opcode.LT:
  141. return "<"
  142. case opcode.LeftShift:
  143. return "<<"
  144. // case opcode.Like:
  145. case opcode.LogicAnd:
  146. return "&"
  147. case opcode.LogicOr:
  148. return "|"
  149. // case opcode.LogicXor:
  150. case opcode.Minus:
  151. return "-"
  152. case opcode.Mod:
  153. return "%"
  154. case opcode.Mul:
  155. return "*"
  156. case opcode.NE:
  157. return "!="
  158. case opcode.Not:
  159. return "!"
  160. // case opcode.NullEQ:
  161. // case opcode.Or:
  162. case opcode.Plus:
  163. return "+"
  164. case opcode.Regexp:
  165. return "~"
  166. case opcode.RightShift:
  167. return ">>"
  168. case opcode.Xor:
  169. return "#"
  170. default:
  171. return o.String()
  172. }
  173. }
  174. func (c *cc) convertBinaryOperationExpr(n *pcast.BinaryOperationExpr) ast.Node {
  175. if n.Op == opcode.LogicAnd || n.Op == opcode.LogicOr {
  176. return &ast.BoolExpr{
  177. // TODO: Set op
  178. Args: &ast.List{
  179. Items: []ast.Node{
  180. c.convert(n.L),
  181. c.convert(n.R),
  182. },
  183. },
  184. }
  185. } else {
  186. return &ast.A_Expr{
  187. // TODO: Set kind
  188. Name: &ast.List{
  189. Items: []ast.Node{
  190. &ast.String{Str: opToName(n.Op)},
  191. },
  192. },
  193. Lexpr: c.convert(n.L),
  194. Rexpr: c.convert(n.R),
  195. }
  196. }
  197. }
  198. func (c *cc) convertCreateTableStmt(n *pcast.CreateTableStmt) ast.Node {
  199. create := &ast.CreateTableStmt{
  200. Name: parseTableName(n.Table),
  201. IfNotExists: n.IfNotExists,
  202. }
  203. if n.ReferTable != nil {
  204. create.ReferTable = parseTableName(n.ReferTable)
  205. }
  206. for _, def := range n.Cols {
  207. var vals *ast.List
  208. if len(def.Tp.Elems) > 0 {
  209. vals = &ast.List{}
  210. for i := range def.Tp.Elems {
  211. vals.Items = append(vals.Items, &ast.String{
  212. Str: def.Tp.Elems[i],
  213. })
  214. }
  215. }
  216. comment := ""
  217. for _, opt := range def.Options {
  218. switch opt.Tp {
  219. case pcast.ColumnOptionComment:
  220. if value, ok := opt.Expr.(*driver.ValueExpr); ok {
  221. comment = value.GetString()
  222. }
  223. }
  224. }
  225. columnDef := ast.ColumnDef{
  226. Colname: def.Name.String(),
  227. TypeName: &ast.TypeName{Name: types.TypeStr(def.Tp.Tp)},
  228. IsNotNull: isNotNull(def),
  229. Comment: comment,
  230. Vals: vals,
  231. }
  232. if def.Tp.Flen >= 0 {
  233. length := def.Tp.Flen
  234. columnDef.Length = &length
  235. }
  236. create.Cols = append(create.Cols, &columnDef)
  237. }
  238. for _, opt := range n.Options {
  239. switch opt.Tp {
  240. case pcast.TableOptionComment:
  241. create.Comment = opt.StrValue
  242. }
  243. }
  244. return create
  245. }
  246. func (c *cc) convertColumnNameExpr(n *pcast.ColumnNameExpr) *ast.ColumnRef {
  247. var items []ast.Node
  248. if schema := n.Name.Schema.String(); schema != "" {
  249. items = append(items, NewIdentifer(schema))
  250. }
  251. if table := n.Name.Table.String(); table != "" {
  252. items = append(items, NewIdentifer(table))
  253. }
  254. items = append(items, NewIdentifer(n.Name.Name.String()))
  255. return &ast.ColumnRef{
  256. Fields: &ast.List{
  257. Items: items,
  258. },
  259. }
  260. }
  261. func (c *cc) convertColumnNames(cols []*pcast.ColumnName) *ast.List {
  262. list := &ast.List{Items: []ast.Node{}}
  263. for i := range cols {
  264. name := identifier(cols[i].Name.String())
  265. list.Items = append(list.Items, &ast.ResTarget{
  266. Name: &name,
  267. })
  268. }
  269. return list
  270. }
  271. func (c *cc) convertDeleteStmt(n *pcast.DeleteStmt) *ast.DeleteStmt {
  272. rels := c.convertTableRefsClause(n.TableRefs)
  273. if len(rels.Items) != 1 {
  274. panic("expected one range var")
  275. }
  276. rel := rels.Items[0]
  277. rangeVar, ok := rel.(*ast.RangeVar)
  278. if !ok {
  279. panic("expected range var")
  280. }
  281. return &ast.DeleteStmt{
  282. Relation: rangeVar,
  283. WhereClause: c.convert(n.Where),
  284. ReturningList: &ast.List{},
  285. WithClause: c.convertWithClause(n.With),
  286. }
  287. }
  288. func (c *cc) convertDropTableStmt(n *pcast.DropTableStmt) ast.Node {
  289. drop := &ast.DropTableStmt{IfExists: n.IfExists}
  290. for _, name := range n.Tables {
  291. drop.Tables = append(drop.Tables, parseTableName(name))
  292. }
  293. return drop
  294. }
  295. func (c *cc) convertRenameTableStmt(n *pcast.RenameTableStmt) ast.Node {
  296. list := &ast.List{Items: []ast.Node{}}
  297. for _, table := range n.TableToTables {
  298. list.Items = append(list.Items, &ast.RenameTableStmt{
  299. Table: parseTableName(table.OldTable),
  300. NewName: &parseTableName(table.NewTable).Name,
  301. })
  302. }
  303. return list
  304. }
  305. func (c *cc) convertExistsSubqueryExpr(n *pcast.ExistsSubqueryExpr) *ast.SubLink {
  306. sublink := &ast.SubLink{}
  307. if ss, ok := c.convert(n.Sel).(*ast.SelectStmt); ok {
  308. sublink.Subselect = ss
  309. }
  310. return sublink
  311. }
  312. func (c *cc) convertFieldList(n *pcast.FieldList) *ast.List {
  313. fields := make([]ast.Node, len(n.Fields))
  314. for i := range n.Fields {
  315. fields[i] = c.convertSelectField(n.Fields[i])
  316. }
  317. return &ast.List{Items: fields}
  318. }
  319. func (c *cc) convertFuncCallExpr(n *pcast.FuncCallExpr) ast.Node {
  320. schema := n.Schema.String()
  321. name := strings.ToLower(n.FnName.String())
  322. // TODO: Deprecate the usage of Funcname
  323. items := []ast.Node{}
  324. if schema != "" {
  325. items = append(items, NewIdentifer(schema))
  326. }
  327. items = append(items, NewIdentifer(name))
  328. args := &ast.List{}
  329. for _, arg := range n.Args {
  330. args.Items = append(args.Items, c.convert(arg))
  331. }
  332. if schema == "" && name == "coalesce" {
  333. return &ast.CoalesceExpr{
  334. Args: args,
  335. }
  336. } else {
  337. return &ast.FuncCall{
  338. Args: args,
  339. Func: &ast.FuncName{
  340. Schema: schema,
  341. Name: name,
  342. },
  343. Funcname: &ast.List{
  344. Items: items,
  345. },
  346. Location: n.OriginTextPosition(),
  347. }
  348. }
  349. }
  350. func (c *cc) convertInsertStmt(n *pcast.InsertStmt) *ast.InsertStmt {
  351. rels := c.convertTableRefsClause(n.Table)
  352. if len(rels.Items) != 1 {
  353. panic("expected one range var")
  354. }
  355. rel := rels.Items[0]
  356. rangeVar, ok := rel.(*ast.RangeVar)
  357. if !ok {
  358. panic("expected range var")
  359. }
  360. // debug.Dump(n)
  361. insert := &ast.InsertStmt{
  362. Relation: rangeVar,
  363. Cols: c.convertColumnNames(n.Columns),
  364. ReturningList: &ast.List{},
  365. }
  366. if ss, ok := c.convert(n.Select).(*ast.SelectStmt); ok {
  367. ss.ValuesLists = c.convertLists(n.Lists)
  368. insert.SelectStmt = ss
  369. } else {
  370. insert.SelectStmt = &ast.SelectStmt{
  371. FromClause: &ast.List{},
  372. TargetList: &ast.List{},
  373. ValuesLists: c.convertLists(n.Lists),
  374. }
  375. }
  376. if n.OnDuplicate != nil {
  377. targetList := &ast.List{}
  378. for _, a := range n.OnDuplicate {
  379. targetList.Items = append(targetList.Items, c.convertAssignment(a))
  380. }
  381. insert.OnConflictClause = &ast.OnConflictClause{
  382. TargetList: targetList,
  383. Location: n.OriginTextPosition(),
  384. }
  385. }
  386. return insert
  387. }
  388. func (c *cc) convertLists(lists [][]pcast.ExprNode) *ast.List {
  389. list := &ast.List{Items: []ast.Node{}}
  390. for _, exprs := range lists {
  391. inner := &ast.List{Items: []ast.Node{}}
  392. for _, expr := range exprs {
  393. inner.Items = append(inner.Items, c.convert(expr))
  394. }
  395. list.Items = append(list.Items, inner)
  396. }
  397. return list
  398. }
  399. func (c *cc) convertParamMarkerExpr(n *driver.ParamMarkerExpr) *ast.ParamRef {
  400. // Parameter numbers start at one
  401. c.paramCount += 1
  402. return &ast.ParamRef{
  403. Number: c.paramCount,
  404. Location: n.Offset,
  405. }
  406. }
  407. func (c *cc) convertSelectField(n *pcast.SelectField) *ast.ResTarget {
  408. var val ast.Node
  409. if n.WildCard != nil {
  410. val = c.convertWildCardField(n.WildCard)
  411. } else {
  412. val = c.convert(n.Expr)
  413. }
  414. var name *string
  415. if n.AsName.O != "" {
  416. asname := identifier(n.AsName.O)
  417. name = &asname
  418. }
  419. return &ast.ResTarget{
  420. // TODO: Populate Indirection field
  421. Name: name,
  422. Val: val,
  423. Location: n.Offset,
  424. }
  425. }
  426. func (c *cc) convertSelectStmt(n *pcast.SelectStmt) *ast.SelectStmt {
  427. windowClause := &ast.List{Items: make([]ast.Node, 0)}
  428. orderByClause := c.convertOrderByClause(n.OrderBy)
  429. if orderByClause != nil {
  430. windowClause.Items = append(windowClause.Items, orderByClause)
  431. }
  432. op, all := c.convertSetOprType(n.AfterSetOperator)
  433. stmt := &ast.SelectStmt{
  434. TargetList: c.convertFieldList(n.Fields),
  435. FromClause: c.convertTableRefsClause(n.From),
  436. GroupClause: c.convertGroupByClause(n.GroupBy),
  437. WhereClause: c.convert(n.Where),
  438. WithClause: c.convertWithClause(n.With),
  439. WindowClause: windowClause,
  440. Op: op,
  441. All: all,
  442. }
  443. if n.Limit != nil {
  444. stmt.LimitCount = c.convert(n.Limit.Count)
  445. stmt.LimitOffset = c.convert(n.Limit.Offset)
  446. }
  447. return stmt
  448. }
  449. func (c *cc) convertSubqueryExpr(n *pcast.SubqueryExpr) ast.Node {
  450. return c.convert(n.Query)
  451. }
  452. func (c *cc) convertTableRefsClause(n *pcast.TableRefsClause) *ast.List {
  453. if n == nil {
  454. return &ast.List{}
  455. }
  456. return c.convertJoin(n.TableRefs)
  457. }
  458. func (c *cc) convertCommonTableExpression(n *pcast.CommonTableExpression) *ast.CommonTableExpr {
  459. if n == nil {
  460. return nil
  461. }
  462. name := n.Name.String()
  463. columns := &ast.List{}
  464. for _, col := range n.ColNameList {
  465. columns.Items = append(columns.Items, NewIdentifer(col.String()))
  466. }
  467. return &ast.CommonTableExpr{
  468. Ctename: &name,
  469. Ctequery: c.convert(n.Query),
  470. Ctecolnames: columns,
  471. }
  472. }
  473. func (c *cc) convertWithClause(n *pcast.WithClause) *ast.WithClause {
  474. if n == nil {
  475. return nil
  476. }
  477. list := &ast.List{}
  478. for _, n := range n.CTEs {
  479. list.Items = append(list.Items, c.convertCommonTableExpression(n))
  480. }
  481. return &ast.WithClause{
  482. Ctes: list,
  483. Recursive: n.IsRecursive,
  484. Location: n.OriginTextPosition(),
  485. }
  486. }
  487. func (c *cc) convertUpdateStmt(n *pcast.UpdateStmt) *ast.UpdateStmt {
  488. rels := c.convertTableRefsClause(n.TableRefs)
  489. if len(rels.Items) != 1 {
  490. panic("expected one range var")
  491. }
  492. relations := &ast.List{}
  493. switch rel := rels.Items[0].(type) {
  494. // Special case for joins in updates
  495. case *ast.JoinExpr:
  496. left, ok := rel.Larg.(*ast.RangeVar)
  497. if !ok {
  498. panic("expected range var")
  499. }
  500. relations.Items = append(relations.Items, left)
  501. right, ok := rel.Rarg.(*ast.RangeVar)
  502. if !ok {
  503. panic("expected range var")
  504. }
  505. relations.Items = append(relations.Items, right)
  506. case *ast.RangeVar:
  507. relations.Items = append(relations.Items, rel)
  508. default:
  509. panic("expected range var")
  510. }
  511. // TargetList
  512. list := &ast.List{}
  513. for _, a := range n.List {
  514. list.Items = append(list.Items, c.convertAssignment(a))
  515. }
  516. return &ast.UpdateStmt{
  517. Relations: relations,
  518. TargetList: list,
  519. WhereClause: c.convert(n.Where),
  520. FromClause: &ast.List{},
  521. ReturningList: &ast.List{},
  522. WithClause: c.convertWithClause(n.With),
  523. }
  524. }
  525. func (c *cc) convertValueExpr(n *driver.ValueExpr) *ast.A_Const {
  526. return &ast.A_Const{
  527. Val: &ast.String{
  528. Str: n.Datum.GetString(),
  529. },
  530. }
  531. }
  532. func (c *cc) convertWildCardField(n *pcast.WildCardField) *ast.ColumnRef {
  533. items := []ast.Node{}
  534. if t := n.Table.String(); t != "" {
  535. items = append(items, NewIdentifer(t))
  536. }
  537. items = append(items, &ast.A_Star{})
  538. return &ast.ColumnRef{
  539. Fields: &ast.List{
  540. Items: items,
  541. },
  542. }
  543. }
  544. func (c *cc) convertAdminStmt(n *pcast.AdminStmt) ast.Node {
  545. return todo(n)
  546. }
  547. func (c *cc) convertAggregateFuncExpr(n *pcast.AggregateFuncExpr) *ast.FuncCall {
  548. name := strings.ToLower(n.F)
  549. fn := &ast.FuncCall{
  550. Func: &ast.FuncName{
  551. Name: name,
  552. },
  553. Funcname: &ast.List{
  554. Items: []ast.Node{
  555. NewIdentifer(name),
  556. },
  557. },
  558. Args: &ast.List{},
  559. AggOrder: &ast.List{},
  560. }
  561. for _, a := range n.Args {
  562. if value, ok := a.(*driver.ValueExpr); ok {
  563. if value.GetInt64() == int64(1) {
  564. fn.AggStar = true
  565. continue
  566. }
  567. }
  568. fn.Args.Items = append(fn.Args.Items, c.convert(a))
  569. }
  570. if n.Distinct {
  571. fn.AggDistinct = true
  572. }
  573. return fn
  574. }
  575. func (c *cc) convertAlterDatabaseStmt(n *pcast.AlterDatabaseStmt) ast.Node {
  576. return todo(n)
  577. }
  578. func (c *cc) convertAlterInstanceStmt(n *pcast.AlterInstanceStmt) ast.Node {
  579. return todo(n)
  580. }
  581. func (c *cc) convertAlterTableSpec(n *pcast.AlterTableSpec) ast.Node {
  582. return todo(n)
  583. }
  584. func (c *cc) convertAlterUserStmt(n *pcast.AlterUserStmt) ast.Node {
  585. return todo(n)
  586. }
  587. func (c *cc) convertAnalyzeTableStmt(n *pcast.AnalyzeTableStmt) ast.Node {
  588. return todo(n)
  589. }
  590. func (c *cc) convertBRIEStmt(n *pcast.BRIEStmt) ast.Node {
  591. return todo(n)
  592. }
  593. func (c *cc) convertBeginStmt(n *pcast.BeginStmt) ast.Node {
  594. return todo(n)
  595. }
  596. func (c *cc) convertBetweenExpr(n *pcast.BetweenExpr) ast.Node {
  597. return &ast.BetweenExpr{
  598. Expr: c.convert(n.Expr),
  599. Left: c.convert(n.Left),
  600. Right: c.convert(n.Right),
  601. Location: n.OriginTextPosition(),
  602. Not: n.Not,
  603. }
  604. }
  605. func (c *cc) convertBinlogStmt(n *pcast.BinlogStmt) ast.Node {
  606. return todo(n)
  607. }
  608. func (c *cc) convertByItem(n *pcast.ByItem) ast.Node {
  609. switch n.Expr.(type) {
  610. case *pcast.PositionExpr:
  611. return c.convertPositionExpr(n.Expr.(*pcast.PositionExpr))
  612. case *pcast.ColumnNameExpr:
  613. return c.convertColumnNameExpr(n.Expr.(*pcast.ColumnNameExpr))
  614. default:
  615. return todo(n)
  616. }
  617. }
  618. func (c *cc) convertCaseExpr(n *pcast.CaseExpr) ast.Node {
  619. if n == nil {
  620. return nil
  621. }
  622. list := &ast.List{Items: []ast.Node{}}
  623. for _, n := range n.WhenClauses {
  624. list.Items = append(list.Items, c.convertWhenClause(n))
  625. }
  626. return &ast.CaseExpr{
  627. Args: list,
  628. Defresult: c.convert(n.ElseClause),
  629. Location: n.OriginTextPosition(),
  630. }
  631. }
  632. func (c *cc) convertChangeStmt(n *pcast.ChangeStmt) ast.Node {
  633. return todo(n)
  634. }
  635. func (c *cc) convertCleanupTableLockStmt(n *pcast.CleanupTableLockStmt) ast.Node {
  636. return todo(n)
  637. }
  638. func (c *cc) convertColumnDef(n *pcast.ColumnDef) ast.Node {
  639. return todo(n)
  640. }
  641. func (c *cc) convertColumnName(n *pcast.ColumnName) ast.Node {
  642. return todo(n)
  643. }
  644. func (c *cc) convertColumnPosition(n *pcast.ColumnPosition) ast.Node {
  645. return todo(n)
  646. }
  647. func (c *cc) convertCommitStmt(n *pcast.CommitStmt) ast.Node {
  648. return todo(n)
  649. }
  650. func (c *cc) convertCompareSubqueryExpr(n *pcast.CompareSubqueryExpr) ast.Node {
  651. return todo(n)
  652. }
  653. func (c *cc) convertConstraint(n *pcast.Constraint) ast.Node {
  654. return todo(n)
  655. }
  656. func (c *cc) convertCreateBindingStmt(n *pcast.CreateBindingStmt) ast.Node {
  657. return todo(n)
  658. }
  659. func (c *cc) convertCreateDatabaseStmt(n *pcast.CreateDatabaseStmt) ast.Node {
  660. return &ast.CreateSchemaStmt{
  661. Name: &n.Name,
  662. IfNotExists: n.IfNotExists,
  663. }
  664. }
  665. func (c *cc) convertCreateIndexStmt(n *pcast.CreateIndexStmt) ast.Node {
  666. return todo(n)
  667. }
  668. func (c *cc) convertCreateSequenceStmt(n *pcast.CreateSequenceStmt) ast.Node {
  669. return todo(n)
  670. }
  671. func (c *cc) convertCreateStatisticsStmt(n *pcast.CreateStatisticsStmt) ast.Node {
  672. return todo(n)
  673. }
  674. func (c *cc) convertCreateUserStmt(n *pcast.CreateUserStmt) ast.Node {
  675. return todo(n)
  676. }
  677. func (c *cc) convertCreateViewStmt(n *pcast.CreateViewStmt) ast.Node {
  678. return &ast.ViewStmt{
  679. View: c.convertTableName(n.ViewName),
  680. Aliases: &ast.List{},
  681. Query: c.convert(n.Select),
  682. Replace: n.OrReplace,
  683. Options: &ast.List{},
  684. WithCheckOption: ast.ViewCheckOption(n.CheckOption),
  685. }
  686. }
  687. func (c *cc) convertDeallocateStmt(n *pcast.DeallocateStmt) ast.Node {
  688. return todo(n)
  689. }
  690. func (c *cc) convertDefaultExpr(n *pcast.DefaultExpr) ast.Node {
  691. return todo(n)
  692. }
  693. func (c *cc) convertDeleteTableList(n *pcast.DeleteTableList) ast.Node {
  694. return todo(n)
  695. }
  696. func (c *cc) convertDoStmt(n *pcast.DoStmt) ast.Node {
  697. return todo(n)
  698. }
  699. func (c *cc) convertDropBindingStmt(n *pcast.DropBindingStmt) ast.Node {
  700. return todo(n)
  701. }
  702. func (c *cc) convertDropDatabaseStmt(n *pcast.DropDatabaseStmt) ast.Node {
  703. return &ast.DropSchemaStmt{
  704. MissingOk: !n.IfExists,
  705. Schemas: []*ast.String{
  706. NewIdentifer(n.Name),
  707. },
  708. }
  709. }
  710. func (c *cc) convertDropIndexStmt(n *pcast.DropIndexStmt) ast.Node {
  711. return todo(n)
  712. }
  713. func (c *cc) convertDropSequenceStmt(n *pcast.DropSequenceStmt) ast.Node {
  714. return todo(n)
  715. }
  716. func (c *cc) convertDropStatisticsStmt(n *pcast.DropStatisticsStmt) ast.Node {
  717. return todo(n)
  718. }
  719. func (c *cc) convertDropStatsStmt(n *pcast.DropStatsStmt) ast.Node {
  720. return todo(n)
  721. }
  722. func (c *cc) convertDropUserStmt(n *pcast.DropUserStmt) ast.Node {
  723. return todo(n)
  724. }
  725. func (c *cc) convertExecuteStmt(n *pcast.ExecuteStmt) ast.Node {
  726. return todo(n)
  727. }
  728. func (c *cc) convertExplainForStmt(n *pcast.ExplainForStmt) ast.Node {
  729. return todo(n)
  730. }
  731. func (c *cc) convertExplainStmt(n *pcast.ExplainStmt) ast.Node {
  732. return todo(n)
  733. }
  734. func (c *cc) convertFlashBackTableStmt(n *pcast.FlashBackTableStmt) ast.Node {
  735. return todo(n)
  736. }
  737. func (c *cc) convertFlushStmt(n *pcast.FlushStmt) ast.Node {
  738. return todo(n)
  739. }
  740. func (c *cc) convertFrameBound(n *pcast.FrameBound) ast.Node {
  741. return todo(n)
  742. }
  743. func (c *cc) convertFrameClause(n *pcast.FrameClause) ast.Node {
  744. return todo(n)
  745. }
  746. func (c *cc) convertFuncCastExpr(n *pcast.FuncCastExpr) ast.Node {
  747. return todo(n)
  748. }
  749. func (c *cc) convertGetFormatSelectorExpr(n *pcast.GetFormatSelectorExpr) ast.Node {
  750. return todo(n)
  751. }
  752. func (c *cc) convertGrantRoleStmt(n *pcast.GrantRoleStmt) ast.Node {
  753. return todo(n)
  754. }
  755. func (c *cc) convertGrantStmt(n *pcast.GrantStmt) ast.Node {
  756. return todo(n)
  757. }
  758. func (c *cc) convertGroupByClause(n *pcast.GroupByClause) *ast.List {
  759. if n == nil {
  760. return &ast.List{}
  761. }
  762. var items []ast.Node
  763. for _, item := range n.Items {
  764. items = append(items, c.convertByItem(item))
  765. }
  766. return &ast.List{
  767. Items: items,
  768. }
  769. }
  770. func (c *cc) convertHavingClause(n *pcast.HavingClause) ast.Node {
  771. return todo(n)
  772. }
  773. func (c *cc) convertIndexAdviseStmt(n *pcast.IndexAdviseStmt) ast.Node {
  774. return todo(n)
  775. }
  776. func (c *cc) convertIndexLockAndAlgorithm(n *pcast.IndexLockAndAlgorithm) ast.Node {
  777. return todo(n)
  778. }
  779. func (c *cc) convertIndexPartSpecification(n *pcast.IndexPartSpecification) ast.Node {
  780. return todo(n)
  781. }
  782. func (c *cc) convertIsNullExpr(n *pcast.IsNullExpr) ast.Node {
  783. return todo(n)
  784. }
  785. func (c *cc) convertIsTruthExpr(n *pcast.IsTruthExpr) ast.Node {
  786. return todo(n)
  787. }
  788. func (c *cc) convertJoin(n *pcast.Join) *ast.List {
  789. if n == nil {
  790. return &ast.List{}
  791. }
  792. if n.Right != nil && n.Left != nil {
  793. // MySQL doesn't have a FULL join type
  794. joinType := ast.JoinType(n.Tp)
  795. if joinType >= ast.JoinTypeFull {
  796. joinType++
  797. }
  798. return &ast.List{
  799. Items: []ast.Node{&ast.JoinExpr{
  800. Jointype: joinType,
  801. Larg: c.convert(n.Left),
  802. Rarg: c.convert(n.Right),
  803. Quals: c.convert(n.On),
  804. }},
  805. }
  806. }
  807. var tables []ast.Node
  808. if n.Right != nil {
  809. tables = append(tables, c.convert(n.Right))
  810. }
  811. if n.Left != nil {
  812. tables = append(tables, c.convert(n.Left))
  813. }
  814. return &ast.List{Items: tables}
  815. }
  816. func (c *cc) convertKillStmt(n *pcast.KillStmt) ast.Node {
  817. return todo(n)
  818. }
  819. func (c *cc) convertLimit(n *pcast.Limit) ast.Node {
  820. return todo(n)
  821. }
  822. func (c *cc) convertLoadDataStmt(n *pcast.LoadDataStmt) ast.Node {
  823. return todo(n)
  824. }
  825. func (c *cc) convertLoadStatsStmt(n *pcast.LoadStatsStmt) ast.Node {
  826. return todo(n)
  827. }
  828. func (c *cc) convertLockTablesStmt(n *pcast.LockTablesStmt) ast.Node {
  829. return todo(n)
  830. }
  831. func (c *cc) convertMatchAgainst(n *pcast.MatchAgainst) ast.Node {
  832. return todo(n)
  833. }
  834. func (c *cc) convertMaxValueExpr(n *pcast.MaxValueExpr) ast.Node {
  835. return todo(n)
  836. }
  837. func (c *cc) convertOnCondition(n *pcast.OnCondition) ast.Node {
  838. if n == nil {
  839. return nil
  840. }
  841. return c.convert(n.Expr)
  842. }
  843. func (c *cc) convertOnDeleteOpt(n *pcast.OnDeleteOpt) ast.Node {
  844. return todo(n)
  845. }
  846. func (c *cc) convertOnUpdateOpt(n *pcast.OnUpdateOpt) ast.Node {
  847. return todo(n)
  848. }
  849. func (c *cc) convertOrderByClause(n *pcast.OrderByClause) ast.Node {
  850. if n == nil {
  851. return nil
  852. }
  853. list := &ast.List{Items: []ast.Node{}}
  854. for _, item := range n.Items {
  855. switch item.Expr.(type) {
  856. case *pcast.CaseExpr:
  857. list.Items = append(list.Items, &ast.CaseWhen{
  858. Expr: c.convert(item.Expr),
  859. Location: item.Expr.OriginTextPosition(),
  860. })
  861. case *pcast.ColumnNameExpr:
  862. list.Items = append(list.Items, &ast.CaseExpr{
  863. Xpr: c.convert(item.Expr),
  864. Location: item.Expr.OriginTextPosition(),
  865. })
  866. }
  867. }
  868. return list
  869. }
  870. func (c *cc) convertParenthesesExpr(n *pcast.ParenthesesExpr) ast.Node {
  871. if n == nil {
  872. return nil
  873. }
  874. return c.convert(n.Expr)
  875. }
  876. func (c *cc) convertPartitionByClause(n *pcast.PartitionByClause) ast.Node {
  877. return todo(n)
  878. }
  879. func (c *cc) convertPatternInExpr(n *pcast.PatternInExpr) ast.Node {
  880. var list []ast.Node
  881. var val ast.Node
  882. expr := c.convert(n.Expr)
  883. for _, v := range n.List {
  884. val = c.convert(v)
  885. if val != nil {
  886. list = append(list, val)
  887. }
  888. }
  889. sel := c.convert(n.Sel)
  890. in := &ast.In{
  891. Expr: expr,
  892. List: list,
  893. Not: n.Not,
  894. Sel: sel,
  895. Location: n.OriginTextPosition(),
  896. }
  897. return in
  898. }
  899. func (c *cc) convertPatternLikeExpr(n *pcast.PatternLikeExpr) ast.Node {
  900. return &ast.A_Expr{
  901. Kind: ast.A_Expr_Kind(9),
  902. Name: &ast.List{
  903. Items: []ast.Node{
  904. &ast.String{Str: "~~"},
  905. },
  906. },
  907. Lexpr: c.convert(n.Expr),
  908. Rexpr: c.convert(n.Pattern),
  909. }
  910. }
  911. func (c *cc) convertPatternRegexpExpr(n *pcast.PatternRegexpExpr) ast.Node {
  912. return todo(n)
  913. }
  914. func (c *cc) convertPlacementSpec(n *pcast.PlacementSpec) ast.Node {
  915. return todo(n)
  916. }
  917. func (c *cc) convertPositionExpr(n *pcast.PositionExpr) ast.Node {
  918. return todo(n)
  919. }
  920. func (c *cc) convertPrepareStmt(n *pcast.PrepareStmt) ast.Node {
  921. return todo(n)
  922. }
  923. func (c *cc) convertPrivElem(n *pcast.PrivElem) ast.Node {
  924. return todo(n)
  925. }
  926. func (c *cc) convertRecoverTableStmt(n *pcast.RecoverTableStmt) ast.Node {
  927. return todo(n)
  928. }
  929. func (c *cc) convertReferenceDef(n *pcast.ReferenceDef) ast.Node {
  930. return todo(n)
  931. }
  932. func (c *cc) convertRepairTableStmt(n *pcast.RepairTableStmt) ast.Node {
  933. return todo(n)
  934. }
  935. func (c *cc) convertRevokeRoleStmt(n *pcast.RevokeRoleStmt) ast.Node {
  936. return todo(n)
  937. }
  938. func (c *cc) convertRevokeStmt(n *pcast.RevokeStmt) ast.Node {
  939. return todo(n)
  940. }
  941. func (c *cc) convertRollbackStmt(n *pcast.RollbackStmt) ast.Node {
  942. return todo(n)
  943. }
  944. func (c *cc) convertRowExpr(n *pcast.RowExpr) ast.Node {
  945. return todo(n)
  946. }
  947. func (c *cc) convertSetCollationExpr(n *pcast.SetCollationExpr) ast.Node {
  948. return todo(n)
  949. }
  950. func (c *cc) convertSetConfigStmt(n *pcast.SetConfigStmt) ast.Node {
  951. return todo(n)
  952. }
  953. func (c *cc) convertSetDefaultRoleStmt(n *pcast.SetDefaultRoleStmt) ast.Node {
  954. return todo(n)
  955. }
  956. func (c *cc) convertSetOprType(n *pcast.SetOprType) (op ast.SetOperation, all bool) {
  957. if n == nil {
  958. return
  959. }
  960. switch *n {
  961. case pcast.Union:
  962. op = ast.Union
  963. case pcast.UnionAll:
  964. op = ast.Union
  965. all = true
  966. case pcast.Intersect:
  967. op = ast.Intersect
  968. case pcast.IntersectAll:
  969. op = ast.Intersect
  970. all = true
  971. case pcast.Except:
  972. op = ast.Except
  973. case pcast.ExceptAll:
  974. op = ast.Except
  975. all = true
  976. }
  977. return
  978. }
  979. // convertSetOprSelectList converts a list of SELECT from the Pingcap parser
  980. // into a tree. It is called for UNION, INTERSECT or EXCLUDE operation.
  981. //
  982. // Given an union with the following nodes:
  983. // [Select{1}, Select{2}, Select{3}, Select{4}]
  984. //
  985. // The function will return:
  986. // Select{
  987. // Larg: Select{
  988. // Larg: Select{
  989. // Larg: Select{1},
  990. // Rarg: Select{2},
  991. // Op: Union
  992. // },
  993. // Rarg: Select{3},
  994. // Op: Union,
  995. // },
  996. // Rarg: Select{4},
  997. // Op: Union,
  998. // }
  999. func (c *cc) convertSetOprSelectList(n *pcast.SetOprSelectList) ast.Node {
  1000. selectStmts := make([]*ast.SelectStmt, len(n.Selects))
  1001. for i, node := range n.Selects {
  1002. selectStmts[i] = c.convertSelectStmt(node.(*pcast.SelectStmt))
  1003. }
  1004. op, all := c.convertSetOprType(n.AfterSetOperator)
  1005. tree := &ast.SelectStmt{
  1006. TargetList: &ast.List{},
  1007. FromClause: &ast.List{},
  1008. WhereClause: nil,
  1009. Op: op,
  1010. All: all,
  1011. WithClause: c.convertWithClause(n.With),
  1012. }
  1013. for _, stmt := range selectStmts {
  1014. // We move Op and All from the child to the parent.
  1015. op, all := stmt.Op, stmt.All
  1016. stmt.Op, stmt.All = ast.None, false
  1017. switch {
  1018. case tree.Larg == nil:
  1019. tree.Larg = stmt
  1020. case tree.Rarg == nil:
  1021. tree.Rarg = stmt
  1022. tree.Op = op
  1023. tree.All = all
  1024. default:
  1025. tree = &ast.SelectStmt{
  1026. TargetList: &ast.List{},
  1027. FromClause: &ast.List{},
  1028. WhereClause: nil,
  1029. Larg: tree,
  1030. Rarg: stmt,
  1031. Op: op,
  1032. All: all,
  1033. WithClause: c.convertWithClause(n.With),
  1034. }
  1035. }
  1036. }
  1037. return tree
  1038. }
  1039. func (c *cc) convertSetOprStmt(n *pcast.SetOprStmt) ast.Node {
  1040. if n.SelectList != nil {
  1041. return c.convertSetOprSelectList(n.SelectList)
  1042. }
  1043. return todo(n)
  1044. }
  1045. func (c *cc) convertSetPwdStmt(n *pcast.SetPwdStmt) ast.Node {
  1046. return todo(n)
  1047. }
  1048. func (c *cc) convertSetRoleStmt(n *pcast.SetRoleStmt) ast.Node {
  1049. return todo(n)
  1050. }
  1051. func (c *cc) convertSetStmt(n *pcast.SetStmt) ast.Node {
  1052. return todo(n)
  1053. }
  1054. func (c *cc) convertShowStmt(n *pcast.ShowStmt) ast.Node {
  1055. return todo(n)
  1056. }
  1057. func (c *cc) convertShutdownStmt(n *pcast.ShutdownStmt) ast.Node {
  1058. return todo(n)
  1059. }
  1060. func (c *cc) convertSplitRegionStmt(n *pcast.SplitRegionStmt) ast.Node {
  1061. return todo(n)
  1062. }
  1063. func (c *cc) convertTableName(n *pcast.TableName) *ast.RangeVar {
  1064. schema := identifier(n.Schema.String())
  1065. rel := identifier(n.Name.String())
  1066. return &ast.RangeVar{
  1067. Schemaname: &schema,
  1068. Relname: &rel,
  1069. }
  1070. }
  1071. func (c *cc) convertTableNameExpr(n *pcast.TableNameExpr) ast.Node {
  1072. return todo(n)
  1073. }
  1074. func (c *cc) convertTableOptimizerHint(n *pcast.TableOptimizerHint) ast.Node {
  1075. return todo(n)
  1076. }
  1077. func (c *cc) convertTableSource(node *pcast.TableSource) ast.Node {
  1078. if node == nil {
  1079. return nil
  1080. }
  1081. alias := node.AsName.String()
  1082. switch n := node.Source.(type) {
  1083. case *pcast.SelectStmt:
  1084. rs := &ast.RangeSubselect{
  1085. Subquery: c.convert(n),
  1086. }
  1087. if alias != "" {
  1088. rs.Alias = &ast.Alias{Aliasname: &alias}
  1089. }
  1090. return rs
  1091. case *pcast.TableName:
  1092. rv := c.convertTableName(n)
  1093. if alias != "" {
  1094. rv.Alias = &ast.Alias{Aliasname: &alias}
  1095. }
  1096. return rv
  1097. default:
  1098. return todo(n)
  1099. }
  1100. }
  1101. func (c *cc) convertTableToTable(n *pcast.TableToTable) ast.Node {
  1102. return todo(n)
  1103. }
  1104. func (c *cc) convertTimeUnitExpr(n *pcast.TimeUnitExpr) ast.Node {
  1105. return todo(n)
  1106. }
  1107. func (c *cc) convertTraceStmt(n *pcast.TraceStmt) ast.Node {
  1108. return todo(n)
  1109. }
  1110. func (c *cc) convertTrimDirectionExpr(n *pcast.TrimDirectionExpr) ast.Node {
  1111. return todo(n)
  1112. }
  1113. func (c *cc) convertTruncateTableStmt(n *pcast.TruncateTableStmt) *ast.TruncateStmt {
  1114. return &ast.TruncateStmt{
  1115. Relations: toList(n.Table),
  1116. }
  1117. }
  1118. func (c *cc) convertUnaryOperationExpr(n *pcast.UnaryOperationExpr) ast.Node {
  1119. return todo(n)
  1120. }
  1121. func (c *cc) convertUnlockTablesStmt(n *pcast.UnlockTablesStmt) ast.Node {
  1122. return todo(n)
  1123. }
  1124. func (c *cc) convertUseStmt(n *pcast.UseStmt) ast.Node {
  1125. return todo(n)
  1126. }
  1127. func (c *cc) convertValuesExpr(n *pcast.ValuesExpr) ast.Node {
  1128. return todo(n)
  1129. }
  1130. func (c *cc) convertVariableAssignment(n *pcast.VariableAssignment) ast.Node {
  1131. return todo(n)
  1132. }
  1133. func (c *cc) convertVariableExpr(n *pcast.VariableExpr) ast.Node {
  1134. return todo(n)
  1135. }
  1136. func (c *cc) convertWhenClause(n *pcast.WhenClause) ast.Node {
  1137. if n == nil {
  1138. return nil
  1139. }
  1140. return &ast.CaseWhen{
  1141. Expr: c.convert(n.Expr),
  1142. Result: c.convert(n.Result),
  1143. Location: n.OriginTextPosition(),
  1144. }
  1145. }
  1146. func (c *cc) convertWindowFuncExpr(n *pcast.WindowFuncExpr) ast.Node {
  1147. return todo(n)
  1148. }
  1149. func (c *cc) convertWindowSpec(n *pcast.WindowSpec) ast.Node {
  1150. return todo(n)
  1151. }
  1152. func (c *cc) convert(node pcast.Node) ast.Node {
  1153. switch n := node.(type) {
  1154. case *driver.ParamMarkerExpr:
  1155. return c.convertParamMarkerExpr(n)
  1156. case *driver.ValueExpr:
  1157. return c.convertValueExpr(n)
  1158. case *pcast.AdminStmt:
  1159. return c.convertAdminStmt(n)
  1160. case *pcast.AggregateFuncExpr:
  1161. return c.convertAggregateFuncExpr(n)
  1162. case *pcast.AlterDatabaseStmt:
  1163. return c.convertAlterDatabaseStmt(n)
  1164. case *pcast.AlterInstanceStmt:
  1165. return c.convertAlterInstanceStmt(n)
  1166. case *pcast.AlterTableSpec:
  1167. return c.convertAlterTableSpec(n)
  1168. case *pcast.AlterTableStmt:
  1169. return c.convertAlterTableStmt(n)
  1170. case *pcast.AlterUserStmt:
  1171. return c.convertAlterUserStmt(n)
  1172. case *pcast.AnalyzeTableStmt:
  1173. return c.convertAnalyzeTableStmt(n)
  1174. case *pcast.Assignment:
  1175. return c.convertAssignment(n)
  1176. case *pcast.BRIEStmt:
  1177. return c.convertBRIEStmt(n)
  1178. case *pcast.BeginStmt:
  1179. return c.convertBeginStmt(n)
  1180. case *pcast.BetweenExpr:
  1181. return c.convertBetweenExpr(n)
  1182. case *pcast.BinaryOperationExpr:
  1183. return c.convertBinaryOperationExpr(n)
  1184. case *pcast.BinlogStmt:
  1185. return c.convertBinlogStmt(n)
  1186. case *pcast.ByItem:
  1187. return c.convertByItem(n)
  1188. case *pcast.CaseExpr:
  1189. return c.convertCaseExpr(n)
  1190. case *pcast.ChangeStmt:
  1191. return c.convertChangeStmt(n)
  1192. case *pcast.CleanupTableLockStmt:
  1193. return c.convertCleanupTableLockStmt(n)
  1194. case *pcast.ColumnDef:
  1195. return c.convertColumnDef(n)
  1196. case *pcast.ColumnName:
  1197. return c.convertColumnName(n)
  1198. case *pcast.ColumnNameExpr:
  1199. return c.convertColumnNameExpr(n)
  1200. case *pcast.ColumnPosition:
  1201. return c.convertColumnPosition(n)
  1202. case *pcast.CommitStmt:
  1203. return c.convertCommitStmt(n)
  1204. case *pcast.CompareSubqueryExpr:
  1205. return c.convertCompareSubqueryExpr(n)
  1206. case *pcast.Constraint:
  1207. return c.convertConstraint(n)
  1208. case *pcast.CreateBindingStmt:
  1209. return c.convertCreateBindingStmt(n)
  1210. case *pcast.CreateDatabaseStmt:
  1211. return c.convertCreateDatabaseStmt(n)
  1212. case *pcast.CreateIndexStmt:
  1213. return c.convertCreateIndexStmt(n)
  1214. case *pcast.CreateSequenceStmt:
  1215. return c.convertCreateSequenceStmt(n)
  1216. case *pcast.CreateStatisticsStmt:
  1217. return c.convertCreateStatisticsStmt(n)
  1218. case *pcast.CreateTableStmt:
  1219. return c.convertCreateTableStmt(n)
  1220. case *pcast.CreateUserStmt:
  1221. return c.convertCreateUserStmt(n)
  1222. case *pcast.CreateViewStmt:
  1223. return c.convertCreateViewStmt(n)
  1224. case *pcast.DeallocateStmt:
  1225. return c.convertDeallocateStmt(n)
  1226. case *pcast.DefaultExpr:
  1227. return c.convertDefaultExpr(n)
  1228. case *pcast.DeleteStmt:
  1229. return c.convertDeleteStmt(n)
  1230. case *pcast.DeleteTableList:
  1231. return c.convertDeleteTableList(n)
  1232. case *pcast.DoStmt:
  1233. return c.convertDoStmt(n)
  1234. case *pcast.DropBindingStmt:
  1235. return c.convertDropBindingStmt(n)
  1236. case *pcast.DropDatabaseStmt:
  1237. return c.convertDropDatabaseStmt(n)
  1238. case *pcast.DropIndexStmt:
  1239. return c.convertDropIndexStmt(n)
  1240. case *pcast.DropSequenceStmt:
  1241. return c.convertDropSequenceStmt(n)
  1242. case *pcast.DropStatisticsStmt:
  1243. return c.convertDropStatisticsStmt(n)
  1244. case *pcast.DropStatsStmt:
  1245. return c.convertDropStatsStmt(n)
  1246. case *pcast.DropTableStmt:
  1247. return c.convertDropTableStmt(n)
  1248. case *pcast.DropUserStmt:
  1249. return c.convertDropUserStmt(n)
  1250. case *pcast.ExecuteStmt:
  1251. return c.convertExecuteStmt(n)
  1252. case *pcast.ExistsSubqueryExpr:
  1253. return c.convertExistsSubqueryExpr(n)
  1254. case *pcast.ExplainForStmt:
  1255. return c.convertExplainForStmt(n)
  1256. case *pcast.ExplainStmt:
  1257. return c.convertExplainStmt(n)
  1258. case *pcast.FieldList:
  1259. return c.convertFieldList(n)
  1260. case *pcast.FlashBackTableStmt:
  1261. return c.convertFlashBackTableStmt(n)
  1262. case *pcast.FlushStmt:
  1263. return c.convertFlushStmt(n)
  1264. case *pcast.FrameBound:
  1265. return c.convertFrameBound(n)
  1266. case *pcast.FrameClause:
  1267. return c.convertFrameClause(n)
  1268. case *pcast.FuncCallExpr:
  1269. return c.convertFuncCallExpr(n)
  1270. case *pcast.FuncCastExpr:
  1271. return c.convertFuncCastExpr(n)
  1272. case *pcast.GetFormatSelectorExpr:
  1273. return c.convertGetFormatSelectorExpr(n)
  1274. case *pcast.GrantRoleStmt:
  1275. return c.convertGrantRoleStmt(n)
  1276. case *pcast.GrantStmt:
  1277. return c.convertGrantStmt(n)
  1278. case *pcast.GroupByClause:
  1279. return c.convertGroupByClause(n)
  1280. case *pcast.HavingClause:
  1281. return c.convertHavingClause(n)
  1282. case *pcast.IndexAdviseStmt:
  1283. return c.convertIndexAdviseStmt(n)
  1284. case *pcast.IndexLockAndAlgorithm:
  1285. return c.convertIndexLockAndAlgorithm(n)
  1286. case *pcast.IndexPartSpecification:
  1287. return c.convertIndexPartSpecification(n)
  1288. case *pcast.InsertStmt:
  1289. return c.convertInsertStmt(n)
  1290. case *pcast.IsNullExpr:
  1291. return c.convertIsNullExpr(n)
  1292. case *pcast.IsTruthExpr:
  1293. return c.convertIsTruthExpr(n)
  1294. case *pcast.Join:
  1295. return c.convertJoin(n)
  1296. case *pcast.KillStmt:
  1297. return c.convertKillStmt(n)
  1298. case *pcast.Limit:
  1299. return c.convertLimit(n)
  1300. case *pcast.LoadDataStmt:
  1301. return c.convertLoadDataStmt(n)
  1302. case *pcast.LoadStatsStmt:
  1303. return c.convertLoadStatsStmt(n)
  1304. case *pcast.LockTablesStmt:
  1305. return c.convertLockTablesStmt(n)
  1306. case *pcast.MatchAgainst:
  1307. return c.convertMatchAgainst(n)
  1308. case *pcast.MaxValueExpr:
  1309. return c.convertMaxValueExpr(n)
  1310. case *pcast.OnCondition:
  1311. return c.convertOnCondition(n)
  1312. case *pcast.OnDeleteOpt:
  1313. return c.convertOnDeleteOpt(n)
  1314. case *pcast.OnUpdateOpt:
  1315. return c.convertOnUpdateOpt(n)
  1316. case *pcast.OrderByClause:
  1317. return c.convertOrderByClause(n)
  1318. case *pcast.ParenthesesExpr:
  1319. return c.convertParenthesesExpr(n)
  1320. case *pcast.PartitionByClause:
  1321. return c.convertPartitionByClause(n)
  1322. case *pcast.PatternInExpr:
  1323. return c.convertPatternInExpr(n)
  1324. case *pcast.PatternLikeExpr:
  1325. return c.convertPatternLikeExpr(n)
  1326. case *pcast.PatternRegexpExpr:
  1327. return c.convertPatternRegexpExpr(n)
  1328. case *pcast.PlacementSpec:
  1329. return c.convertPlacementSpec(n)
  1330. case *pcast.PositionExpr:
  1331. return c.convertPositionExpr(n)
  1332. case *pcast.PrepareStmt:
  1333. return c.convertPrepareStmt(n)
  1334. case *pcast.PrivElem:
  1335. return c.convertPrivElem(n)
  1336. case *pcast.RecoverTableStmt:
  1337. return c.convertRecoverTableStmt(n)
  1338. case *pcast.ReferenceDef:
  1339. return c.convertReferenceDef(n)
  1340. case *pcast.RenameTableStmt:
  1341. return c.convertRenameTableStmt(n)
  1342. case *pcast.RepairTableStmt:
  1343. return c.convertRepairTableStmt(n)
  1344. case *pcast.RevokeRoleStmt:
  1345. return c.convertRevokeRoleStmt(n)
  1346. case *pcast.RevokeStmt:
  1347. return c.convertRevokeStmt(n)
  1348. case *pcast.RollbackStmt:
  1349. return c.convertRollbackStmt(n)
  1350. case *pcast.RowExpr:
  1351. return c.convertRowExpr(n)
  1352. case *pcast.SelectField:
  1353. return c.convertSelectField(n)
  1354. case *pcast.SelectStmt:
  1355. return c.convertSelectStmt(n)
  1356. case *pcast.SetCollationExpr:
  1357. return c.convertSetCollationExpr(n)
  1358. case *pcast.SetConfigStmt:
  1359. return c.convertSetConfigStmt(n)
  1360. case *pcast.SetDefaultRoleStmt:
  1361. return c.convertSetDefaultRoleStmt(n)
  1362. case *pcast.SetOprSelectList:
  1363. return c.convertSetOprSelectList(n)
  1364. case *pcast.SetOprStmt:
  1365. return c.convertSetOprStmt(n)
  1366. case *pcast.SetPwdStmt:
  1367. return c.convertSetPwdStmt(n)
  1368. case *pcast.SetRoleStmt:
  1369. return c.convertSetRoleStmt(n)
  1370. case *pcast.SetStmt:
  1371. return c.convertSetStmt(n)
  1372. case *pcast.ShowStmt:
  1373. return c.convertShowStmt(n)
  1374. case *pcast.ShutdownStmt:
  1375. return c.convertShutdownStmt(n)
  1376. case *pcast.SplitRegionStmt:
  1377. return c.convertSplitRegionStmt(n)
  1378. case *pcast.SubqueryExpr:
  1379. return c.convertSubqueryExpr(n)
  1380. case *pcast.TableName:
  1381. return c.convertTableName(n)
  1382. case *pcast.TableNameExpr:
  1383. return c.convertTableNameExpr(n)
  1384. case *pcast.TableOptimizerHint:
  1385. return c.convertTableOptimizerHint(n)
  1386. case *pcast.TableRefsClause:
  1387. return c.convertTableRefsClause(n)
  1388. case *pcast.TableSource:
  1389. return c.convertTableSource(n)
  1390. case *pcast.TableToTable:
  1391. return c.convertTableToTable(n)
  1392. case *pcast.TimeUnitExpr:
  1393. return c.convertTimeUnitExpr(n)
  1394. case *pcast.TraceStmt:
  1395. return c.convertTraceStmt(n)
  1396. case *pcast.TrimDirectionExpr:
  1397. return c.convertTrimDirectionExpr(n)
  1398. case *pcast.TruncateTableStmt:
  1399. return c.convertTruncateTableStmt(n)
  1400. case *pcast.UnaryOperationExpr:
  1401. return c.convertUnaryOperationExpr(n)
  1402. case *pcast.UnlockTablesStmt:
  1403. return c.convertUnlockTablesStmt(n)
  1404. case *pcast.UpdateStmt:
  1405. return c.convertUpdateStmt(n)
  1406. case *pcast.UseStmt:
  1407. return c.convertUseStmt(n)
  1408. case *pcast.ValuesExpr:
  1409. return c.convertValuesExpr(n)
  1410. case *pcast.VariableAssignment:
  1411. return c.convertVariableAssignment(n)
  1412. case *pcast.VariableExpr:
  1413. return c.convertVariableExpr(n)
  1414. case *pcast.WhenClause:
  1415. return c.convertWhenClause(n)
  1416. case *pcast.WildCardField:
  1417. return c.convertWildCardField(n)
  1418. case *pcast.WindowFuncExpr:
  1419. return c.convertWindowFuncExpr(n)
  1420. case *pcast.WindowSpec:
  1421. return c.convertWindowSpec(n)
  1422. case nil:
  1423. return nil
  1424. default:
  1425. return todo(n)
  1426. }
  1427. }