feat: Add Transform's builtin functions#63
Conversation
|
|
||
|
|
||
| def skip_row(reason: str | None) -> NoReturn: | ||
| raise SkippedRow(reason or "") |
There was a problem hiding this comment.
Useful to emulate a early return because this construct does not exist in JSONata as it is an expression based language where only the last expression is returned.
magicparse/transform.py
Outdated
| return mapping[key] | ||
| except KeyError as error: | ||
| _error = TransformError("No matching key in mapping") | ||
| _error.add_note(f"key = {key}") |
There was a problem hiding this comment.
I'm wondering if I should add exception note like this for every other builtin functions: it could help a lot to debug if we have the inputs as notes.
| return Transform(expr=expression) | ||
| def __init__(self, expression: str) -> None: | ||
| super().__init__(expression) | ||
| self.validate_input = False |
There was a problem hiding this comment.
By default, JSONata validate that the input it evaluates (the data, not the expression) is only composed of JSON values like int, float, map, list, null.
But it does not support python Decimal object which we use a lot.
In order to allow that, and reduce unecessary input validation which is costly and likely redundant, I just disable it by default.
10b9727 to
7012ccc
Compare
These functions should be shipper as builtins as they are very general and useful in many cases.
With this feature set I was able to implement an equivalent to almost all parser + post processor for the article import process.