首页 > 解决方案 > 产生多个线程以删除多个相同元素时出错

问题描述

我想在 xml 中删除复制 2353218 次的相同元素,只保留一个。试图生成该进程但出现以下错误。没有产卵它需要太多时间。请帮忙。

 xquery version "1.0-ml";
    let $input := doc("http://www.somedomain.com/name/12345.xml")/xpath/toMultipleElement[2 to last()]

    let $batch-size := 50000

    let $input-size := fn:count($input)

    let $num-batches :=  xs:int(math:ceil($input-size div $batch-size ))

    let $result :=
    <root>{

    for $batch-start in (1 to $num-batches)
      let $processing-seq := $input[($batch-size * ($batch-start - 1) + 1)  to ($batch-size * ($batch-start ))]
      return

        xdmp:spawn-function(function() {
        xdmp:node-delete($processing-seq),

        <success batch-start='{$batch-start}'> processing sequence deleted</success>
        }, 
        <options xmlns="xdmp:eval">
          <result>true</result>
          <transaction-mode>update-auto-commit</transaction-mode>
        </options>)
    }</root>

    return 
    xdmp:save("D:/batch-wise-delete.xml", $result)

错误:[1.0-ml] XDMP-DELEXTNODES: let $processing-seq := $input[$batch-size * ($batch-start - 1) + 1 to $batch-size * $batch-start] -- 不能删除外部节点

标签: marklogicmarklogic-8

解决方案


与其删除所有孩子,不如写一个有一个孩子的新父母。

let $parent := doc("http://www.somedomain.com/name/12345.xml")/xpath/parent
let $chosen-child := $parent/toMultipleElement[1]
return xdmp:node-replace($parent, <parent>{ $chosen-child }</parent>

推荐阅读