marklogic - MarkLogic 光学 API 聚合算法
问题描述
我正在尝试使用 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。
希望有帮助,
推荐阅读
- postgresql - 将变量从一个 sql 脚本传递到另一个作为 postgres sql 中的参数
- firebase - 如何在 Flutter 中查询其字段值包含在本地列表变量中的 Firestore 数据
- c# - 使用 linq 排序、区分并选择前 5 个结果
- powershell - Test-WSMan 上的 if/else 语句
- javascript - 从有效负载中删除密钥
- google-sheets - 与多个工作表相比,识别列表中的新项目
- ansible - import_role 和 include_role 在变量优先级方面的区别
- reactjs - 在循环中将项目添加到状态数组
- reactjs - yup.js 验证数字字段大于兄弟,或可为空
- jinja2 - 块和块周围的jinja2空白控制