简体   繁体   English

MarkLogic 中的光学查询错误 - 无效强制:map:map

[英]Error in Optic query in MarkLogic - Invalid coercion: map:map

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.尝试获取基于特定条件的记录占另一条记录总数的百分比时,我收到无效的 map 错误。 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.下面的代码试图在辅助报价大于 0 时获取所有 6 个月前的辅助报价价格占发货参考总数的百分比。我正在使用预订日期来计算 6 个月前的日期范围。

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 &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>)

The error is telling you that the $qualifier parameter is a map and cannot be converted to xs:string .该错误告诉您$qualifier参数是 map 并且不能转换为xs:string

If you look at the signature of the op:select function:如果您查看操作的签名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.您将看到$qualifier是第三个参数。

When using the => , the plan is being set as the first parameter for you.使用=>时,计划被设置为您的第一个参数。 The columns for the op:select() are the second parameter. op:select()的列是第二个参数。 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 .否则,您似乎将$Var3指定为 select 的列,然后将percentage列指定为$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")))) )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM