【问题标题】:cassandra field string vs. longcassandra 字段字符串与长
【发布时间】:2013-02-21 23:03:01
【问题描述】:

好的,我在这里发疯了。有许多行为我无法用 Cassandra 解释,我什至不确定它们是否相关。

我创建了一个如下表(为简洁起见,未显示所有列):

create column family cachekey  
    with comparator = UTF8Type  
    and column_metadata =  
    [  
    {  
        column_name : accountNumber,  
        validation_class : UTF8Type  
    },  
    {  
        column_name : homeId,  
        validation_class : LongType  
    }  
 ...  
];

一些记录被添加到该表中(不是我)。现在,当我显示架构时,我不确定为什么看不到我创建的列

[default@cachekeydata] show schema;
...

use cachekeydata;

create column family cachekey  
  with column_type = 'Standard'  
  and comparator = 'UTF8Type'  
  and default_validation_class = 'BytesType'  
  and key_validation_class = 'BytesType'  
  and read_repair_chance = 0.1  
  and dclocal_read_repair_chance = 0.0  
  and gc_grace = 864000  
  and min_compaction_threshold = 4  
  and max_compaction_threshold = 32  
  and replicate_on_write = true  
  and compaction_strategy = 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'  
  and caching = 'KEYS_ONLY'  
  and compression_options = {'sstable_compression' :   'org.apache.cassandra.io.compress.SnappyCompressor'};  

现在,真正让我感到困惑的是:当我从我的 java 代码中提取数据时,我在尝试检索 long 时出现空指针异常,但在检索某些记录的字符串时却没有:

System.out.println("Mac=" + mac);
System.out.println("  cidx=<" + result.getStringValue("homeId",null) + ">");
System.out.println("  cidx=<" + result.getLongValue("homeId",null) + ">");
System.out.println("  cidx=<" + result.getColumnByName("homeId").getLongValue() + ">");

导致:

Mac=001DD67CFF46
  cidx=<50190074>
  cidx=<3832617404583655220>
  cidx=<3832617404583655220>
Mac=001DCFE2122C
  cidx=<3663580>

后跟 NullPointerException。换句话说,result.getStringValue("homeId",null) 返回 3663580 但 result.getLongValue("homeId",null) 在 Cassandra 库代码中运行以下行时会导致 NullPointerException:

LongSerializer.get().fromBytes(column.getValue());

最后,从 cli 控制台显示与上面相同的两条记录对我来说没有任何可疑之处:

[default@cachekeydata] get cachekey[utf8('001DD67CFF46')];
=> (column=accountNumber, value=30373833373132303730323036, timestamp=1361305382124)
=> (column=corp, value=3037383337, timestamp=1361305382124)
=> (column=homeId, value=3530313930303734, timestamp=1361305382124)
=> (column=zip, value=3130343732, timestamp=1361305382124)
Returned 4 results.
Elapsed time: 70 msec(s).
[default@cachekeydata] get cachekey[utf8('001DCFE2122C')];
=> (column=accountNumber, value=30373830383132333437323032, timestamp=1361305376659)
=> (column=corp, value=3037383038, timestamp=1361305376659)
=> (column=homeId, value=33363633353830, timestamp=1361305376659)
=> (column=zip, value=3036393033, timestamp=1361305376659)
Returned 4 results.
Elapsed time: 45 msec(s).

我的问题:

  • 第一季度。大问题。为什么我在上面的例子中得到一个空指针?
  • 第二季度。较小的:
    • Q2a。考虑到我在 1 中设置表格的方式,我在 3 中观察到的情况是正常的吗?
    • Q2b。为什么我的字符串和长值不匹配?

【问题讨论】:

  • 你确定写入homeId的值是长的吗?
  • 我确定我在创建表时将validation_class设置为LongType。我不知道如何填充表格,这本质上是我的问题:考虑到我是如何创建表格的,如何在表格中输入数据以导致我上面描述的行为?

标签: java schema cassandra astyanax


【解决方案1】:

不确定答案是否对任何人有用,但预期较长的数据已作为字符串插入。这显然导致了我上面解释的至少两个问题:

  • 无论数据被读取为 String 还是 Long 都会显示不同的结果(我不习惯来自 Oracle 世界)
  • 导致这些偶尔出现的空指针异常

【讨论】:

猜你喜欢
  • 2018-09-15
  • 1970-01-01
  • 2017-08-19
  • 2010-09-05
  • 2015-08-15
  • 2014-11-05
  • 2014-07-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多