-
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 shape
transform
#750
Comments
Would be awesome if this new transform support string split, like the example below from {
"args": "a=1&b=2&c"
} to {
"args_a": "1",
"args_b": "2",
"args_c": "" nginx produces this kind of log http://nginx.org/en/docs/http/ngx_http_core_module.html#var_args My current implementation is using lua, but it's not elegant [transforms.parse_args]
type = "lua"
inputs = ["datasource"]
source = """
function Split(szFullString, szSeparator)
local nFindStartIndex = 1
local nSplitIndex = 1
local nSplitArray = {}
while true do
local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
if not nFindLastIndex then
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
break
end
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)
nFindStartIndex = nFindLastIndex + string.len(szSeparator)
nSplitIndex = nSplitIndex + 1
end
return nSplitArray
end
local args = Split(event["args"], "&")
for i, arg in ipairs(args) do
local arg_d = Split(arg, "=")
if arg_d[1] and arg_d[2] then
local key = string.format("args_%s", arg_d[1], arg_d[2])
event[key] = arg_d[2]
elseif arg_d[1] then
local key = string.format("args_%s", arg_d[1])
event[key] = ""
end
end
""" |
It would also be cool to add some sort of {
"id": "whatever",
"foo": [1,2]
} Into two events: { "id": "whatever", "foo": 1 }
{ "id": "whatever", "foo": 2 } |
I like the "expand" idea. I added the |
Just adding a couple of libraries here for inspiration: |
To clarify, we probably shouldn't use these libraries, but we can expose a similar interface: [transforms.change_it_up]
type = "shape"
changes = [
{add.new_field = "my value"},
{add.parent.child = "this is a nested field value"},
{coerce.another_field = "int"},
{rename.old_field = "new_name"},
{remove.bad_field = true}
] This is a very rough example, but you get the idea. The awkwardness with the above syntax is removing fields, but you get the idea. |
Finally, another interesting source of inspiration is the
It's proven to be a powerful succinct syntax that engineers already understand. I'm not proposing that this interface would power the generic |
Definitely! Also don't forget fields coping. Parsing query strings for me sounds like a task to a separate transform. Even with add+remove+copy+rename you need to define some strict rules to not confuse users. |
Agree! And thanks for the feedback. @Hoverbear is working all of this right now. She's putting together a rough guide on schema management that will summarize the work we do here. Would love to get your thoughts when that is done. |
@anton-ryzhov I agree about query strings! If we do end up combing |
@binarylogic Bumblebee looks pretty compelling, it's just a sequence of steps. I worry Proteus feels very custom with that DSL. |
@binarylogic That example in #750 (comment) is unfortunately not valid toml. :( Here's the closest I could come up with that is valid and clean: [transforms.change_it_up]
type = "shape"
inputs = ["my-source-id"]
[[transforms.change_it_up.changes]]
add = "new_field"
value = "my value" # All value fields below allow templating.
[[transforms.change_it_up.changes]]
create = "parent.child" # Users can escape with \. for period-containing fields.
value = "this is a nested value"
[[transforms.change_it_up.changes]] # Consider leaving this as a separate transform.
rename = "old_field"
to = "new_name"
[[transforms.change_it_up.changes]]
remove = "bad_field" # Optionally an array
|
Say what? Tom... Before we decide on this change, we probably need to clarify #1731. Because I'm wondering if a higher-level solution like the We'll make a decision on Monday what to do here. |
We need a better way to add, remove, rename, and possibly coerce fields in one shot. If simple enough, this could replace the
add_fields
,remove_fields
, andcoerce
transform.I'm open to better naming, such as simply
transform
.Ref #377
The text was updated successfully, but these errors were encountered: