计算文件数量并列出基于源的文件。
输入:
[
{
"filename": "FF/raw/first/raw_A/filenameA_20240212002113.DAT"
},
{
"filename": "FF/raw/first/raw_A/filenameA__20240205150101.DAT"
},
{
"filename": "FF/raw/first/raw_B/filenameB_20240212002113.DAT"
},
{
"filename": "FF/raw/first/raw_B/filenameB_20240205150101.DAT"
}
]
预期输出:
[
{
"Source": "raw_A",
"Filecount": 2,// Number of files that indicates in fileNames
"FileName": [
"filenameA_20240212002113.DAT",
"filenameA_20240205150101.DAT"
]
},
{
"Source": "raw_B",
"Filecount": 2,
"FileName": [
"filenameB_20240212002113.DAT",
"filenameB_20240205150101.DAT"
]
}
]
我在震动规格中尝试过的:
[ { “操作”:“转移”, “规格”:{ “”:{ “”:{ "////": "Source:&(0,4):filecount:: Filename.&(0,5)" // 使用第 5 个星号提取叶节点,例如使用 &(0,5) } } } }, { “操作”:“转移”, “规格”:{ “”:{ “”:{ "$": "&2.[#2]" } } } }, { “操作”:“修改覆盖测试版”, “规格”:{ “”:{ "文件计数": "=大小(@(1,&文件名))" } } },
{ “操作”:“转移”, “规格”:{ “”:{ "": "[#2].&1" } } } ]
您可以使用以下转换
[
{ // group objects by raw_A & B
"operation": "shift",
"spec": {
"*": {
"*": {
"*/*/*/*/*": {
"$(0,5)": "&(1,4).FileName"
}
}
}
}
},
{ // calculate the lengths of "FileName" arrays
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"Filecount": "=size(@(1,FileName))"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"$": "[#2].Source", // convert values of object keys to an attribute's values
"*": "[#2].&"
}
}
}
]
网站上的 演示 https://jolt-demo.appspot.com/ 是: