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.
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.
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.
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.
| 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.
Shouldn't we also assert the parameterized_properties here?
There was a problem hiding this comment.
👌 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 valuesand #31 if you have a better name recommendation, please go ahead :PChecklist