Double Scientific Notation Issue

19 views
Skip to first unread message

Shrikant Dange

unread,
Mar 25, 2016, 3:54:21 PM3/25/16
to cascading-user
Hi All,
   I am trying to find the solution to avoid conversion of double value in scientific notation.
   e.g. 7536546814678.12 to 7.53654681467812E12
        Note: If double value is less thant 10^-3 or greateer than 10^7 then only it gets converted to scientific notation.
//Code
Fields inputFields = new Fields("double_val").applyTypes(Double.class);
Scheme inputScheme = new TextDelimited(inputFields,true,",");
Tap inTap = new Hfs(inputScheme,inputPath,SinkMode.REPLACE);
Pipe mainPipe = new Pipe("main");
Scheme outputScheme = new TextDelimited(inputFields,true,",");
Tap outTap = new Hfs(outputScheme,outputPath,SinkMode.REPLACE);
FlowDef flowDef = FlowDef.flowDef();
flowDef.setName("Project2");
flowDef.addSource(mainPipe, inTap);
flowDef.addTailSink(mainPipe, outTap);
Flow wcFlow = flowConnector.connect(flowDef);
wcFlow.complete();
//
Input File:
double_val
7536546814678.12
76748.76
Actual Output:
double_val
7.53654681467812E12
76748.76
 
Expected Output:
7536546814678.12
76748.76
Observations:
public Double coerce( Object value ) method from cascading.tuple.coerce.DoubleObjectCoerce class executes:
Double.parseDouble( value.toString() )  which results in conversion of double values.
Could you please let me know if there is any workaround for this?
Regards,
Shrikant Dange

Andre Kelpe

unread,
Mar 29, 2016, 6:25:08 AM3/29/16
to cascading-user
You can write your own types with custom Coerce method instead of
using the built-in ones:

http://docs.cascading.org/cascading/3.0/userguide/ch04-tuple-fields.html#field-coercion

http://docs.cascading.org/cascading/3.0/userguide/ch04-tuple-fields.html#field-typing

http://docs.cascading.org/cascading/3.0/userguide/ch10-hadoop-common.html#custom-types

http://docs.cascading.org/cascading/3.0/userguide/ch19-extending-cascading.html#custom-types

- André
> --
> You received this message because you are subscribed to the Google Groups
> "cascading-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cascading-use...@googlegroups.com.
> To post to this group, send email to cascadi...@googlegroups.com.
> Visit this group at https://groups.google.com/group/cascading-user.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/cascading-user/c6ea6ed1-f9a0-48fe-a6cf-296f483dd0ec%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
André Kelpe
an...@concurrentinc.com
http://concurrentinc.com
Reply all
Reply to author
Forward
0 new messages