3

I want to remove the particular column from the csv file and load it into database using mlcp.

My csv file contains:

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

I want to use that URI column as the uri for the document and also that uri column should be skipped/removed in the inserted document.

How to do it??

4

1 回答 1

4

使用 MLCP 而不是在 MarkLogic Data Hub 上下文中的最佳选择是使用 MLCP 转换。您可以在此处找到一些解释和一些示例:

在摄取期间转换内容

如果您要将 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

于 2018-12-17T14:40:08.673 回答