我正在尝试从列表中删除null
,not set
,""
值。尽管我似乎找不到解决此问题的解决方案/功能。
用例:
尝试了一堆不同的功能,即如果需要则剥离,替换...
管道配置
{
"_id": "jonas-testing",
"type": "pipe",
"source": {
"type": "embedded",
"entities": [{
"_id": "1",
"list": [1, 2, 3, 4]
}]
},
"transform": {
"type": "dtl",
"rules": {
"default": [
["copy", "*"],
["add", "_this-is-a-list-for-testing",
["list", "foo", "", "bar", "baz"]
],
["add", "list-with-no-nulls",
["if",
["eq", "_T._this-is-a-list-for-testing", ""],
["strip", "", "_T._this-is-a-list-for-testing"],
["strip", "", "_T._this-is-a-list-for-testing"]
]
]
]
}
}
}
结果
[
{
"_id": "1",
"_this-is-a-list-for-testing": [
"foo",
"",
"bar",
"baz"
],
"list": [
1,
2,
3,
4
],
"list-with-no-nulls": [
"foo",
"",
"bar",
"baz"
]
}
]
预期结果
[
{
"_id": "1",
"_this-is-a-list-for-testing": [
"foo",
"",
"bar",
"baz"
],
"list": [
1,
2,
3,
4
],
"list-with-no-nulls": [
"foo",
"bar",
"baz"
]
}
]
答案 0 :(得分:0)
使用带有“ is-not-null”或“ neq”的“ filter”函数来过滤出空值或空字符串值:
{
"_id": "jonas-testing",
"type": "pipe",
"source": {
"type": "embedded",
"entities": [{
"_id": "1",
"list": [1, 2, 3, 4]
}]
},
"transform": {
"type": "dtl",
"rules": {
"default": [
["copy", "*"],
["add", "_this-is-a-list-for-testing",
["list", "foo", "", "bar", "baz"]
],
["add", "list-with-no-empty-strings",
["filter", ["neq", "", "_."], "_T._this-is-a-list-for-testing"]
],
["add", "list-with-no-nulls",
["filter", ["is-not-null", "_."], "_T._this-is-a-list-for-testing"]
]
]
}
}
}