Marklogic 如何在加载文件时从csv文件中删除列?

Marklogic 如何在加载文件时从csv文件中删除列?,marklogic,marklogic-9,mlcp,Marklogic,Marklogic 9,Mlcp,我想从csv文件中删除特定列,并使用mlcp将其加载到数据库中 我的csv文件包含: URI,EmpId,Name,age,gender,salary 1/Niranjan,1,Niranjan,35,M,1000 2/Deepan,2,Deepan,25,M,2000 3/Mehul,3,Mehul,28,M,3000 我想使用该URI列作为文档的URI,并且在插入的文档中应该跳过/删除该URI列 如何做到这一点???在使用MLCP而不是在MarkLogic数据中心上下文中时,最好的选择是使

我想从csv文件中删除特定列,并使用mlcp将其加载到数据库中

我的csv文件包含:

URI,EmpId,Name,age,gender,salary
1/Niranjan,1,Niranjan,35,M,1000
2/Deepan,2,Deepan,25,M,2000
3/Mehul,3,Mehul,28,M,3000
我想使用该URI列作为文档的URI,并且在插入的文档中应该跳过/删除该URI列


如何做到这一点???

在使用MLCP而不是在MarkLogic数据中心上下文中时,最好的选择是使用MLCP Transforms。您可以在这里找到一些解释和一些示例:

在将CSV转换为JSON的情况下,可以使用以下内容

将其另存为模块数据库中的/strip-columns.sjs:

/* jshint node: true */
/* global xdmp */

exports.transform = function(content, context) {
  'use strict';

  /* jshint camelcase: false */
  var stripColumns = (context.transform_param !== undefined) ? context.transform_param.split(/,/) : [];
  /* jshint camelcase: true */

  // detect JSON, assumes uri has correct extension
  if (xdmp.uriFormat(content.uri) === 'json') {

    // Convert input to mutable object for manipulation
    var newDoc = content.value.toObject();
    Object.keys(newDoc)
    .map(function(key) {
      if (stripColumns.indexOf(key) > -1) {
        delete newDoc[key];
      }
    });

    // Convert result back into a document
    content.value = newDoc;

  }

  // return updated content object
  return content;
};
然后你可以这样调用它:

mlcp.sh import -input_file_path test.csv -input_file_type delimited_text -uri_id URI -document_type json -output_uri_prefix / -output_uri_suffix .json -output_collections data,type/csv,format/json -output_permissions app-user,read -transform_module /strip-columns.sjs -transform_param URI

我认为这个答案也适用于DHF上下文,因为MLCP通常用于将数据摄取到DHF暂存数据库中。DHF输入流使用特定于datahub的转换,您不会自行更改。相反,您需要对数据中心框架调用的content.sjs等进行更改。是否有任何mlcp转换函数在加载文档时忽略该列?不幸的是,这不是现成的。没有参数,也没有要复制粘贴的变换。不过,这样的转换并不一定很困难,尤其是在生成JSON并使用服务器端JavaScript类型转换的情况下。