简体   繁体   English

Cassandra Java驱动程序UDT映射

[英]Cassandra java driver UDT Mapping

So I have a UDT in Cassandra Database: 所以我在Cassandra数据库中有一个UDT:

CREATE TYPE cs4224.OrderLine (
    OL_I_ID int,
    OL_DELIVERY_D timestamp,
    OL_AMOUNT float,
    OL_SUPPLY_W_ID int,
    OL_QUANTITY int,
    OL_DIST_INFO varchar
);

When I query for this, I can get UDTValue but I am not sure how can I map to a UDTClass as I am using Cassandra Java Driver 2.2.0rc3 当我查询时,我可以获取UDTValue,但是我不确定如何映射到UDTClass,因为我正在使用Cassandra Java Driver 2.2.0rc3

In 2.1, there is some instruction like this tutorial . 在2.1中,有一些类似本教程的说明 But it seems this(UDTMapper) is removed or not yet added in 2.2.0. 但是,似乎(UDTMapper)在2.2.0中已删除或尚未添加。 How can do the same thing or just to achieve the same effect? 怎样才能做同样的事情或仅仅达到相同的效果?

Thanks a lot. 非常感谢。

Turns out I do not have to the UDTMapper at all in 2.2.0rc3. 事实证明,在2.2.0rc3中我完全不需要使用UDTMapper。 Basically there is a UDTValue class that I can make use of to get whatever value I want by using getInt or similar methods. 基本上,有一个UDTValue类可以通过使用getInt或类似方法来获取所需的任何值。 A code sample is below: 下面是一个代码示例:

Map<Integer, UDTValue> ols = row.getMap("o_ols", Integer.class, UDTValue.class);
for (Integer key: ols.keySet()) {
     UDTValue ol = ols.get(key);
     olIId = ol.getInt("ol_i_id");
     olQuantity = ol.getInt("ol_quantity");
     olDistInfo = ol.getString("ol_dist_info");
     olSupplyWId = ol.getInt("ol_supply_w_id");
     olAmount = ol.getFloat("ol_amount");
     olSum += olAmount;
     newOrderLine = orderLineType.newValue()
         .setInt("OL_I_ID", olIId)
         .setTimestamp("ol_delivery_d", new Timestamp(now.getTime()))
         .setFloat("ol_amount", olAmount)
         .setInt("ol_supply_w_id", olSupplyWId)
         .setInt("ol_quantity", olQuantity)
         .setString("ol_dist_info", olDistInfo);
     orderLines.put(key, newOrderLine);
 }

hope this helps others as well. 希望这对其他人也有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM