我试图更新“map”列,但是尝试这样做会导致错误:
错误:
error: database errorTypeError: Not a valid bigint, expected Long/Number/Buffer, obtained '2014-12-07T13:53:10.658Z'
尝试
var query_attendance = 'UPDATE emp_attendance SET attendace = attendace + ? where year = ? and month = ? and emp_id = ?';
var udpateAttendance = function(empId, timestampMillis, cb){
var foundDate = new Date(timestampMillis);
var year = foundDate.getUTCFullYear();
var month = foundDate.getUTCMonth();
var date = foundDate.getUTCDate();
var attendace = {};
attendace['2014-12-07T13:53:10.658Z'] = 'Present';
// winston.info('attendace' + JSON.stringify(foundDate));
var values = [attendace, year, month, empId];
var options = {
hints: ['map','int','int','int'],
prepare: true
};
winston.info('Values: ' + JSON.stringify(values));
client.execute(query_attendance, values, options, function(err, resultSet){
winston.info('Query Completed');
if(err){
winston.error('database error' + err);
cb(err, null);
return;
}
winston.info('Query successful');
cb(null, resultSet);
});
}
My View:
我想我需要告诉驱动程序,地图收集中的键类型是时间戳类型,但是我没有找到如何为驱动程序指定这样的输入。
发布于 2014-12-07 12:05:25
在对cassandra驱动程序库进行了大量调试之后,我最终发现了其中的错误。
当'encoder.js‘在’cassandra‘中接收到类型日期的输入时,'encodeTimestamp()’使用'instanceof‘关键字检查类型。这就是我的错误导致错误的地方,因为
attendace[foundDate]
or
attendace['2014-12-07T13:53:10.658Z']
可能正在按'string‘类型(是js新手,不能确认)来做键。所以,解决问题的方法是,i need to pass date object as key of attendace variable
。
注:
虽然,我仍然无法将日期作为对象传递给另一个对象的键,但这是完全不同的问题。为了继续运行流(直到我找到了将日期作为对象传递的方法),我在cassandra驱动程序中对'encodeTimestamp()‘的'encoder.js’做了一个小小的修改。变化
function encodeTimestamp (value, type) {
console.log('Encoding time stamp: ' + value + '\ttype:'+type);
//parsing the date object,
var convertedDate = new Date(value);
// check if supplied value is converted into date, if so, assign its value to value variable and continue with original process
if((convertedDate) && (convertedDate!= NaN)){
value = convertedDate;
}
if (value instanceof Date) {
console.log('Value is date ');
value = value.getTime();
}else{
console.log('input value ' + value + ' is not a date');
}
return encodeBigNumber (value, type);
}
This is hack only
,所以我希望一定会有一个真正的解决方案,
https://stackoverflow.com/questions/27343545
复制相似问题