[parser] parser: SetText for trace statement and set default format to json (#46)

This commit is contained in:
tiancaiamao
2018-11-20 15:28:20 +08:00
committed by Ti Chi Robot
parent e5fb49c9b0
commit fa3239e982
3 changed files with 3127 additions and 3085 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2375,8 +2375,19 @@ TraceStmt:
{
$$ = &ast.TraceStmt{
Stmt: $2,
Format: "row",
Format: "json",
}
startOffset := parser.startOffset(&yyS[yypt])
$2.SetText(string(parser.src[startOffset:]))
}
| "TRACE" "FORMAT" "=" stringLit TraceableStmt
{
$$ = &ast.TraceStmt{
Stmt: $5,
Format: $4,
}
startOffset := parser.startOffset(&yyS[yypt])
$5.SetText(string(parser.src[startOffset:]))
}
ExplainSym:

View File

@ -2206,6 +2206,8 @@ func (s *testParserSuite) TestTrace(c *C) {
{"trace replace into foo values (1 || 2)", true},
{"trace update t set id = id + 1 order by id desc;", true},
{"trace select c1 from t1 union (select c2 from t2) limit 1, 1", true},
{"trace format = 'row' select c1 from t1 union (select c2 from t2) limit 1, 1", true},
{"trace format = 'json' update t set id = id + 1 order by id desc;", true},
}
s.RunTest(c, table)
}
@ -2568,4 +2570,17 @@ func (s *testParserSuite) TestFieldText(c *C) {
c.Assert(err, IsNil)
tmp := stmts[0].(*ast.SelectStmt)
c.Assert(tmp.Fields.Fields[0].Text(), Equals, "a")
sqls := []string{
"trace select a from t",
"trace format = 'row' select a from t",
"trace format = 'json' select a from t",
}
for _, sql := range sqls {
stmts, err = parser.Parse(sql, "", "")
c.Assert(err, IsNil)
traceStmt := stmts[0].(*ast.TraceStmt)
c.Assert(traceStmt.Text(), Equals, sql)
c.Assert(traceStmt.Stmt.Text(), Equals, "select a from t")
}
}