This is the correct way. Thanks!
I've changed the code.

-----Original Message-----
From: Susheel Kumar Gadalay [mailto:[email protected]] 
Sent: December-19-13 2:01 AM
To: [email protected]
Subject: Re: emitting various types - how to send long as string and unmarshal 
into long

Yes, emitting new Values("String", 34234234L) will work.

In the bolt just fetch that value by tuple.getString(0), tuple.getLong(1).

I have not used tuple.,getDouble() to fetch Double value. Just check


On 12/19/13, Adam Lewis <[email protected]> wrote:
> Why not use boxed primitives and the Object... ctor?
>
> e.g.
>
>             new Values( "string", 1.5, 3423423423L);
>
>
>
>
> On Wed, Dec 18, 2013 at 5:32 PM, Adrian Mocanu
> <[email protected]>wrote:
>
>>  Thanks
>>
>> A second pair of eyes helps J
>>
>>
>>
>> I wonder why string.toLong didn't work ..
>>
>>
>>
>> *From:* Jon Logan [mailto:[email protected]]
>> *Sent:* December-18-13 5:30 PM
>> *To:* [email protected]
>> *Subject:* Re: emitting various types - how to send long as string 
>> and unmarshal into long
>>
>>
>>
>>
>> http://stackoverflow.com/questions/7693324/converting-string-to-long-
>> in-java
>>
>>
>>
>> On Wed, Dec 18, 2013 at 5:25 PM, Adrian Mocanu 
>> <[email protected]>
>> wrote:
>>
>>  Hi
>>
>> I have a quick question about sending data of different types from a 
>> spout.
>>
>>
>>
>> I need to emit a string, double and long from a spout (all at once as 
>> a tuple).
>>
>> Unfortunately Values c'tor takes arguments of the same type so I 
>> decided to convert all of these to Strings.
>>
>>
>>
>>     _collector.emit(new Values(myNameAsString, myDouble.toString, 
>> myLong.toString ))
>>
>>
>>
>> When the tuple is received in the bolt it cannot convert the long 
>> back into a long.
>>
>>
>>
>>     java.lang.ClassCastException: java.lang.String cannot be cast to 
>> java.lang.Long
>>
>>
>>
>> I looked at the value and it is a valid long: 61345076523000
>>
>> The bolt code that does the str2int conversion is *val
>> tupleTimestampAsLong: Long= tuple.getString(2).toLong*
>>
>>
>>
>> The question, how to emit multiple values of different types from 
>> spout/bolt at once? (or at least how to convert a string into a long).
>>
>>
>>
>> Thanks a lot!
>>
>> -Adrian
>>
>>
>>
>>
>>
>

Reply via email to