Search code examples
apache-storm

Storm tuple.getIntegerByField not working as expected


I have a tuple with the below data first column is "affectedAccount"

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

when I run

tuple.getIntegerByField("affectedAccount");

it throws ClassCastException while when I run

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

it works okey, why it didn't work eventhough the value is Integer


Solution

  • My guess would be that the type of the first column isn't actually Integer, but String. Take a look at the implementation of Tuple.getIntegerByField https://github.com/apache/storm/blob/efb2e9a337f9320efd7e5873e493532aa58f341c/storm-client/src/jvm/org/apache/storm/tuple/TupleImpl.java#L174.

    The reason this.affectedAccount = Integer.parseInt(tuple.getStringByField("affectedAccount")); works is that the field is actually of String type.