我在Sesam中有一个http转换,它从REST api读取实体并写入数据集。
{
"_id": "read-entities",
"type": "pipe",
"source": {
"type": "dataset",
"dataset": "global-entities"
},
"transform": [{
"type": "dtl",
"rules": {
"default": [
["copy", "*"],
["add", "::foo",
["first", "_S.entity:foo"]
]
]
}
}, {
"type": "http",
"system": "entities",
"url": "/transform"
}, {
"type": "dtl",
"rules": {
"default": [
["add", "entities", "_S.response"]
]
}
}]
}这是我得到的回应:
[
{
"_id": "namespace:fuubar",
"entities:entity": [
{
"foo":"baz"
}
]
}
]除了来自源数据集的"_id“之外,实体到达时没有名称空间,是否有为"read-entites"-pipe添加名称空间的方法?
谢谢
发布于 2018-02-01 05:44:44
这可以通过将规则应用于每个对象来解决,在每个对象中,通过在对象的键前加上名称空间来映射它们,如果值是字典(JSON对象),则有条件地递归地应用此规则:
{
"_id": "recursively-add-namespaces",
"type": "pipe",
"source": {
"type": "embedded",
"entities": [{
"_id": "namespace:fuubar",
"entities:entity": [{
"foo": "baz",
"nested": {
"bar": "foobar"
}
}]
}]
},
"transform": {
"type": "dtl",
"rules": {
"default": [
["add", "::namespaced-entity",
["apply", "add-my-ns", "_S.entities:entity"]
]
],
"add-my-ns": [
["merge",
["map-dict",
["concat", "my-ns:", "_."],
["if",
["is-dict", "_."],
["apply", "add-my-ns", "_."], "_."], "_S."]
]
]
}
},
"add_namespaces": false
}这将产生以下结果:
[
{
"_id": "namespace:fuubar",
"namespaced-entity": [
{
"my-ns:foo": "baz",
"my-ns:nested": {
"my-ns:bar": "foobar"
}
}
]
}
]https://stackoverflow.com/questions/48170426
复制相似问题