Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions v3/newrelic/sqlparse/sqlparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
"alter": nil,
"commit": nil,
"rollback": nil,
"with": nil,
}
firstWordRegex = regexp.MustCompile(`^\w+`)
cCommentRegex = regexp.MustCompile(`(?is)/\*.*?\*/`)
Expand Down
10 changes: 10 additions & 0 deletions v3/newrelic/sqlparse/sqlparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,13 @@ func TestExtractTable(t *testing.T) {
}
}
}
func TestParseSQLWith(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test case using WHERE as not the first word to be parsed and check if proper operation is picked up. Could be as a subquery added to TestParseSQLSubQuery or add a test checking WITH and operations where Input contains multiple queries i.e.

{Input: "Select * FROM cte; WITH cte AS (SELECT * FROM users) SELECT * FROM cte;", Operation: "select", Table: "cte"}

for _, tc := range []sqlTestcase{
{Input: "WITH cte AS (SELECT * FROM users) SELECT * FROM cte", Operation: "with", Table: ""},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Table (newrelic.DatastoreSegment.Collection) not get populated in this case?

{Input: "WITH RECURSIVE cte AS (SELECT id FROM employees) SELECT * FROM cte", Operation: "with", Table: ""},
{Input: "with temp AS (SELECT id FROM foo) SELECT * FROM temp", Operation: "with", Table: ""},
{Input: " WITH cte AS (SELECT * FROM bar) SELECT * FROM cte", Operation: "with", Table: ""},
} {
tc.test(t)
}
}
Loading