Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Error retrieving long values using the API: Default Gson parser converts any number to Double. #19

Closed
darroyocazorla opened this issue Dec 16, 2014 · 3 comments
Labels
Milestone

Comments

@darroyocazorla
Copy link
Member

I am trying to listening an existing stream using the API. Numerical columns are returned as Double. Therefore, there is loss of precision working with longs. The streaming shell is working OK. Is there any way to solve it?

Thanks.

@ajnavarro
Copy link
Contributor

Hi @darroyostratio, Could you post any example of this (queries used, code snippet, etc.)? thanks.

@darroyocazorla
Copy link
Member Author

We are just listening the stream. This is the code to read the messages:

String host = "127.0.0.1";
final IStratioStreamingAPI stratioStreamingAPI = StratioStreamingAPIFactory.create()
.initializeWithServerConfig(host, 9092, host, 2181);

ColumnNameType firstStreamColumn = new ColumnNameType("column1", ColumnType.LONG); final String streamName = "testStream";

stratioStreamingAPI.createStream(streamName, Arrays.asList(firstStreamColumn));

KafkaStream<String, StratioStreamingMessage> streams = stratioStreamingAPI.listenStream(streamName);

for (MessageAndMetadata stream : streams) {
StratioStreamingMessage theMessage = (StratioStreamingMessage) stream.message();
for (ColumnNameTypeValue column : theMessage.getColumns()) {
System.out.println("Column: " + column.getColumn());
System.out.println("Value: " + column.getValue());
System.out.println("Type: " + column.getType());
System.out.println("JavaType: " + column.getValue().getClass().getName());
System.out.println("Cast: " + (long) (double) column.getValue());
}
}

@ajnavarro
Copy link
Contributor

Error Catched! Gson translate to Double any number value into a json file.

    new Gson().fromJson(new String(bytes), classOf[StratioStreamingMessage])

Added an issue #20 to fix the problem.

@ajnavarro ajnavarro added the bug label Dec 16, 2014
@ajnavarro ajnavarro added this to the 0.6.2 milestone Jan 12, 2015
@ajnavarro ajnavarro changed the title Error retrieving long values using the API Error retrieving long values using the API: Default Gson parser converts any number to Double. Jan 12, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants