Marklogic中的视觉查询错误 - 无效胁迫:地图:地图

发布于 2025-02-12 19:27:07 字数 2033 浏览 1 评论 0原文

试图根据一定条件获得其他记录的总数时,我会遇到无效的地图错误。 您可以在我的代码中帮助您确定问题吗?

以下代码试图将所有6个月历史的辅助价格的数量的百分比达到辅助报价价格大于0时的货运参考总数。我正在预订日期来计算6个月大的日期范围。

这是我正在尝试的光学查询 -

xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic" at "/MarkLogic/optic.xqy";
import module namespace ofn="http://marklogic.com/optic/expression/fn" at "/MarkLogic/optic/optic-fn.xqy";
import module namespace osql="http://marklogic.com/optic/expression/sql" at "/MarkLogic/optic/optic-sql.xqy";  
declare option xdmp:mapping "false";
let $view := op:from-view("GTM2_Shipment", "Shipment_View")
let $Var1 := op:view-col("Shipment_View", "Ancillary_QuotePrice")
let $Var2 := op:view-col("Shipment_View", "Shipment_Ref")
let $Var3 := op:view-col("Shipment_View", "BookingCreateDt")
return $view
=> op:group-by("transMode",(op:count("Var2", $Var2),op:count("Var1", $Var1)))
=> op:where(op:and((
                   op:gt($Var1, 0),op:gt(ofn:format-dateTime($Var3, '[Y0001]-[M01]-[D01]'),osql:dateadd('month',-6, ofn:format-dateTime(fn:current-dateTime(),'[Y0001]-[M01]-[D01]')))

                   ))
                   )
=>op:select(op:as("multiply", op:divide(op:col("Var1"), op:col("Var2"))))
=>op:select($Var3,op:as("percentage", op:multiply(100, op:col("multiply"))))
=> op:result()

这是我遇到的错误 -

[1.0-ml] XDMP-AS: (err:XPTY0004) $qualifier as xs:string? -- Invalid coercion: map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>) as xs:string
Stack Trace
In /MarkLogic/optic.xqy on line 685
In xdmp:eval("xquery version &quot;1.0-ml&quot;;&#10;import module namespace o...", (), <options xmlns="xdmp:eval"><database>16857865358322067141</database>...</options>)
In xdmp:eval("xquery version &quot;1.0-ml&quot;;&#10;import module namespace o...", (), <options xmlns="xdmp:eval"><database>16857865358322067141</database>...</options>)

I am getting an invalid map error when trying to get the percentage of a record based on a certain condition to the total count of another record.
Can you please help to identify the issue here in my code.

The below code is trying to get the percentage of the count of all 6 months old AncillaryQuote price to the total no of Shipments References when the Ancillary quote price is greater than 0 . I am taking Booking Date to calculate the 6 months old date range.

Here is my optic query which I am trying -

xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic" at "/MarkLogic/optic.xqy";
import module namespace ofn="http://marklogic.com/optic/expression/fn" at "/MarkLogic/optic/optic-fn.xqy";
import module namespace osql="http://marklogic.com/optic/expression/sql" at "/MarkLogic/optic/optic-sql.xqy";  
declare option xdmp:mapping "false";
let $view := op:from-view("GTM2_Shipment", "Shipment_View")
let $Var1 := op:view-col("Shipment_View", "Ancillary_QuotePrice")
let $Var2 := op:view-col("Shipment_View", "Shipment_Ref")
let $Var3 := op:view-col("Shipment_View", "BookingCreateDt")
return $view
=> op:group-by("transMode",(op:count("Var2", $Var2),op:count("Var1", $Var1)))
=> op:where(op:and((
                   op:gt($Var1, 0),op:gt(ofn:format-dateTime($Var3, '[Y0001]-[M01]-[D01]'),osql:dateadd('month',-6, ofn:format-dateTime(fn:current-dateTime(),'[Y0001]-[M01]-[D01]')))

                   ))
                   )
=>op:select(op:as("multiply", op:divide(op:col("Var1"), op:col("Var2"))))
=>op:select($Var3,op:as("percentage", op:multiply(100, op:col("multiply"))))
=> op:result()

Here is the error I am getting -

[1.0-ml] XDMP-AS: (err:XPTY0004) $qualifier as xs:string? -- Invalid coercion: map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>) as xs:string
Stack Trace
In /MarkLogic/optic.xqy on line 685
In xdmp:eval("xquery version "1.0-ml";
import module namespace o...", (), <options xmlns="xdmp:eval"><database>16857865358322067141</database>...</options>)
In xdmp:eval("xquery version "1.0-ml";
import module namespace o...", (), <options xmlns="xdmp:eval"><database>16857865358322067141</database>...</options>)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

来世叙缘 2025-02-19 19:27:08

该错误告诉您$限制符参数是映射,不能将其转换为XS:String

如果您查看 op:select 函数:

op:select(
   $plan as map:map,
   $columns as columnIdentifier*,
   [$qualifier as xs:string?]
) as map:map

您会看到$限制符是第三个参数。

当使用=&GT;时,计划将作为您的第一个参数。 op:select()的列是第二个参数。但是,您需要提供这些列作为序列(用())。否则,您似乎将$ var3指定为要选择的列,然后将百分比列作为$ $ feolifier

更改:

=> op:select($Var3, op:as("percentage", op:multiply(100, op:col("multiply"))))

到:

=> op:select( ($Var3,op:as("percentage", op:multiply(100, op:col("multiply")))) )

The error is telling you that the $qualifier parameter is a map and cannot be converted to xs:string.

If you look at the signature of the op:select function:

op:select(
   $plan as map:map,
   $columns as columnIdentifier*,
   [$qualifier as xs:string?]
) as map:map

You will see that $qualifier is the third parameter.

When using the =>, the plan is being set as the first parameter for you. The columns for the op:select() are the second parameter. However, you need to provide those columns as a sequence (wrap with ()). Otherwise, it appears that you are specifying $Var3 as the columns to select, and then the percentage column as the $qualifier.

Change:

=> op:select($Var3, op:as("percentage", op:multiply(100, op:col("multiply"))))

to:

=> op:select( ($Var3,op:as("percentage", op:multiply(100, op:col("multiply")))) )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文