Skip to content

Commit

Permalink
feat: support GRAPH and pipe syntax
Browse files Browse the repository at this point in the history
Add support for GRAPH and pipe syntax queries to the database/sql driver.

Also adds the missing DDL keywords ANALYZE, GRANT, REVOKE, and RENAME.
  • Loading branch information
olavloite committed Jan 7, 2025
1 parent 076c631 commit 021a0f4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions statement_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
"google.golang.org/grpc/status"
)

var ddlStatements = map[string]bool{"CREATE": true, "DROP": true, "ALTER": true}
var selectStatements = map[string]bool{"SELECT": true, "WITH": true}
var ddlStatements = map[string]bool{"CREATE": true, "DROP": true, "ALTER": true, "ANALYZE": true, "GRANT": true, "REVOKE": true, "RENAME": true}
var selectStatements = map[string]bool{"SELECT": true, "WITH": true, "GRAPH": true, "FROM": true}
var dmlStatements = map[string]bool{"INSERT": true, "UPDATE": true, "DELETE": true}
var selectAndDmlStatements = union(selectStatements, dmlStatements)

Expand Down
28 changes: 28 additions & 0 deletions statement_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,14 @@ func TestRemoveStatementHint(t *testing.T) {
input: `@{JOIN_METHOD=HASH_JOIN} SELECT * FROM PersonsTable`,
want: `SELECT * FROM PersonsTable`,
},
{
input: `@{JOIN_METHOD=HASH_JOIN} FROM Produce |> WHERE item != 'bananas'`,
want: `FROM Produce |> WHERE item != 'bananas'`,
},
{
input: `@{JOIN_METHOD=HASH_JOIN} GRAPH FinGraph MATCH (n) RETURN LABELS(n) AS label, n.id`,
want: `GRAPH FinGraph MATCH (n) RETURN LABELS(n) AS label, n.id`,
},
{
input: `@ {JOIN_METHOD=HASH_JOIN} SELECT * FROM PersonsTable`,
want: `SELECT * FROM PersonsTable`,
Expand Down Expand Up @@ -841,6 +849,26 @@ func TestIsDdl(t *testing.T) {
input: " \t\n ",
want: false,
},
{
name: "analyze",
input: `analyze`,
want: true,
},
{
name: "grant",
input: `GRANT SELECT ON TABLE employees TO ROLE hr_rep;`,
want: true,
},
{
name: "revoke",
input: `REVOKE SELECT ON TABLE employees TO ROLE hr_rep;`,
want: true,
},
{
name: "rename",
input: `rename table foo to bar`,
want: true,
},
}

for _, tc := range tests {
Expand Down

0 comments on commit 021a0f4

Please sign in to comment.