首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MarkLogic 7产卵函数

MarkLogic 7产卵函数
EN

Stack Overflow用户
提问于 2015-07-28 07:57:06
回答 1查看 392关注 0票数 0

我有一个REST端点,它需要处理一个长长的代码列表。因为这可能会触发超时,所以我尝试使用派生函数并在后台执行魔法。但它看起来像产卵函数保存了来自我的REST端点的200 OK响应,所以它并不是真正的产卵。

我增加了日志行来检查它的链在哪里。调试日志中弹出所有日志行。

对于少量的数据,这是很好的工作。对于较大的集合(60k码),它会失败。

在更改代码以派生$text中的每个项的函数(因此生成60k项)之后,我得到以下错误:

代码语言:javascript
复制
2015-07-28 10:20:02.326 Debug: Forest::insert: STRLF3-content-001-1 XDMP-INMMFULL: In-memory storage full; list: table=5%, wordsused=3%, wordsfree=95%, overhead=1%; tree: table=8%, wordsused=3%, wordsfree=97%, overhead=0%

插入数据:

代码语言:javascript
复制
{   
    ProjectID: 102124,
    Text: "2311\n2253\n2312\n6626\n2253\n1234"
}

调用产卵过程:

代码语言:javascript
复制
(: ======================================================================= :) 
(: ! Load Transactions into seperate XML files                             :)
(: ======================================================================= :) 

declare 
%roxy:params("")
function strlf:post(
    $context as map:map,
    $params  as map:map,
    $input   as document-node()*
) as document-node()?
{
    map:put($context, "output-types", "application/json"),
    xdmp:set-response-code(200, "OK"),
    document { 

                  (: Get project ID :)
                  let $_ := xdmp:log('TransTest - stap1', 'debug')
                  let $project  := json:transform-from-json($input)/ns:ProjectID

                  let $_ := xdmp:log('TransTest - stap2', 'debug')
                  let $codes    := json:transform-from-json($input)/ns:Text

                  (: Clean current project :)
                  let $_ := xdmp:log('TransTest - stap3', 'debug')
                  let $uridir   := fn:concat('/app/transactie/', $project/text(), '/', '*')

                  let $_ := xdmp:log('TransTest - stap4', 'debug')
                  let $kill     := xdmp:document-delete(cts:uri-match($uridir))

                  (: Spawn the trannies :)
                  let $_ := xdmp:log('TransTest - stap5', 'debug')

                  (: return 'ja' :)
                  let $_ := xdmp:spawn-function(strlf:spawner($project, $codes, $uridir),
                    <options xmlns="xdmp:eval">
                      <transaction-mode>update-auto-commit</transaction-mode>
                    </options>)

                  return 'done'

    }
};

函数strlf:spawner:

代码语言:javascript
复制
declare private function strlf:spawner(
  $project,
  $codes,
  $uridir
)
{ 
  (: Tokenize on lines :)
  let $text     := fn:tokenize($codes, fn:codepoints-to-string(10))

  let $loop     :=
    for $regel in $text

      let $tokregel := fn:tokenize($regel, ",")           

      let $intvalue := 
       if (fn:contains($regel, ","))
       then fn:substring-after($regel, "€")
       else 1 

      let $code :=
       if (fn:contains($regel, ","))
       then $tokregel[1]
       else $regel 

      (: Build map of maps, p4 should be postcode :)
      let $map      := map:map()
      let $_        := map:put($map, 'code', $code)
      let $_        := map:put($map, 'p4', fn:substring($code[1], 1, 4))
      let $_        := map:put($map, 'value', $intvalue)
      let $_        := map:put($map, 'projectid', $project/text())

      (: Create unverified random doc id :)
      let $docid    := fn:string(xdmp:random(1000000000000))

      (: Build URI :)
      let $uridoc   := fn:concat('/app/transactie/', $project/text(), '/', $docid, '.xml')

    (: Save transaction document and skip header :)
    return 
    (if (map:get($map, 'code') != 'CODE')
    then xdmp:document-insert 
            (
            $uridoc,
              <transaction xmlns='http://www.dikw.nl/transactions' projectid='{map:get($map, 'projectid')}' code='{map:get($map, 'code')}' p4='{map:get($map, 'p4')}'>
                <value>{map:get($map, 'value')}</value>
              </transaction>
            )
    else ()) 

  (: Empty return :)
  return $loop        
};
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-28 08:42:01

正确,您将strlf:spawner($project, $codes, $uridir)作为xdmp:spawn-function的第一个参数,使其得到执行,并将结果传递给xdmp:spawn-function。由于spawner函数返回空序列,所以spawn函数不会抛出错误。

修复非常简单,将您的spawner调用包装为一个匿名函数:

代码语言:javascript
复制
let $_ := xdmp:spawn-function(function () { strlf:spawner($project, $codes, $uridir) },
                <options xmlns="xdmp:eval">
                  <transaction-mode>update-auto-commit</transaction-mode>
                </options>)

哈哈!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31670493

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档