Skip to content

Commit

Permalink
[parser] parser: fix select field text (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
alivxxx authored and ti-chi-bot committed Oct 9, 2021
1 parent bd8cc65 commit 5fe32fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion parser/parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -4378,7 +4378,7 @@ SelectStmtFromTable:
}
lastField := st.Fields.Fields[len(st.Fields.Fields)-1]
if lastField.Expr != nil && lastField.AsName.O == "" {
lastEnd := parser.endOffset(&yyS[yypt-4])
lastEnd := parser.endOffset(&yyS[yypt-5])
lastField.SetText(parser.src[lastField.Offset:lastEnd])
}
if $4 != nil {
Expand Down
8 changes: 8 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2523,3 +2523,11 @@ func (s *testParserSuite) TestWindowFunctions(c *C) {
s.enableWindowFunc = true
s.RunTest(c, table)
}

func (s *testParserSuite) TestFieldText(c *C) {
parser := New()
stmts, err := parser.Parse("select a from t", "", "")
c.Assert(err, IsNil)
tmp := stmts[0].(*ast.SelectStmt)
c.Assert(tmp.Fields.Fields[0].Text(), Equals, "a")
}

0 comments on commit 5fe32fe

Please sign in to comment.