我正在尝试使用 MarkLogics Optic API 进行算术以使用聚合函数,但出现以下错误:
message=OPTIC-INVALARGS: fn.error(null, 'OPTIC-INVALARGS', -- Invalid arguments: right argument at 1 of op.multiply value must have xs.numeric datatype: op.count(op.col('count_42'), null)
我正在向行端点请求:
POST http://marklogic:8000/LATEST/rows?database=SQLData HTTP/1.1
我正在尝试一个相当基本的查询,请参阅以下内容:
{
"$optic": {
"ns": "op",
"fn": "operators",
"args": [{
"ns": "op",
"fn": "from-view",
"args": [null, "employees", "e", null]
}, {
"ns": "op",
"fn": "select",
"args": [[{
"ns": "op",
"fn": "col",
"args": ["firstname"]
}, {
"ns": "op",
"fn": "col",
"args": ["lastname"]
}
], null]
}, {
"ns": "op",
"fn": "group-by",
"args": [[{
"ns": "op",
"fn": "col",
"args": ["firstname"]
}
], [{
"ns": "op",
"fn": "as",
"args": ["es", {
"ns": "op",
"fn": "multiply",
"args": [10, {
"ns": "op",
"fn": "count",
"args": ["count_42"]
}
]
}
]
}
]]
}
]
}
}
我不确定我是否做错了什么或者端点不支持聚合算术。如果有人有线索,我将不胜感激。
提前致谢。
op.count() 聚合不是表达式函数。与其他聚合一样,它填充列而不是返回值。该函数需要填充列的名称,并且必须出现在 groupBy() 操作的值列表的顶层:
http://docs.marklogic.com/op.count
应该可以将乘法表达式移动到后续的 select() 操作中,该操作将填充的计数列作为参数之一。换句话说,在分组操作之后,您可以像任何其他列一样在表达式中使用聚合列。
一般来说,通过在 QueryConsole 中使用 SJS 或 XQuery 构建器测试光学查询(使用 limit() 生成一个小的结果集),调试可能会更容易。一旦查询按预期工作,使用 op.export() 生成 JSON AST。
希望有帮助,