Storm tuple.getIntegerByField 未按预期运行

Storm tuple.getIntegerByField not working as expected

我有一个包含以下数据的元组 第一列是 "affectedAccount"

 source: source-spout:12, stream: default, id: {}, [1, 11455455, 1288, 20180717, 000808, 1, 6, 1, d, 1, Y, 1.250000, 6, , , , , , , ]

当我运行

tuple.getIntegerByField("affectedAccount");

它抛出 ClassCastException 而当我 运行

 this.affectedAccount = Integer.parseInt(tuple.getStringByField("affectedAccount"));

它工作正常,为什么它没有工作,即使值为 Integer

我猜第一列的类型实际上不是 Integer,而是 String。看一下 Tuple.getIntegerByField https://github.com/apache/storm/blob/efb2e9a337f9320efd7e5873e493532aa58f341c/storm-client/src/jvm/org/apache/storm/tuple/TupleImpl.java#L174 的实现。

this.affectedAccount = Integer.parseInt(tuple.getStringByField("affectedAccount"));有效的原因是该字段实际上是String类型。