Niel
Niel

Reputation: 31

learning about the MarkLogic CoRB processing

I'm currently Learning MarkLogic database, and looking in to the CoRB batch processing(running it on windows). I've made 10 sample data in the Documents database such as below

/customer1~10.xml

<?xml version="1.0" encoding="UTF-8"?>
<customer>
  <name>Customer1</name>
  <address>123 Main St</address>
  <company>A Corporation</company>
  <emailAddress>[email protected]</emailAddress>
</customer>

the <address> and <company> are all the same for the next 9 datasets.

Now my goal was to go through all the /Customer*.xml data with the Uri.xqy and change the <emailAddress> from [email protected] to [email protected].

I've been trying the queries below and it wouldn't return anything.

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
)

PROCESS

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)

and the corb command below, Ive made a app-server(XDBC)on port 9000 which has "documents" as a database and "modules" as a modules database.

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

Upvotes: 1

Views: 372

Answers (1)

Before adding CoRB into the mix, validate that your logic works in query console (and idealy do this as the same user as your CoRB process using an invoke function). There is no value in trying to automate bulk processing if you cannot validate the the logic works with the same user on a control document.

It is also helpful to log/trace so that you know what your code is doing.

Tab 1: validate your URIS proces - does it return what you expect?

Tab 2: validate your PROCESS function. (Replace the external $URI with a sample control document.)

Your configuration would state that each call to the PROCESS module sends one URI at a time (and invokes 4 at a time).

I think you will see that your code is not executing as expected. I suggest the following to get you started:

(: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")))

Upvotes: 2

Related Questions