【问题标题】:Cassandra java driver UDT MappingCassandra java驱动UDT映射
【发布时间】:2016-01-31 20:30:55
【问题描述】:

所以我在 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
);

当我查询这个时,我可以获得 UDTValue,但我不确定如何映射到 UDTClass,因为我正在使用 Cassandra Java Driver 2.2.0rc3

在 2.1 中,有一些类似 tutorial 的指令。但似乎 this(UDTMapper) 已在 2.2.0 中删除或尚未添加。怎么能做同样的事情或只是为了达到同样的效果?

非常感谢。

【问题讨论】:

    标签: java cassandra


    【解决方案1】:

    原来我在 2.2.0rc3 中根本不需要 UDTMapper。基本上有一个 UDTValue 类,我可以通过使用 getInt 或类似方法来获取我想要的任何值。代码示例如下:

    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);
     }
    

    希望这对其他人也有帮助。

    【讨论】:

      猜你喜欢
      • 2017-08-22
      • 2018-05-06
      • 2021-01-02
      • 2017-06-27
      • 1970-01-01
      • 2017-03-28
      • 1970-01-01
      • 2020-08-01
      • 2016-01-02
      相关资源
      最近更新 更多