0

I'm trying to get the value of the tuple by the String but when i'm doing it getting an error saying

 incompatible types: java.lang.Object cannot be converted to java.lang.String

this is how I'm Trying.

 `  public void execute(Tuple tuple) {
  String field = tuple.getValueByField("name");

        for(String user:field.split(","))}`

I tried like this by casting the string

String field = (String) tuple.getValueByField("name"); 

Is this a correct way to get the value of the tuple by the field name?

2
  • 1
    Which Tuple class are you using? Commented Feb 23, 2016 at 5:01
  • yes it is correct, if return type is string. Are you getting any error on (String) tuple.getValueByField("name"); ? Commented Feb 23, 2016 at 5:04

4 Answers 4

2

Use

tuple.getStringByField("name");

getStringByField is used to retrieve the value, based on column name.

Apache storm Documentation

what is use of Tuple.getStringByField(“ABC”) in Storm

Sign up to request clarification or add additional context in comments.

Comments

1

try using getStringByField instead

if you want to use getValueByField then you will need to check if (obj instanceof String) then cast it

Comments

1

yes it is correct, if return type is string.

String field = (String) tuple.getValueByField("name"); 

See example for reference

http://www.programcreek.com/java-api-examples/index.php?class=backtype.storm.tuple.Tuple&method=getValueByField

Comments

-1

Try this...

String field = String.valueOf(tuple.getValueByField("name")); 

instead of

String field = (String) tuple.getValueByField("name"); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.