-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add with_properties
and interpolated_properties
#37
Conversation
22d33c7
to
34ad12c
Compare
cratedb_sqlparse_py/README.md
Outdated
# Metadata(schema='doc', table_name='tbl12', interpolated_properties={}, with_properties={'allocation.max_retries': '5', 'blocks.metadata': 'false'}) | ||
``` | ||
|
||
#### Interpolated properties. |
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.
I don't get what's the value of splitting those into an extra key in metadata
.
Could you please explain what is the thought behind this?
(If we keep it, for the name I think Query parameterized properties
sounds a bit better)
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.
Just conveniency, so users don't need to constantly filter properties to get those that are parametrized, without this I see myself (as an user) extending the API to filter this parameters.
I like parameterized properties
. 👍
def visitTableName(self, ctx: SqlBaseParser.TableNameContext): | ||
fqn = ctx.qname() | ||
parts = self.get_text(fqn).replace('"', "").split(".") | ||
parts = self.get_text(fqn).split(".") |
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.
You might be interested in this utility methods, and their corresponding improvements?
cratedb_sqlparse_py/README.md
Outdated
# Metadata(schema='doc', table_name='tbl12', interpolated_properties={'blocks.metadata': '$1'}, with_properties={'allocation.max_retries': '5', 'blocks.metadata': '$1'}) | ||
``` | ||
|
||
In this case, both `blocks.metadata` will be in `with_properties` and `interpolated_properties`. |
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.
In this case, both `blocks.metadata` will be in `with_properties` and `interpolated_properties`. | |
In this case, `blocks.metadata` will be in `with_properties` and `interpolated_properties` as well. |
34ad12c
to
13abbca
Compare
assert all(x in stmt.metadata.parameterized_properties for x in keys) | ||
assert all(x in stmt.metadata.with_properties for x in keys) | ||
assert stmt.metadata.with_properties["key"] == "$1" | ||
assert stmt.metadata.with_properties["key2"] == "$2" |
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.
Shouldn't we also assert the parameterized_properties here?
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.
👌 Not only that but we can just do
expected = {'key': 'val', 'key2': '2'}
# Has all the keys.
assert stmt.metadata.with_properties == expected
Summary of the changes / Why this is an improvement
This PR allows for extracting properties defined by
[ WITH ( parameter [= value] [, ... ] ) ]
statements.For example:
It also handles the special case of what I call,
interpolated values
and #31 if you have a better name recommendation, please go ahead :PChecklist