【问题标题】:MarkLogic Optic API aggregate arithmeticsMarkLogic 光学 API 聚合算法
【发布时间】:2023-03-12 09:20:01
【问题描述】:

我正在尝试使用 MarkLogics Optic API 让 Arithmetics 与聚合函数一起使用,但出现以下错误:

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"]
                                    }
                                ]
                            }
                        ]
                    }
                ]]
        }
    ]
  }
}

我不确定我做错了什么,或者端点不支持聚合算术。如果有人有线索,将不胜感激。

提前致谢。

【问题讨论】:

    标签: marklogic


    【解决方案1】:

    op.count() 聚合不是表达式函数。与其他聚合一样,它填充列而不是返回值。该函数需要填充列的名称,并且必须出现在 groupBy() 操作的值列表的顶层:

    http://docs.marklogic.com/op.count

    应该可以将乘法表达式移动到后续的 select() 操作中,该操作将填充的计数列作为参数之一。换句话说,在分组操作之后,您可以像使用任何其他列一样,在表达式中使用聚合列。

    通常,通过在 QueryConsole 中使用 SJS 或 XQuery 构建器测试光学查询(使用 limit() 生成一个小的结果集),调试可能会更容易。一旦查询按预期工作,使用 op.export() 生成 JSON AST。

    希望对您有所帮助,

    【讨论】:

    • 谢谢!将算法应用于聚合的别名到第二批选择作品。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    • 2017-09-13
    • 2019-03-02
    • 2014-05-24
    相关资源
    最近更新 更多