gpt4 book ai didi

java - Cassandra Java 驱动程序 UDT 映射

转载 作者:行者123 更新时间:2023-11-30 08:07:51 25 4
gpt4 key购买 nike

所以我在 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 中被删除或尚未添加。怎么能做同样的事情或者只是达到同样的效果?

非常感谢。

最佳答案

原来在 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);
}

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

关于java - Cassandra Java 驱动程序 UDT 映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33452519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com