我已经在网上搜寻了如何解决此问题的方法,收效甚微。
我正在解析CSV,然后使用DynamoDB将数据放入表中。每当有空白条目时,我都会收到错误消息:
One or more parameter values were invalid: An AttributeValue may not contain an empty string
Run Code Online (Sandbox Code Playgroud)
例如:
Header: "Name","Age","Birth date"
Entry: Brandon,22 <------ THROWS ERROR
Run Code Online (Sandbox Code Playgroud)
问题是,我永远不会知道CSV中是否有空格。但是即使有,我仍然需要解析它。
我试图将空字符串的值重新分配为“ N / A”之类的内容,以消除此错误,但无济于事。有什么建议么?
编辑:添加上下文的代码。
var file = process.argv[2];
console.log("File: " + file);
var csv = require("fast-csv");
csv.fromPath(file, {
headers: true,
ignoreEmpty: true
})
.on("data", function(data) {
// Uncomment to see CSV data
// console.log(data);
params = {
TableName: tableName,
Item: {
RefID: {
S: data["Ref-ID"]
},
//lots more items
}
};
//Validation …Run Code Online (Sandbox Code Playgroud) 我正在解析CSV文件,并将数据放入带有AWS DynamoDB的表中。
就目前而言,我收到以下错误:
One or more parameter values were invalid: An AttributeValue may not contain an empty string
...在将数据放入表之前。数据正在传递到表中,但是在向我发送该错误一百万次之前还没有。
我的代码:
var csv = require("fast-csv");
csv.fromPath(file, {
headers: true,
ignoreEmpty: true
})
.on("data", function(data) {
for (var key in data) {
if (data.hasOwnProperty(key)) {
if (data[key] === "" || data[key] === undefined || data[key] === null) {
data[key] = "N/A";
}
}
params = {
TableName: tableName,
Item: {
RefID: {
S: data["Ref-ID"]
},
//lots of other data
}
};
dynamodb.putItem(params, …Run Code Online (Sandbox Code Playgroud) 编辑:[已解决] 对于阅读本文的任何人来说,Papa Parse 是浏览器的解析器,而不是 Node.js。Baby Parse 用于 Node.js,但要知道它的功能并不广泛,并且不能直接从文件解析,只能从字符串解析。
在该papaparse.js文件中,有这样一行代码:
xhr = new XMLHttpRequest();
Run Code Online (Sandbox Code Playgroud)
这似乎导致了错误,我不知道如何解决它。
我的代码:
var Papa = require('papaparse');
var data;
process.argv.forEach(function(val, index, array) {
console.log(index + ': ' + val);
});
var file = process.argv[2];
console.log("File: " + file);
// Parse the file
Papa.parse(file, {
header: true,
download: true,
dynamicTyping: true,
complete: function(results) {
data = results;
console.log(data);
}
});
Run Code Online (Sandbox Code Playgroud)
任何想法,将不胜感激 :)
AWS的新增功能,试图将数据放入表中。阅读文档并尝试按照示例操作后,我遇到了此验证错误。
One of the required keys was not given a value
Run Code Online (Sandbox Code Playgroud)
我的代码:
var conf = require("/directory");
var AccessKey = 'supersecretkey';
var SecretKey = 'supersecretkey';
var tableName = conf.tableCS;
var AWS = require('aws-sdk');
console.log("Endpoint: " + conf.endpoint);
AWS.config.update({
accessKeyId: AccessKey,
secretAccessKey: SecretKey,
region: conf.region,
endpoint: conf.endpoint
});
var docClient = new AWS.DynamoDB.DocumentClient();
var file = process.argv[2];
console.log("File: " + file);
var csv = require("fast-csv");
csv.fromPath(file)
.on("data", function(data) {
// Uncomment to see CSV data
// console.log(data);
var arrayLength = data.length;
for …Run Code Online (Sandbox Code Playgroud)