-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
New remap
transform v1
#3119
Comments
There are two major remaining features that ought to be added to the remap transform which in my view would otherwise block it from replacing all the current mapping transforms. Those two features are type coercion and error handling. Type coercion is straight forward and in order to fit this in nicely with our existing syntaxes I would suggest we start small and add query functions (one for each type) that take a path parameter, it would look like this: mapping = """
.id = string(.id)
.bytes_in = int(.bytes_in)
.bytes_out = int(.bytes_in)
.timestamp = timestamp(.timestamp, "%d/%m/%Y:%H:%M:%S %z")
.status = int(.status)
""" However, we're now introducing more ways in which our mappings might fail, and therefore it would be nice to be able to specify per-field how (and whether) to recover in the event where these type coercions cannot be performed. I suggest we allow an optional second parameter for these functions that defines the default value to use if for any reason the coercion is going to fail (the field doesn't exist, its value cannot be converted, etc). It would look like this: mapping = """
.id = string(.id)
.bytes_in = int(.bytes_in, 0)
.bytes_out = int(.bytes_in, 0)
.timestamp = timestamp(.timestamp, "%d/%m/%Y:%H:%M:%S %z")
.status = int(.status, 200)
""" Note that in this example we don't specify a default for the field .timestamp = timestamp(string(.timestamp, "11/10/1946:12:00:00 -0400"), "%d/%m/%Y:%H:%M:%S %z") This syntax would also solve general purpose error handling as it would allow users to specify type assertions and also fallback values in the case where the target paths don't exist. |
If it's possible, I think allowing defaulting to null would be nice too for cases where the field cannot be coerced (or is missing). I think this would presumably look something like:
I suppose there is also a distinction between |
Sounds good, I think allowing |
The first version is mostly focused on laying a solid foundation that:
The text was updated successfully, but these errors were encountered: