Apache storm Storm tuple.getIntegerByField未按预期工作
我有一个包含以下数据的元组 第一列是“受影响的账户” 当我跑的时候Apache storm Storm tuple.getIntegerByField未按预期工作,apache-storm,Apache Storm,我有一个包含以下数据的元组 第一列是“受影响的账户” 当我跑的时候 tuple.getIntegerByField("affectedAccount"); this.affectedAccount = Integer.parseInt(tuple.getStringByField("affectedAccount")); 它抛出ClassCastException 当我跑的时候 tuple.getIntegerByField("affectedAccount"); this.affec
tuple.getIntegerByField("affectedAccount");
this.affectedAccount = Integer.parseInt(tuple.getStringByField("affectedAccount"));
它抛出ClassCastException
当我跑的时候
tuple.getIntegerByField("affectedAccount");
this.affectedAccount = Integer.parseInt(tuple.getStringByField("affectedAccount"));
它工作正常,为什么即使值是整数也不工作呢?我猜第一列的类型实际上不是整数,而是字符串。看看Tuple.getIntegerByField的实现
原因是this.affectedAccount=Integer.parseInt(tuple.getStringByField(“affectedAccount”)代码>的作用在于字段实际上是字符串类型。您所说的“字段实际上是字符串类型”是什么意思?我可以看到它被实现为返回(整数)值;那么我在哪里可以设置字段类型呢?我的意思是,您从中接收元组的喷口(或其他螺栓?)在“affectedAccount”字段中放入了一个字符串,而不是一个整数(因此
“1”
而不是1
)。您必须查看上游的bolt/Spoot以了解如何更改类型。Spoot只是读取一个文件并发送其内容,我还重写了DeclareoutpFields方法。好的,但是您在Spoot中输入值的第一个参数的对象的Java类型是int/Integer吗?