CORB 给出 PRE-BATCH-MODULE 错误

问题描述 投票:0回答:1

我正在运行 CORB,但收到 URI 错误。下面是代码和 CORB 属性

THREAD-COUNT=4
URIS-MODULE=get-uri.xqy
PROCESS-MODULE=report.xqy
PROCESS-TASK=com.marklogic.developer.corb.ExportBatchToFileTask
EXPORT-FILE-NAME=report.xml
PRE-BATCH-MODULE=preProces.xqy
PRE-BATCH-TASK=com.marklogic.developer.corb.PreBatchUpdateFileTask

获取-uri.xqy代码:

let $uris := cts:uris((), (), cts:collection-query("InvoiceHistory"))
return (count($uris), $uris)

preProces.xqy代码:

declare variable $URI as xs:string external;

(: Retrieve all relevant records from the current document :)
let $records := fn:doc($URI)/records

(: Group records by creation_date and calculate the sum of doc_count for each group :)
let $grouped-records :=
                  for $date in distinct-values($records//document/@creation_date)
                  let $total := sum($records/document[@creation_date = $date]/@doc_count/xs:integer(.))
                  return <group date="{$date}" total-docs="{$total}"/>

  (: Serialize the grouped records as XML and store in a temporary collection :)
 let $temp-doc :=
               <results>{ $grouped-records }</results>

 return xdmp:document-insert("/temp/preprocessed.xml", $temp-doc)

报告.xqy代码:

declare namespace fn = "http://www.w3.org/2005/xpath-functions";
declare variable $URI as xs:string external;

(: Retrieve the preprocessed data :)
let $preprocessed := doc("/temp/preprocessed.xml")/results

(: Generate the final report :)
let $final-report :=
                <results>{
                           for $group in $preprocessed/group
                           order by $group/@date
                           return <result date="{$group/@date}" total-docs="{$group/@total-docs}"/>
                  }</results>

return $final-report

CORB 错误:

com.marklogic.developer.corb.CorbException: Undefined external variable at URI:
    at com.marklogic.developer.corb.AbstractTask.wrapProcessException(AbstractTask.java:426)
    at com.marklogic.developer.corb.AbstractTask.handleRequestException(AbstractTask.java:373)
    at com.marklogic.developer.corb.AbstractTask.invokeModule(AbstractTask.java:202)
    at com.marklogic.developer.corb.PreBatchUpdateFileTask.call(PreBatchUpdateFileTask.java:63)
    at com.marklogic.developer.corb.PreBatchUpdateFileTask.call(PreBatchUpdateFileTask.java:30)
    at com.marklogic.developer.corb.Manager.runPreBatchTask(Manager.java:790)
    at com.marklogic.developer.corb.Manager.populateQueue(Manager.java:857)
    at com.marklogic.developer.corb.Manager.run(Manager.java:603)
    at com.marklogic.developer.corb.Manager.main(Manager.java:140) Caused by: com.marklogic.xcc.exceptions.XQueryException: XDMP-EXTVAR:

(err:XPDY0002) 将变量 $URI 声明为 xs:string external; -- 未定义的外部变量 fn:QName("","URI")

哪里出了问题,有人可以建议吗?

xquery marklogic-10 marklogic-corb
1个回答
0
投票

PRE-BATCH 模块在开始处理所选的每个 URI 之前运行。它的供给方式与

PROCESS-MODULE
不同。 因此,

$URI

不会为

preProces.xqy
外部变量设置值,并且在执行时会抛出错误。
看起来 

$URI

实际上应该是

PROCESS-MODULE
,它将为每个选定的 URI 调用。但是,您将结果插入到静态 URI 中,并且每次运行时都会覆盖内容(并且速度会非常慢,因为对该 URI 的锁定会使事情成为单线程)。 如果您尝试生成合并的 XML 报告,您可能会考虑返回 XML 片段,即

preProcess.xqy

,而不是使用

return <results>{ $grouped-records }</results>
PRE-BATCH-MODULE=INLINE-XQUERY|"<results>"
插入数据库,然后所有内容都将写入
POST-BATCH-MODULE=INLINE-XQUERY|"</results>"
ExportBatchToFileTask 的输出文件。
    

© www.soinside.com 2019 - 2024. All rights reserved.