0

好吧,我在这里发疯了。有许多行为我无法用 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).

我的问题:

  • Q1。大问题。为什么我在上面的例子中得到一个空指针?
  • Q2。较小的:
    • Q2a。鉴于我如何在 1 中设置表格,我在 3 中观察到的情况是正常的吗?
    • Q2b。为什么我的字符串和长值不匹配?
4

1 回答 1

0

Not sure the answer will be useful to anyone, but the data that were expected to be long were inserted as string. This apparently caused at least two issues that I explained above:

  • displaying a different result whether the data was read as String or Long (something I wasn't used to coming from the Oracle world)
  • causing these occasional null pointer exceptions
于 2013-02-21T15:03:01.793 回答