[MarkLogic Dev General] Commit in XQUERY

Danny Sokolsky dsokolsky at marklogic.com
Thu Jan 15 13:21:37 PST 2009


Hi Pradeep,

What is the exact error message you are getting with a large file?  

-Danny


-----Original Message-----
From: Pradeep Maddireddy [mailto:Pradeep.Maddireddy at HTCinc.com] 
Sent: Thursday, January 15, 2009 12:22 PM
To: Danny Sokolsky
Cc: General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] Commit in XQUERY

Hi Danny,

Thank you very much. xdmp:document-get solved my problem.

When the document size is large ( 100Mb or greater) this QUERY fails. What is the best method to load large documents. 

Thanks
Pradeep Maddireddy


-----Original Message-----
From: Danny Sokolsky [mailto:dsokolsky at marklogic.com] 
Sent: Thursday, January 15, 2009 1:47 PM
To: Pradeep Maddireddy; General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] Commit in XQUERY

Hi Pradeep,

There is no need to use both xdmp:document-load and xdmp:document-insert in the same statement, just choose one of them.  For example, you can construct the document using XQuery (including your metadata), then use xdmp:document-insert to store your abc.xml document in the database as follows:

xquery version "1.0-ml";

let $document_name := "abc.xml"
let $metadata := 
  <metadata>
     <metadata-content>goes here</metadata-content>
  </metadata>  
let $orig-content := <some-content>goes here</some-content>
return
xdmp:document-insert($document_name, 
  <wrapper>{
      $metadata ,
      <original-content>{$orig-content}</original-content>}
  </wrapper> )

Or, if you are trying to load a document from your filesystem that has a path of /space/abc.xml, you can do something like this (using xdmp:document-get to get the file with the content from the filesystem):

xquery version "1.0-ml";

let $document_name := "/space/abc.xml"
let $metadata := 
  <metadata>
     <metadata-content>goes here</metadata-content>
  </metadata>  
let $orig-content := xdmp:document-get($document_name)
return
xdmp:document-insert($document_name, 
  <wrapper>{
      $metadata ,
      <original-content>{$orig-content}</original-content>}
  </wrapper> )

That would insert a document into the database with the URI /space/abc.xml.  Then a doc("/space/abc.xml") returns the following:

<wrapper>
  <metadata><metadata-content>goes here</metadata-content></metadata>
  <original-content>
    <some-content>goes here</some-content>
  </original-content>
</wrapper>


-Danny


From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Pradeep Maddireddy
Sent: Wednesday, January 14, 2009 8:16 AM
To: general at developer.marklogic.com
Subject: [MarkLogic Dev General] Commit in XQUERY

Hi..!

We are planning to store the metadata and orginal xml content in the following format, so that a search can be performed on both original content and metadata at one shot.
      
<wrapper>
<metadata>
<metdata content>
</metadata>  
<original-content> 
<!-- original content goes here -->
</original-content>
</wrapper>

The XQUERY function I have created (given below) receives document URI and meta data (as a node) 

define function   load-document($document_uri   as xs:string, $metadata      as node()
{
let $document_name := "abc.xml"
return
xdmp:document-load($document_uri,<options xmlns="xdmp:document-load"><uri>{$document_name}</uri></options>),
xdmp:document-insert($document_name,<wrapper>{$metadata}<original-content>{fn:doc($document_name)/node()}</original-content></wrapper>)

}

In the first function xdmp:document-load I am creating the document from the URI received and in the 
  second function xdmp:document-insert I am trying to retrieve original content as a node  
  (using fn:doc($document_name)/node() )  and  then attach metadata to it and then load it into marklogic, but as the data will not be committed untill the control exits the module, even after the first function document-load gets executed when I try to retrieve the original content as a node I receive nothing.

Is there any function like commit which could solve the problem or else is there any work around for this other than having two different functions and invoking them one after another from front end. 


Thanks in advance.

Regards,
Pradeep Maddireddy







More information about the General mailing list