-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into kennytm/backup-restore-statements
- Loading branch information
Showing
19 changed files
with
7,567 additions
and
7,308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,56 @@ | ||
# Parser | ||
# Parser - A MySQL Compatible SQL Parser | ||
|
||
[![Go Report Card](https://goreportcard.com/badge/github.com/pingcap/parser)](https://goreportcard.com/report/github.com/pingcap/parser) [![CircleCI Status](https://circleci.com/gh/pingcap/parser.svg?style=shield)](https://circleci.com/gh/pingcap/parser) [![GoDoc](https://godoc.org/github.com/pingcap/parser?status.svg)](https://godoc.org/github.com/pingcap/parser) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/pingcap/parser)](https://goreportcard.com/report/github.com/pingcap/parser) | ||
[![CircleCI Status](https://circleci.com/gh/pingcap/parser.svg?style=shield)](https://circleci.com/gh/pingcap/parser) | ||
[![GoDoc](https://godoc.org/github.com/pingcap/parser?status.svg)](https://godoc.org/github.com/pingcap/parser) | ||
[![codecov](https://codecov.io/gh/pingcap/parser/branch/master/graph/badge.svg)](https://codecov.io/gh/pingcap/parser) | ||
|
||
TiDB SQL Parser | ||
The goal of this project is to build a Golang parser that is fully compatible with MySQL syntax, easy to extend, and high performance. Currently, features supported by parser are as follows: | ||
|
||
## How to use it | ||
|
||
```go | ||
import ( | ||
"fmt" | ||
"github.com/pingcap/parser" | ||
_ "github.com/pingcap/tidb/types/parser_driver" | ||
) | ||
|
||
// This example show how to parse a text sql into ast. | ||
func example() { | ||
|
||
// 0. make sure import parser_driver implemented by TiDB(user also can implement own driver by self). | ||
// and add `import _ "github.com/pingcap/tidb/types/parser_driver"` in the head of file. | ||
|
||
// 1. Create a parser. The parser is NOT goroutine safe and should | ||
// not be shared among multiple goroutines. However, parser is also | ||
// heavy, so each goroutine should reuse its own local instance if | ||
// possible. | ||
p := parser.New() | ||
- Highly compatible with MySQL: it supports almost all features of MySQL. For the complete details, see [parser.y](https://github.com/pingcap/parser/blob/master/parser.y) and [hintparser.y](https://github.com/pingcap/parser/blob/master/hintparser.y). | ||
- Extensible: adding a new syntax requires only a few lines of Yacc and Golang code changes. As an example, see [PR-680](https://github.com/pingcap/parser/pull/680/files). | ||
- Good performance: the parser is generated by goyacc in a bottom-up approach. It is efficient to build an AST tree with a state machine. | ||
|
||
// 2. Parse a text SQL into AST([]ast.StmtNode). | ||
stmtNodes, _, err := p.Parse("select * from tbl where id = 1", "", "") | ||
|
||
// 3. Use AST to do cool things. | ||
fmt.Println(stmtNodes[0], err) | ||
} | ||
``` | ||
|
||
See [https://godoc.org/github.com/pingcap/parser](https://godoc.org/github.com/pingcap/parser) | ||
|
||
## How to update parser for TiDB | ||
|
||
Assuming that you want to file a PR (pull request) to TiDB, and your PR includes a change in the parser, follow these steps to update the parser in TiDB. | ||
## How to use it | ||
|
||
### Step 1: Make changes in your parser repository | ||
Please read the [quickstart](https://github.com/pingcap/parser/blob/master/docs/quickstart.md). | ||
|
||
Fork this repository to your own account and commit the changes to your repository. | ||
## Future | ||
|
||
> **Note:** | ||
> | ||
> - Don't forget to run `make test` before you commit! | ||
> - Make sure `parser.go` is updated. | ||
- Support more MySQL syntax | ||
- Optimize the code structure, make it easier to extend | ||
- Improve performance and benchmark | ||
- Improve the quality of code and comments | ||
|
||
Suppose the forked repository is `https://github.com/your-repo/parser`. | ||
## Getting Help | ||
|
||
### Step 2: Make your parser changes take effect in TiDB and run CI | ||
- [GitHub Issue](https://github.com/pingcap/parser/issues) | ||
- [Stack Overflow](https://stackoverflow.com/questions/tagged/tidb) | ||
- [User Group (Chinese)](https://asktug.com/) | ||
|
||
1. In your TiDB repository, execute the `replace` instruction to make your parser changes take effect: | ||
If you have any questions, feel free to join and discuss in #sig-ddl channel of [Slack-community](https://pingcap.com/tidbslack/). | ||
|
||
``` | ||
GO111MODULE=on go mod edit -replace github.com/pingcap/parser=github.com/your-repo/parser@your-branch | ||
``` | ||
If you want to join as a special interest group member, see [DDL Special Interest Group](https://github.com/pingcap/community/tree/master/special-interest-groups/sig-ddl). | ||
|
||
2. `make dev` to run CI in TiDB. | ||
## Users | ||
|
||
3. File a PR to TiDB. | ||
These projects use this parser. Please feel free to extend this list if you | ||
found you are one of the users but not listed here: | ||
|
||
### Step 3: Merge the PR about the parser to this repository | ||
- [pingcap/tidb](https://github.com/pingcap/tidb) | ||
- [XiaoMi/soar](https://github.com/XiaoMi/soar) | ||
- [XiaoMi/Gaea](https://github.com/XiaoMi/Gaea) | ||
- [sql-machine-learning/sqlflow](https://github.com/sql-machine-learning/sqlflow) | ||
|
||
File a PR to this repository. **Link the related PR in TiDB in your PR description or comment.** | ||
## Contributing | ||
|
||
This PR will be reviewed, and if everything goes well, it will be merged. | ||
Contributions are welcomed and greatly appreciated. See [CONTRIBUTING.md](https://github.com/pingcap/community/blob/master/CONTRIBUTING.md) for details on submitting patches and the contribution workflow. | ||
|
||
### Step 4: Update TiDB to use the latest parser | ||
Here is how to [update parser for TiDB](https://github.com/pingcap/parser/blob/master/docs/update-parser-for-tidb.md). | ||
|
||
In your TiDB pull request, modify the `go.mod` file manually or use this command: | ||
## Acknowledgments | ||
|
||
``` | ||
GO111MODULE=on go get -u github.com/pingcap/parser@master | ||
``` | ||
Thanks [cznic](https://github.com/cznic) for providing some great open-source tools. | ||
|
||
Make sure the `replace` instruction is changed back to the `require` instruction and the version is the latest. | ||
## License | ||
Parser is under the Apache 2.0 license. See the LICENSE file for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.