首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何更新键为时间戳类型的cassandra中的集合

如何更新键为时间戳类型的cassandra中的集合
EN

Stack Overflow用户
提问于 2014-12-07 06:16:20
回答 1查看 711关注 0票数 2

我试图更新“map”列,但是尝试这样做会导致错误:

错误:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
error: database errorTypeError: Not a valid bigint, expected Long/Number/Buffer, obtained '2014-12-07T13:53:10.658Z'

尝试

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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:

我想我需要告诉驱动程序,地图收集中的键类型是时间戳类型,但是我没有找到如何为驱动程序指定这样的输入。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-07 12:05:25

在对cassandra驱动程序库进行了大量调试之后,我最终发现了其中的错误。

当'encoder.js‘在’cassandra‘中接收到类型日期的输入时,'encodeTimestamp()’使用'instanceof‘关键字检查类型。这就是我的错误导致错误的地方,因为

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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’做了一个小小的修改。变化

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  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,所以我希望一定会有一个真正的解决方案,

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27343545

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文