Skip to content

Commit

Permalink
Rename UpdateItem*
Browse files Browse the repository at this point in the history
  • Loading branch information
apstndb committed Jan 9, 2025
1 parent a9b2381 commit 8d56cd7
Show file tree
Hide file tree
Showing 26 changed files with 64 additions and 64 deletions.
12 changes: 6 additions & 6 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,8 @@ type UpdateItem interface {
isUpdateItem()
}

func (UpdateItemAssign) isUpdateItem() {}
func (UpdateItemNested) isUpdateItem() {}
func (UpdateItemSetValue) isUpdateItem() {}
func (UpdateItemDML) isUpdateItem() {}

// ChangeStreamFor represents FOR clause in CREATE/ALTER CHANGE STREAM statement.
type ChangeStreamFor interface {
Expand Down Expand Up @@ -3740,21 +3740,21 @@ type Update struct {
ThenReturn *ThenReturn // optional
}

// UpdateItemNested is nested update node in UPDATE statement.
// UpdateItemDML is nested update UpdateItem node in UPDATE statement.
//
// ({{.DML | sql}})
type UpdateItemNested struct {
type UpdateItemDML struct {
// pos = Lparen
// end = Rparen + 1

Lparen, Rparen token.Pos // position of "(", ")"
DML DML
}

// UpdateItemAssign is assignment node in UPDATE statement .
// UpdateItemSetValue is assignment style UpdateItem node in UPDATE statement .
//
// {{.Path | sqlJoin "."}} = {{.DefaultExpr | sql}}
type UpdateItemAssign struct {
type UpdateItemSetValue struct {
// pos = Path[0].pos
// end = DefaultExpr.end

Expand Down
8 changes: 4 additions & 4 deletions ast/pos.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ast/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1253,11 +1253,11 @@ func (u *Update) SQL() string {
sqlOpt(" ", u.ThenReturn, "")
}

func (u *UpdateItemAssign) SQL() string {
func (u *UpdateItemSetValue) SQL() string {
return sqlJoin(u.Path, ".") + " = " + u.DefaultExpr.SQL()
}

func (u *UpdateItemNested) SQL() string {
func (u *UpdateItemDML) SQL() string {
return "(" + u.DML.SQL() + ")"
}

Expand Down
4 changes: 2 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4897,7 +4897,7 @@ func (p *Parser) parseUpdateItem() ast.UpdateItem {
lparen := p.expect("(").Pos
dml := p.parseDML(true)
rparen := p.expect(")").Pos
return &ast.UpdateItemNested{
return &ast.UpdateItemDML{
Lparen: lparen,
Rparen: rparen,
DML: dml,
Expand All @@ -4908,7 +4908,7 @@ func (p *Parser) parseUpdateItem() ast.UpdateItem {
p.expect("=")
defaultExpr := p.parseDefaultExpr()

return &ast.UpdateItemAssign{
return &ast.UpdateItemSetValue{
Path: path,
DefaultExpr: defaultExpr,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ WHERE SingerId = 3 AND s.Albums.title = 'Go! Go! Go!'
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemNested{
&ast.UpdateItemDML{
Lparen: 23,
Rparen: 85,
DML: &ast.Delete{
Expand Down Expand Up @@ -84,7 +84,7 @@ WHERE SingerId = 3 AND s.Albums.title = 'Go! Go! Go!'
},
},
},
&ast.UpdateItemNested{
&ast.UpdateItemDML{
Lparen: 90,
Rparen: 204,
DML: &ast.Update{
Expand Down Expand Up @@ -117,7 +117,7 @@ WHERE SingerId = 3 AND s.Albums.title = 'Go! Go! Go!'
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 121,
Expand Down Expand Up @@ -167,7 +167,7 @@ WHERE SingerId = 3 AND s.Albums.title = 'Go! Go! Go!'
},
},
},
&ast.UpdateItemNested{
&ast.UpdateItemDML{
Lparen: 209,
Rparen: 275,
DML: &ast.Insert{
Expand Down
2 changes: 1 addition & 1 deletion testdata/result/dml/nested_update_insert_song.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ WHERE s.SingerId = 5 AND s.AlbumInfo.title = "Fire is Hot"
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemNested{
&ast.UpdateItemDML{
Lparen: 21,
Rparen: 105,
DML: &ast.Insert{
Expand Down
4 changes: 2 additions & 2 deletions testdata/result/dml/nested_update_insert_song_path.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ WHERE s.SingerId = 5 and s.AlbumInfo.title = "Fire is Hot"
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemNested{
&ast.UpdateItemDML{
Lparen: 21,
Rparen: 102,
DML: &ast.Insert{
Expand Down Expand Up @@ -69,7 +69,7 @@ WHERE s.SingerId = 5 and s.AlbumInfo.title = "Fire is Hot"
},
},
},
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 109,
Expand Down
2 changes: 1 addition & 1 deletion testdata/result/dml/nested_update_insert_string.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ WHERE s.SingerId = 5 AND s.AlbumInfo.title = "Fire is Hot"
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemNested{
&ast.UpdateItemDML{
Lparen: 21,
Rparen: 73,
DML: &ast.Insert{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ WHERE s.SingerId = 5
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemNested{
&ast.UpdateItemDML{
Lparen: 21,
Rparen: 175,
DML: &ast.Update{
Expand Down Expand Up @@ -58,7 +58,7 @@ WHERE s.SingerId = 5
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemNested{
&ast.UpdateItemDML{
Lparen: 57,
Rparen: 135,
DML: &ast.Insert{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ WHERE s.SingerId = 5
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemNested{
&ast.UpdateItemDML{
Lparen: 21,
Rparen: 189,
DML: &ast.Update{
Expand Down Expand Up @@ -59,7 +59,7 @@ WHERE s.SingerId = 5
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemNested{
&ast.UpdateItemDML{
Lparen: 58,
Rparen: 148,
DML: &ast.Update{
Expand Down Expand Up @@ -87,7 +87,7 @@ WHERE s.SingerId = 5
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 91,
Expand Down
6 changes: 3 additions & 3 deletions testdata/result/dml/update.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ update foo set foo = bar, bar = foo, baz = DEFAULT where foo = 1
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 15,
Expand All @@ -29,7 +29,7 @@ update foo set foo = bar, bar = foo, baz = DEFAULT where foo = 1
},
},
},
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 26,
Expand All @@ -46,7 +46,7 @@ update foo set foo = bar, bar = foo, baz = DEFAULT where foo = 1
},
},
},
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 37,
Expand Down
2 changes: 1 addition & 1 deletion testdata/result/dml/update_as.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ update foo as F set F.foo = F.bar + 1 where foo = F.bar
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 20,
Expand Down
6 changes: 3 additions & 3 deletions testdata/result/dml/update_fqn.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ update sch1.foo set foo = bar, bar = foo, baz = DEFAULT where foo = 1
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 20,
Expand All @@ -34,7 +34,7 @@ update sch1.foo set foo = bar, bar = foo, baz = DEFAULT where foo = 1
},
},
},
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 31,
Expand All @@ -51,7 +51,7 @@ update sch1.foo set foo = bar, bar = foo, baz = DEFAULT where foo = 1
},
},
},
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 42,
Expand Down
6 changes: 3 additions & 3 deletions testdata/result/dml/update_then_return_with_action.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ update foo set foo = bar, bar = foo, baz = DEFAULT where foo = 1 then return wit
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 15,
Expand All @@ -29,7 +29,7 @@ update foo set foo = bar, bar = foo, baz = DEFAULT where foo = 1 then return wit
},
},
},
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 26,
Expand All @@ -46,7 +46,7 @@ update foo set foo = bar, bar = foo, baz = DEFAULT where foo = 1 then return wit
},
},
},
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 37,
Expand Down
4 changes: 2 additions & 2 deletions testdata/result/dml/update_with_safe_ml_predict.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ WHERE products.desc_embed IS NULL
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 100,
Expand Down Expand Up @@ -163,7 +163,7 @@ WHERE products.desc_embed IS NULL
},
},
},
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 340,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ WHERE SingerId = 3 AND s.Albums.title = 'Go! Go! Go!'
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemNested{
&ast.UpdateItemDML{
Lparen: 23,
Rparen: 85,
DML: &ast.Delete{
Expand Down Expand Up @@ -84,7 +84,7 @@ WHERE SingerId = 3 AND s.Albums.title = 'Go! Go! Go!'
},
},
},
&ast.UpdateItemNested{
&ast.UpdateItemDML{
Lparen: 90,
Rparen: 204,
DML: &ast.Update{
Expand Down Expand Up @@ -117,7 +117,7 @@ WHERE SingerId = 3 AND s.Albums.title = 'Go! Go! Go!'
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 121,
Expand Down Expand Up @@ -167,7 +167,7 @@ WHERE SingerId = 3 AND s.Albums.title = 'Go! Go! Go!'
},
},
},
&ast.UpdateItemNested{
&ast.UpdateItemDML{
Lparen: 209,
Rparen: 275,
DML: &ast.Insert{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ WHERE s.SingerId = 5 AND s.AlbumInfo.title = "Fire is Hot"
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemNested{
&ast.UpdateItemDML{
Lparen: 21,
Rparen: 105,
DML: &ast.Insert{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ WHERE s.SingerId = 5 and s.AlbumInfo.title = "Fire is Hot"
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemNested{
&ast.UpdateItemDML{
Lparen: 21,
Rparen: 102,
DML: &ast.Insert{
Expand Down Expand Up @@ -69,7 +69,7 @@ WHERE s.SingerId = 5 and s.AlbumInfo.title = "Fire is Hot"
},
},
},
&ast.UpdateItemAssign{
&ast.UpdateItemSetValue{
Path: []*ast.Ident{
&ast.Ident{
NamePos: 109,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ WHERE s.SingerId = 5 AND s.AlbumInfo.title = "Fire is Hot"
},
},
Updates: []ast.UpdateItem{
&ast.UpdateItemNested{
&ast.UpdateItemDML{
Lparen: 21,
Rparen: 73,
DML: &ast.Insert{
Expand Down
Loading

0 comments on commit 8d56cd7

Please sign in to comment.