Skip to content

Comments

feat: Add Transform's builtin functions#63

Merged
ducdetronquito merged 1 commit intomainfrom
task/PLA-2894
Feb 23, 2026
Merged

feat: Add Transform's builtin functions#63
ducdetronquito merged 1 commit intomainfrom
task/PLA-2894

Conversation

@ducdetronquito
Copy link
Contributor

@ducdetronquito ducdetronquito commented Feb 20, 2026

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.

@ducdetronquito ducdetronquito self-assigned this Feb 20, 2026
@ducdetronquito ducdetronquito requested a review from a team as a code owner February 20, 2026 11:05
@github-actions
Copy link
Contributor

🛡️ The security scan result : Repo and Config



def skip_row(reason: str | None) -> NoReturn:
raise SkippedRow(reason or "")
Copy link
Contributor Author

@ducdetronquito ducdetronquito Feb 20, 2026

Choose a reason for hiding this comment

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

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.

return mapping[key]
except KeyError as error:
_error = TransformError("No matching key in mapping")
_error.add_note(f"key = {key}")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

@ducdetronquito ducdetronquito merged commit dc1ee7a into main Feb 23, 2026
4 checks passed
@ducdetronquito ducdetronquito deleted the task/PLA-2894 branch February 23, 2026 09:28
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.

1 participant