Skip to content

Commit

Permalink
Merge branch 'main' into fulghum/max_allowed_packet
Browse files Browse the repository at this point in the history
  • Loading branch information
fulghum committed Jan 17, 2024
2 parents 33f24ba + 123ca09 commit c9088ef
Show file tree
Hide file tree
Showing 6 changed files with 10,503 additions and 10,375 deletions.
18 changes: 17 additions & 1 deletion go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -2067,6 +2067,12 @@ type DDL struct {

// OptSelect is set for CREATE TABLE <> AS SELECT operations.
OptSelect *OptSelect

// User is set for ALTER USER operations.
User AccountName

// Authentication is set for ALTER USER operations.
Authentication *Authentication
}

// ColumnOrder is used in some DDL statements to specify or change the order of a column in a schema.
Expand Down Expand Up @@ -2295,9 +2301,19 @@ func (node *DDL) Format(buf *TrackedBuffer) {
} else {
buf.Myprintf("%s", sb.String())
}
} else {
} else if node.Table.IsEmpty() == false {
buf.Myprintf("%s table %v", node.Action, node.Table)
node.alterFormat(buf)
} else if node.User.IsEmpty() == false {
ifExists := ""
if node.IfExists {
ifExists = "if exists "
}
buf.Myprintf("%s user %s%s %s", node.Action, ifExists, node.User.String(), node.Authentication.String())
node.alterFormat(buf)
} else {
buf.Myprintf(fmt.Sprintf("unsupported alter command: %v", node))
node.alterFormat(buf)
}
case FlushStr:
buf.Myprintf("%s", node.Action)
Expand Down
5 changes: 5 additions & 0 deletions go/vt/sqlparser/ast_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func (an *AccountName) String() string {
strings.ReplaceAll(an.Name, "`", "``"), strings.ReplaceAll(host, "`", "``"))
}

// IsEmpty returns true if any of the fields in this AccountName are set.
func (an *AccountName) IsEmpty() bool {
return an.Name == "" && an.Host == ""
}

// AccountRename represents an account changing its name.
type AccountRename struct {
From AccountName
Expand Down
1 change: 1 addition & 0 deletions go/vt/sqlparser/keywords.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ var keywords = map[string]int{
"plugins": PLUGINS,
"point": POINT,
"polygon": POLYGON,
"position": POSITION,
"precedes": PRECEDES,
"preceding": PRECEDING,
"precision": PRECISION,
Expand Down
24 changes: 23 additions & 1 deletion go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2745,6 +2745,21 @@ var (
}, {
input: "CREATE USER UserName@localhost ATTRIBUTE '{\"attr\": \"attr_text\"}'",
output: "create user `UserName`@`localhost` attribute '{\"attr\": \"attr_text\"}'",
}, {
input: "ALTER USER IF EXISTS foo@bar IDENTIFIED BY 'password1';",
output: "alter user if exists `foo`@`bar` identified by 'password1'",
}, {
input: "ALTER USER foo@bar IDENTIFIED BY 'password1';",
output: "alter user `foo`@`bar` identified by 'password1'",
}, {
input: "ALTER USER foo@bar IDENTIFIED BY RANDOM PASSWORD;",
output: "alter user `foo`@`bar` identified by random password",
}, {
input: "ALTER USER foo@bar IDENTIFIED WITH some_plugin;",
output: "alter user `foo`@`bar` identified with some_plugin",
}, {
input: "ALTER USER foo@bar IDENTIFIED WITH some_plugin BY 'auth_string';",
output: "alter user `foo`@`bar` identified with some_plugin by 'auth_string'",
}, {
input: "RENAME USER UserName1@localhost TO UserName2@localhost, UserName3 TO UserName4",
output: "rename user `UserName1`@`localhost` to `UserName2`@`localhost`, `UserName3`@`%` to `UserName4`@`%`",
Expand Down Expand Up @@ -5214,7 +5229,6 @@ func TestFunctionCalls(t *testing.T) {
"select PI() from dual",
"select Point() from dual",
"select Polygon() from dual",
"select POSITION() from dual",
"select POW() from dual",
"select POWER() from dual",
"select PS_CURRENT_THREAD_ID() from dual",
Expand Down Expand Up @@ -5415,6 +5429,14 @@ func TestFunctionCalls(t *testing.T) {
input: "SELECT CAST(foo AS FLOAT)",
output: "select CAST(foo as FLOAT)",
},
{
input: "SELECT POSITION('abc' in 'xyz')",
output: "select LOCATE('abc', 'xyz')",
},
{
input: "SELECT POSITION(1 + 1 in foo)",
output: "select LOCATE(1 + 1, foo)",
},
}

// Unimplemented or broken functionality
Expand Down
Loading

0 comments on commit c9088ef

Please sign in to comment.