Skip to content

Commit

Permalink
add partial support for ':=' assignment operator (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
jennifersp authored Nov 9, 2023
1 parent 51b7694 commit c0fa018
Show file tree
Hide file tree
Showing 6 changed files with 9,837 additions and 9,781 deletions.
26 changes: 13 additions & 13 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,19 +522,19 @@ func (q QueryOpts) Format(buf *TrackedBuffer) {

// Select represents a SELECT statement.
type Select struct {
Comments Comments
QueryOpts QueryOpts
With *With
SelectExprs SelectExprs
From TableExprs
Where *Where
GroupBy GroupBy
Having *Where
Window Window
OrderBy OrderBy
Limit *Limit
Lock string
Into *Into
Comments Comments
QueryOpts QueryOpts
With *With
SelectExprs SelectExprs
From TableExprs
Where *Where
GroupBy GroupBy
Having *Where
Window Window
OrderBy OrderBy
Limit *Limit
Lock string
Into *Into
}

// Select.QueryOpts
Expand Down
4 changes: 2 additions & 2 deletions go/vt/sqlparser/keywords.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ var keywords = map[string]int{
"localtime": LOCALTIME,
"localtimestamp": LOCALTIMESTAMP,
"lock": LOCK,
"locked": LOCKED,
"locked": LOCKED,
"logs": LOGS,
"long": LONG,
"longblob": LONGBLOB,
Expand Down Expand Up @@ -533,7 +533,7 @@ var keywords = map[string]int{
"shutdown": SHUTDOWN,
"signal": SIGNAL,
"signed": SIGNED,
"skip": SKIP,
"skip": SKIP,
"skip_query_rewrite": SKIP_QUERY_REWRITE,
"slave": SLAVE,
"slow": SLOW,
Expand Down
35 changes: 29 additions & 6 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ var (
input: "SET @foo = 'o' 'ne';",
output: "set @foo = 'one'",
},
{
input: "SET @foo := 'o' 'ne';",
output: "set @foo = 'one'",
},
{
input: "SET @foo = \"o\" \"ne\";",
output: "set @foo = 'one'",
Expand All @@ -97,6 +101,10 @@ var (
input: "SET @@GLOBAL.GTID_PURGED= /*!80000 '+'*/ 'beabe64c-9dc6-11ed-8021-a0f9021e8e70:1-126';",
output: "set global GTID_PURGED = '+beabe64c-9dc6-11ed-8021-a0f9021e8e70:1-126'",
},
{
input: "SET @@GLOBAL.GTID_PURGED:= /*!80000 '+'*/ 'beabe64c-9dc6-11ed-8021-a0f9021e8e70:1-126';",
output: "set global GTID_PURGED = '+beabe64c-9dc6-11ed-8021-a0f9021e8e70:1-126'",
},
{
input: "start replica",
},
Expand Down Expand Up @@ -392,27 +400,27 @@ var (
input: "select /* straight_join */ straight_join 1 from t",
},
{
input: "select sql_calc_found_rows distinct * from t",
input: "select sql_calc_found_rows distinct * from t",
output: "select distinct sql_calc_found_rows * from t",
},
{
input: "select distinct sql_calc_found_rows * from t",
input: "select distinct sql_calc_found_rows * from t",
output: "select distinct sql_calc_found_rows * from t",
},
{
input: "select distinct sql_calc_found_rows distinct * from t",
input: "select distinct sql_calc_found_rows distinct * from t",
output: "select distinct sql_calc_found_rows * from t",
},
{
input: "select sql_cache distinct sql_calc_found_rows straight_join * from t",
input: "select sql_cache distinct sql_calc_found_rows straight_join * from t",
output: "select distinct straight_join sql_calc_found_rows sql_cache * from t",
},
{
input: "select straight_join sql_calc_found_rows all sql_no_cache * from t",
input: "select straight_join sql_calc_found_rows all sql_no_cache * from t",
output: "select all straight_join sql_calc_found_rows sql_no_cache * from t",
},
{
input: "select sql_cache distinct sql_calc_found_rows straight_join straight_join sql_calc_found_rows distinct sql_cache * from t",
input: "select sql_cache distinct sql_calc_found_rows straight_join straight_join sql_calc_found_rows distinct sql_cache * from t",
output: "select distinct straight_join sql_calc_found_rows sql_cache * from t",
},
{
Expand Down Expand Up @@ -1107,6 +1115,9 @@ var (
}, {
input: "insert /* set default */ into a set a = default, b = 2",
output: "insert /* set default */ into a(a, b) values (default, 2)",
}, {
input: "insert /* set default */ into a set a := default, b := 2",
output: "insert /* set default */ into a(a, b) values (default, 2)",
}, {
input: "insert /* value expression list */ into a values (a + 1, 2 * 3)",
}, {
Expand Down Expand Up @@ -1159,6 +1170,9 @@ var (
output: "create table A (\n\tA int\n)",
}, {
input: "update /* simple */ a set b = 3",
}, {
input: "update /* simple */ a set b := 3",
output: "update /* simple */ a set b = 3",
}, {
input: "update /* a.b */ a.b set b = 3",
}, {
Expand Down Expand Up @@ -1292,6 +1306,9 @@ var (
}, {
input: "set session autocommit = ON",
output: "set session autocommit = 'ON'",
}, {
input: "set session autocommit := ON",
output: "set session autocommit = 'ON'",
}, {
input: "set global autocommit = OFF",
output: "set global autocommit = 'OFF'",
Expand Down Expand Up @@ -1331,6 +1348,9 @@ var (
input: "set @user.var = 1",
}, {
input: "set @user.var.name = 1",
}, {
input: "set @user.var.name := 1",
output: "set @user.var.name = 1",
}, {
input: "set autocommit = on",
output: "set autocommit = 'on'",
Expand Down Expand Up @@ -2992,6 +3012,9 @@ var (
}, {
input: "alter table t character set = utf8mb4",
output: "alter table t character set utf8mb4",
}, {
input: "alter table t character set := utf8mb4",
output: "alter table t character set utf8mb4",
}, {
input: "alter table t character set utf8mb4 collate utf8mb4_0900_bin",
output: "alter table t character set utf8mb4 collate utf8mb4_0900_bin",
Expand Down
Loading

0 comments on commit c0fa018

Please sign in to comment.