Skip to content

Commit 9f04ebe

Browse files
authored
Coding agents guidelines (#2298)
1 parent 073df28 commit 9f04ebe

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

AGENTS.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Extensible SQL Lexer and Parser for Rust Agents Guidelines
2+
3+
## General Agent Workflow
4+
1. You will write unit tests to ensure your code change is working as expected.
5+
2. You will run the commands in the Pre Commit Checks section below to ensure your change is ready for a pull request.
6+
3. When instructed to open a PR, you will follow the instructions in the Pull Request Guidelines section below.
7+
8+
## General Coding Guidelines
9+
1. Refrain from adding conditions on specific dialects, such as `dialect_is!(...)` or `dialect_of!(... | ...)`. Instead, define a new function in the `Dialect` trait that describes the condition, so that dialects can turn this condition on more easily.
10+
2. Make targeted code changes and refrain from refactoring, unless it's absolutely required.
11+
12+
## Unit Tests Guidelines
13+
- New unit tests should be added to the `tests` module in the corresponding dialect file (e.g., `tests/sqlparser_redshift.rs` for Redshift), and should be placed at the end of the file.
14+
- If the new functionality is gated using a dialect function, and the SQL is likely relevant in most dialects, tests should be placed under `tests/sqlparser_common.rs`.
15+
- When testing a multi-line SQL statement, use a raw string literal, i.e. `r#"..."#` to preserve formatting.
16+
- The parser builds an abstract syntax tree (AST) from the SQL statement and has functionality to display the tree as SQL. Use the following template for simple unit tests where you expect the SQL created from the AST to be the same as the input SQL:
17+
```rust
18+
<dialect>().verified_stmt(r#"..."#);
19+
```
20+
For example: `snowflake().verified_stmt(r#"SELECT * FROM my_table"#)`. Use `one_statement_parses_to` instead of `verified_stmt` when you expect the SQL created by the AST to differ than the input SQL. For example:
21+
```rust
22+
snowflake().one_statement_parses_to(
23+
"SELECT * FROM my_table t",
24+
"SELECT * FROM my_table AS t",
25+
)
26+
```
27+
28+
## Analyzing Parsing Issues
29+
You can try to simplify the SQL statement to identify the root cause of the parsing issue. This may involve removing certain clauses or components of the SQL statement to see if it can be parsed successfully. Additionally, you can compare the problematic SQL statement with similar statements that are parsed correctly to identify any differences that may be causing the issue.
30+
31+
## Pre Commit Checks
32+
Run the following commands before you commit to ensure the change will pass the CI process:
33+
```bash
34+
cargo test --all-features
35+
cargo fmt --all
36+
cargo clippy --all-targets --all-features -- -D warnings
37+
```
38+
39+
## Pull Request Guidelines
40+
1. PR title should follow this format: `<DIALECT>: <SHORT DESCRIPTION>`, For example, `Showflake: Add support for casting to VARIANT`.
41+
2. Make the PR comment short, provide an example of what was not working and a short description of the fix. Be succint.

dev/release/rat_exclude_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dev/release/rat_exclude_files.txt
66
sqlparser_bench/img/flamegraph.svg
77
**Cargo.lock
88
filtered_rat.txt
9+
AGENTS.md

0 commit comments

Comments
 (0)