-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ACM-12279 | feat: Add a sql parser feature #55
Conversation
Thanks for your quick response. I have some comments:
|
It does. Please look here for some JSONB examples. And here for the specific query you asked for If you want to look at how the grammar is defined, you can find the list of supported tokens here and the list of valid transitions here I moved all the packages into a |
/ok-to-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/ok-to-test |
/assign @ciaranRoche Have discussed with @ziccardi , the SQL parser should a common tool so that it can be shared by fleet manager / maestro and other cluster services. Thanks @ziccardi to contribute it. Hi @ciaranRoche Are you fine to have this SQL parser in this repo? Thanks. |
Adds sql_parser, state_machine, string_parser, string_scanner utlity. They are all needed for the SQLParser.
This PR adds few utilities to the
ocm-common
package:?
placeholders and returns an array of the extracted values.Currently the provided GRAMMAR can parse only WHERE clauses, but it can be easily extended.
See pkg/utils/parser/sql_parser/README.md for details.
For examples of supported strings and validations, look at the tests
This object provides a
SQLGrammar
and aSQLScanner
and depends on the StringParserScanner
and aGrammar
, parses a string and ensure it conforms to the provided grammar.This object depends on the
Scanner
and theStateMachine
objects. (see pkg/utils/parser/string_parser/README.md for details)Scanner
must be implemented to scan the string as required. The package provides aStringScanner
as an example that considers each character a token (see pkg/utils/parser/string_scanner/README.md for details)acceptor
function that defines what values are acceptable for that state, then all the transitions must be defined for each state. The state-machine will then be able to decide autonomously what is the next state, based on the received input (see pkg/utils/parser/state_machine/README.md for details).SQL Parser Features
Supported tokens
The
SQL parser
uses theString Parser
, which in turn takes aGrammar
and aScanner
to parse and validate a string.The
SQL Parser
thus provides aSQLGrammar
and aSQLScanner
to theStringScanner
. Thanks to this, adding new tokens is just a matter of updating theSQL Grammar
.The
Grammar
provided in this PR supports the following tokens: COLUMN_NAME, LITERAL, OPEN_BRACE, CLOSED_BRACE, '=', '>', '<', '>=', '<=', '<>', 'LIKE', 'ILIKE', 'IN', 'AND', 'OR', 'NOT', '->', '@>' and all the valid transitions between these tokens.Security features
When instantiating a
SQLParser
, you can limit the maximum query complexity (maximum number of logic operators: defaults to 10) and the list of column names that are allowed to be inserted into the query.Here a few examples:
accept any column: in this example, any column is accepted
accept only the surname column:
In this case, the parser will return an error:
[1] error parsing the filter: invalid column name: 'name', valid values are: [surname]
limit both columns and complexity
In this case we will get an error due to a too high complexity: "[60] error parsing the filter: maximum number of permitted joins (2) exceeded"