ich die folgende Herausforderung haben. Wir haben CSV-Dateien, die wir mit mlcp in die MarkLogic-Datenbank laden wollen. Wir wollen auch die geladenen Zeilen während der Belastung in OBI Quellen verwandeln, so buils wir eine Transformationsfunktion für die.MLKP CSV-Datei in OBI Quellen verwandeln
Jetzt mit der Transformation Ich kämpfe. Ohne die Transformation wird die Daten wie erwartet als Dokument pro Zeile geladen.
CSV Beispiel:
voornaam,achternaam
hugo,koopmans
thijs,van ulden
transformations ambulance.xqy:
xquery version "1.0-ml";
module namespace rws = "http://marklogic.com/rws";
import module namespace source = "http://marklogic.com/solutions/obi/source" at "/ext/obi/lib/source-lib.xqy";
(: If the input document is XML, create an OBI source from it, with the value
: specified in the input parameter. If the input document is not
: XML, leave it as-is.
:)
declare function rws:transform(
$content as map:map,
$context as map:map
) as map:map*
{
let $attr-value :=
(map:get($context, "transform_param"), "UNDEFINED")[1]
let $the-doc := map:get($content, "value")
return
if (fn:empty($the-doc/element()))
then $content
else
let $root := xdmp:unquote($the-doc/*)
let $source-title := "ambulance source data"
let $collection := 'ambulance'
let $source-id := source:create-source($source-title,(),$root)
let $_ := xdmp:document-add-collections(concat("/marklogic.solutions.obi/source/", $source-id[1],".xml"), $collection)
return (
map:put($content, "value",
$source-id[2]
), $content
)
};
MLCP-Befehl:
mlcp.sh import \
-host localhost \
-port 27041 \
-username admin \
-password admin \
-input_file_path ./sampledata/so-example.csv \
-input_file_type delimited_text \
-transform_module /transforms/transform-ambulance.xqy \
-transform_namespace "http://marklogic.com/rws" \
-mode local
MLCP output:
15/09/08 21:35:08 INFO contentpump.ContentPump: Hadoop library version: 2.6.0
15/09/08 21:35:08 INFO contentpump.LocalJobRunner: Content type: XML
15/09/08 21:35:08 INFO input.FileInputFormat: Total input paths to process : 1
15/09/08 21:35:10 WARN mapreduce.ContentWriter: XDMP-DOCROOTTEXT: xdmp:unquote(document{<root><voornaam>hugo</voornaam><achternaam>koopmans</achternaam></root>}) -- Invalid root text "hugokoopmans" at line 1
15/09/08 21:35:10 WARN mapreduce.ContentWriter: XDMP-DOCROOTTEXT: xdmp:unquote(document{<root><voornaam>thijs</voornaam><achternaam>van ulden</achternaam></root>}) -- Invalid root text "thijsvan ulden" at line 1
15/09/08 21:35:11 INFO contentpump.LocalJobRunner: completed 100%
15/09/08 21:35:11 INFO contentpump.LocalJobRunner: com.marklogic.contentpump.ContentPumpStats:
15/09/08 21:35:11 INFO contentpump.LocalJobRunner: ATTEMPTED_INPUT_RECORD_COUNT: 2
15/09/08 21:35:11 INFO contentpump.LocalJobRunner: SKIPPED_INPUT_RECORD_COUNT: 0
15/09/08 21:35:11 INFO contentpump.LocalJobRunner: Total execution time: 2 sec
Ich habe ohne xdmp versucht: unquote(), aber dann traf ich einen Zwang Dokument-node() Fehler ...
Bitte Beratung ...
Gut, dass Sie es heraus. Bitte akzeptieren Sie Ihre Antwort, um sie von der "unbeantworteten" Liste zu entfernen. (Ja, Stackoverflow Etikette fordert Sie dazu auf, das zu tun.) –
Ich bemerke ein zwei kleine Dinge: Erstens '$ the-doc' ist bereits ein Dokument-Knoten, also warum nehmen' root' Element, und wickeln Sie das wieder als Dokument- Knoten. Ich denke, Sie können '$ the-doc' direkt anstelle von' $ root' verwenden. Zweitens aktualisieren Sie '$ content' mit einem Wert von' Quelle zurückgegeben: create-source', aber ich dachte, dass Funktion bereits ein Dokument in die Datenbank einfügt. Ich denke, du kannst dort einfach eine leere Sequenz zurückgeben. – grtjn