Skip to content

sql: create common SQL parsing library to be used by mysql and postgres#11368

Merged
lizan merged 13 commits into
envoyproxy:masterfrom
cpakulski:issue/11320
Jun 11, 2020
Merged

sql: create common SQL parsing library to be used by mysql and postgres#11368
lizan merged 13 commits into
envoyproxy:masterfrom
cpakulski:issue/11320

Conversation

@cpakulski
Copy link
Copy Markdown
Contributor

Description:
Created sqlutils library to be shared for common functionality between SQL filters.
mysql and postgres filters will use that library to create filter metadata based on SQL query.
mysql filter was already producing metadata but postges will use the new library as described in #11065.

Risk Level:
Low: No new functionality has been added and only mysql_proxy filter is affected

Testing:
Added unit tests.

Docs Changes:
No.

Release Notes:
No.

Fixes: #11320

cpakulski added 3 commits May 27, 2020 21:52
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Fixed a bug in mysql testing routines which masked wrong results returned by SQL parser.

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
@cpakulski cpakulski requested a review from mattklein123 as a code owner May 29, 2020 18:04
cpakulski added 4 commits May 29, 2020 18:15
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
dio
dio previously requested changes Jun 4, 2020
Copy link
Copy Markdown
Member

@dio dio left a comment

Choose a reason for hiding this comment

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

Looks good, couple of notes:


class SQLutils {
public:
static bool setMetadata(const std::string& query, ProtobufWkt::Struct& metadata);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems like we need to add docs on this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see what you mean. Actually at this moment nothing changed from metadata point of view. Documentation for mysql is still valid:https://www.envoyproxy.io/docs/envoy/v1.14.1/configuration/listeners/network_filters/mysql_proxy_filter.html?highlight=metadata#dynamic-metadata.
When I link this setMetadata to Postgres filter I will create similar docs describing what metadata is created by Postgres filter, but this will happen once this PR is merged.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think @dio meant doxygen style doc for this method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added.

Comment thread source/extensions/common/sqlutils/sqlutils.h Outdated
::testing::Values(
TEST_VALUE("blahblah;", false, {}),

TEST_VALUE("CREATE TABLE IF NOT EXISTS table1(Usr VARCHAR(40),Count INT);", true,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we check for all lowercased queries?

create tabel if not exists table1(usr varchar(40),count int);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed testing routine to convert queries to lowercase and uppercase, so all different variants are tested.

cpakulski added 3 commits June 4, 2020 18:30
test queries.

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
@cpakulski
Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Commenter does not have sufficient privileges for PR 11368 in repo envoyproxy/envoy


class SQLutils {
public:
static bool setMetadata(const std::string& query, ProtobufWkt::Struct& metadata);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think @dio meant doxygen style doc for this method.

Comment thread test/extensions/common/sqlutils/sqlutils_test.cc Outdated
Comment thread test/extensions/common/sqlutils/sqlutils_test.cc Outdated

/*
* Test query: "DROP DATABASE <DB>"
* Test is disabled because of a bug in SQL parsing library.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wouldn't this be a regression?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The bug was always there and this PR does not change anything. The old behaviour is preserved. The SQL parser has a bug and produces wrong output for DROP DATABASE. The old unit tests in mysql had another bug which masked SQL parser's bug. In https://github.com/envoyproxy/envoy/blob/release/v1.14/test/extensions/filters/network/mysql_proxy/mysql_command_test.cc#L205-L209 if expected_table_access_map is empty, the routine does NOT check what was parser's result, which is stored in table_access_map. In case of DROP DATABASE the table_access_map is not empty, but old unit test never checked that.

I changed how parsing results are accessed and this uncovered the bug.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

then can we either delete these tests or fix them? I don't think we want permanently disabled test live in the code base.

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
@cpakulski cpakulski requested a review from lizan June 8, 2020 17:15
Copy link
Copy Markdown
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

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

LGTM except the test.


/*
* Test query: "DROP DATABASE <DB>"
* Test is disabled because of a bug in SQL parsing library.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

then can we either delete these tests or fix them? I don't think we want permanently disabled test live in the code base.

Enabled unit tests for DROP DATABASE after fix in sql-parser library.

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
@cpakulski
Copy link
Copy Markdown
Contributor Author

Fixed issue with DROP DATABASE: envoyproxy/sql-parser#3.

Now all tests are enabled and they pass.

@cpakulski cpakulski requested a review from lizan June 10, 2020 19:42
@cpakulski
Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only
Copy link
Copy Markdown

🤷‍♀️ nothing to rebuild.

🐱

Caused by: a #11368 (comment) was created by @cpakulski.

see: more, trace.

lizan
lizan previously approved these changes Jun 11, 2020
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
@lizan lizan dismissed dio’s stale review June 11, 2020 17:35

dio is OOO

@lizan lizan merged commit 8b4c943 into envoyproxy:master Jun 11, 2020
@cpakulski cpakulski deleted the issue/11320 branch June 12, 2020 18:33
arthuryan-k pushed a commit to arthuryan-k/envoy that referenced this pull request Jun 15, 2020
…es (envoyproxy#11368)

Description:
Created _sqlutils_ library to be shared for common functionality between SQL filters.
mysql and postgres filters will use that library to create filter metadata based on SQL query.
mysql filter was already producing metadata but postges will use the new library as described in envoyproxy#11065.

Risk Level:
Low: No new functionality has been added and only mysql_proxy filter is affected

Testing:
Added unit tests.

Docs Changes:
No.

Release Notes:
No.

Fixes: envoyproxy#11320

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Arthur Yan <arthuryan@google.com>
yashwant121 pushed a commit to yashwant121/envoy that referenced this pull request Jun 24, 2020
…es (envoyproxy#11368)

Description:
Created _sqlutils_ library to be shared for common functionality between SQL filters. 
mysql and postgres filters will use that library to create filter metadata based on SQL query.
mysql filter was already producing metadata but postges will use the new library as described in envoyproxy#11065. 

Risk Level:
Low: No new functionality has been added and only mysql_proxy filter is affected

Testing:
Added unit tests.

Docs Changes:
No.

Release Notes:
No.

Fixes: envoyproxy#11320

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: yashwant121 <yadavyashwant36@gmail.com>
songhu pushed a commit to songhu/envoy that referenced this pull request Jun 25, 2020
…es (envoyproxy#11368)

Description:
Created _sqlutils_ library to be shared for common functionality between SQL filters. 
mysql and postgres filters will use that library to create filter metadata based on SQL query.
mysql filter was already producing metadata but postges will use the new library as described in envoyproxy#11065. 

Risk Level:
Low: No new functionality has been added and only mysql_proxy filter is affected

Testing:
Added unit tests.

Docs Changes:
No.

Release Notes:
No.

Fixes: envoyproxy#11320

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
yashwant121 pushed a commit to yashwant121/envoy that referenced this pull request Jul 24, 2020
…es (envoyproxy#11368)

Description:
Created _sqlutils_ library to be shared for common functionality between SQL filters. 
mysql and postgres filters will use that library to create filter metadata based on SQL query.
mysql filter was already producing metadata but postges will use the new library as described in envoyproxy#11065. 

Risk Level:
Low: No new functionality has been added and only mysql_proxy filter is affected

Testing:
Added unit tests.

Docs Changes:
No.

Release Notes:
No.

Fixes: envoyproxy#11320

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: yashwant121 <yadavyashwant36@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create sql library to be used by mySQL and postgres filters

3 participants