Our main work is in pingcap/parser/ast.
Most of ast.Nodes are in pingcap/parser/ast(Others are in pingcap/tidb/types).
We regard each ast.Node as a subtask, and we can complete one or several subtasks as a PR.
Considering that some ast.Node depends on another ast.Node, we divide sub-tasks into five stages.
We believe that a Restore() function is correct when the SQL text it outputs can be parsed successfully
and the generated AST is equal to the original AST.
See: RunTest and RunRestoreTest
Some ast.Node can't be restored to a complete SQL text, such as an ast.ExprNode.
To test them, we can construct a complete SQL text.
See: expressions_test.go
There are examples which include complete implementation and test:
parser#71
Waiting this feature to rewriter view's sql...I think we could use create view func to test this feature later.
@leoppro Do we need to considered sql_mode=ansi_quotes when process TableName\TableAliasName\ColumnName\ColumnAliasName ?
// escape the identifier for pretty-printing.
// For instance, the identifier "foo `bar`" will become "`foo ``bar```".
// The sqlMode controls whether to escape with backquotes (`) or double quotes
// (`"`) depending on whether mysql.ModeANSIQuotes is enabled.
func escape(cis model.CIStr, sqlMode mysql.SQLMode) string {
var quote string
if sqlMode&mysql.ModeANSIQuotes != 0 {
quote = `"`
} else {
quote = "`"
}
return quote + strings.Replace(cis.O, quote, quote+quote, -1) + quote
}
@leoppro Do we need to considered
sql_mode=ansi_quoteswhen process TableName\TableAliasName\ColumnName\ColumnAliasName ?// escape the identifier for pretty-printing. // For instance, the identifier "foo `bar`" will become "`foo ``bar```". // The sqlMode controls whether to escape with backquotes (`) or double quotes // (`"`) depending on whether mysql.ModeANSIQuotes is enabled. func escape(cis model.CIStr, sqlMode mysql.SQLMode) string { var quote string if sqlMode&mysql.ModeANSIQuotes != 0 { quote = `"` } else { quote = "`" } return quote + strings.Replace(cis.O, quote, quote+quote, -1) + quote }
see: https://github.com/pingcap/parser/blob/master/ast/util.go#L189 @AndrewDi
Many thanks for your contributions.
All the tasks have been completed.
Most helpful comment
Many thanks for your contributions.
All the tasks have been completed.