-
Notifications
You must be signed in to change notification settings - Fork 489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ast, parser: extract create view parameters to CreateViewStmt #55
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2132,15 +2132,25 @@ CreateViewStmt: | |
{ | ||
startOffset := parser.startOffset(&yyS[yypt-1]) | ||
selStmt := $10.(*ast.SelectStmt) | ||
selStmt.SetText(string(parser.src[startOffset:])) | ||
selStmt.SetText(strings.TrimSpace(parser.src[startOffset:])) | ||
x := &ast.CreateViewStmt { | ||
OrReplace: $2.(bool), | ||
ViewName: $7.(*ast.TableName), | ||
Select: selStmt, | ||
Algorithm: $3.(model.ViewAlgorithm), | ||
Definer: $4.(*auth.UserIdentity), | ||
Security: $5.(model.ViewSecurity), | ||
} | ||
if $8 != nil{ | ||
x.Cols = $8.([]model.CIStr) | ||
} | ||
if $11 !=nil { | ||
x.CheckOption = $11.(model.ViewCheckOption) | ||
endOffset := parser.startOffset(&yyS[yypt]) | ||
selStmt.SetText(strings.TrimSpace(parser.src[startOffset:endOffset])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested it locally. Seems we do not need this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I remove strings.TrimSpace, extra space would make test fail. FAIL: parser_test.go:2220: testParserSuite.TestView
parser_test.go:2265:
c.Assert(v.Select.Text(), Equals, "select c,d,e from t")
... obtained string = "" +
... "select c,d,e from t \n" +
... " "
... expected string = "select c,d,e from t" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use sql string for test: src := `CREATE OR REPLACE ALGORITHM = UNDEFINED DEFINER = root@localhost
SQL SECURITY DEFINER
VIEW V(a,b,c) AS select c,d,e from t
WITH CASCADED CHECK OPTION;` |
||
} else { | ||
x.CheckOption = model.CheckOptionCascaded | ||
} | ||
$$ = x | ||
} | ||
|
||
|
@@ -2156,25 +2166,25 @@ OrReplace: | |
ViewAlgorithm: | ||
/* EMPTY */ | ||
{ | ||
$$ = "UNDEFINED" | ||
$$ = model.AlgorithmUndefined | ||
} | ||
| "ALGORITHM" "=" "UNDEFINED" | ||
{ | ||
$$ = strings.ToUpper($3) | ||
$$ = model.AlgorithmUndefined | ||
} | ||
| "ALGORITHM" "=" "MERGE" | ||
{ | ||
$$ = strings.ToUpper($3) | ||
$$ = model.AlgorithmMerge | ||
} | ||
| "ALGORITHM" "=" "TEMPTABLE" | ||
{ | ||
$$ = strings.ToUpper($3) | ||
$$ = model.AlgorithmTemptable | ||
} | ||
|
||
ViewDefiner: | ||
/* EMPTY */ | ||
{ | ||
$$ = nil | ||
$$ = &auth.UserIdentity{CurrentUser: true} | ||
} | ||
| "DEFINER" "=" Username | ||
{ | ||
|
@@ -2184,15 +2194,15 @@ ViewDefiner: | |
ViewSQLSecurity: | ||
/* EMPTY */ | ||
{ | ||
$$ = "DEFINER" | ||
$$ = model.SecurityDefiner | ||
} | ||
| "SQL" "SECURITY" "DEFINER" | ||
{ | ||
$$ = $3 | ||
$$ = model.SecurityDefiner | ||
} | ||
| "SQL" "SECURITY" "INVOKER" | ||
{ | ||
$$ = $3 | ||
$$ = model.SecurityInvoker | ||
} | ||
|
||
ViewName: | ||
|
@@ -2228,11 +2238,11 @@ ViewCheckOption: | |
} | ||
| "WITH" "CASCADED" "CHECK" "OPTION" | ||
{ | ||
$$ = $2 | ||
$$ = model.CheckOptionCascaded | ||
} | ||
| "WITH" "LOCAL" "CHECK" "OPTION" | ||
{ | ||
$$ = $2 | ||
$$ = model.CheckOptionLocal | ||
} | ||
|
||
/****************************************************************** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we visit
n.ddlNode
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently ddlNode is not able to visit, and it only contains a statement string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it.