windows 了解MarkLogic CoRB处理

thtygnil  于 2023-04-22  发布在  Windows
关注(0)|答案(1)|浏览(112)

我目前正在学习MarkLogic数据库,并且正在研究CoRB批处理(在Windows上运行)。
/customer1~10.xml

<?xml version="1.0" encoding="UTF-8"?>
<customer>
  <name>Customer1</name>
  <address>123 Main St</address>
  <company>A Corporation</company>
  <emailAddress>customer1@mail.com</emailAddress>
</customer>

<address><company>对于接下来的9个数据集都相同。
现在,我的目标是使用Uri.xqy遍历所有/Customer*.xml数据,并将<emailAddress>从www.example.com更改customer1@mail.com为customer1@changed.mail.com。
我一直在尝试下面的查询,它不会返回任何东西。
URI

xquery version "1.0-ml";

declare variable $target as xs:string external;

let $uris := cts:uris((), (), cts:directory-query($target, "infinity"))
return(
  fn:count($uris),
  $uris
)

工艺流程

xquery version "1.0-ml";

declare variable $URI as xs:string external;

let $docnew := cts:search(fn:doc(), cts:document-query(fn:tokenize($URI, ";")))
for $doc in $docnew
let $new-email := fn:replace($doc//emailAddress/text(), "customer.*@mail.com", "customer*@changed.mail.com")
return
  xdmp:node-replace($doc//emailAddress, $new-email)

和下面的corb命令,我在端口9000上创建了一个app-server(XDBC),它有“documents”作为数据库,“modules”作为modules数据库。

CoRB command
java -cp marklogic-xcc-<version>.jar;corb.jar com.marklogic.developer.corb.ModuleExecutor ^
-DXCC-CONNECTION-URI=xcc://user:password@localhost:9000/Modules ^
-DXCC-MODULE=/process.xqy ^
-DXCC-MODULE-ROOT=C:/corb/ ^
-DURIS-MODULE=uris.xqy ^
-DPROCESS-TASK=com.example.CustomTask ^
-DTHREAD-COUNT=4
nc1teljy

nc1teljy1#

在将CoRB添加到混合中之前,请验证您的逻辑在查询控制台中是否有效(最好使用调用函数以与CoRB流程相同的用户身份执行此操作)。如果无法验证逻辑在控制文档上与相同的用户一起工作,则尝试自动化批量处理没有任何价值。
日志/跟踪也很有帮助,这样你就可以知道你的代码在做什么。
表1:验证URIS流程-它返回的是您期望的结果吗?
选项卡2:验证PROCESS函数(用示例控件文档替换外部$URI)
您的配置将声明对PROCESS模块的每次调用一次发送一个URI(并且一次调用4个URI)。
我想你会看到你的代码没有按预期执行。我建议你开始以下操作:

(:PROCESS:)
xquery version "1.0-ml";
xdmp:invoke-function(function(){
  let $URI = "some URI you know and trust";
  let $_ := xdmp:log("processing URI: " || $URI)
  let $doc := fn:doc($URI)
  let $new-email := fn:replace($doc//emailAddress/text(), "customer.*@mail.com", "customer*@changed.mail.com")
  let $_ := xdmp:log("new email address(proves we got the doc and element): " || $new-email)
  let $new-email-element := <emailAddress>{$new-email}</emailAddress>
  return xdmp:node-replace($doc/customer/emailAddress, $new-email-element)
}, map:entry("userId", xdmp:user("your-user-here")))

相关问题