Documentation Index
Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
Use this file to discover all available pages before exploring further.
NaN (Not a Number)
The danger of NaN
In Java,NaN has the property that NaN != NaN.
This is a problem when storing NaN in a numeric dictionary, as the dictionary uses == to compare values.
This means that the value will never be found and each instance of NaN will be mapped to a new value in the dictionary.
It leads to an ever-growing dictionary, wasting memory, and potential bad result in queries.
How to handle NaN:
Do not dictionarize a field containing NaN
It is ok to have someNaN values in the datastore as long as the field storing the value is not dictionarized.
For instance, such field can be used as a measure.
Try to avoid using NaN
If you need to dictionarize the field to use it as a hierarchy, then try to avoid usingNaN:
- Use another special value as the marker for “no value”, for instance
null,Double.NEGATIVE_INFINITY,Double.POSITIVE_INFINITY,Double.MAX_VALUE… - Use a String column with
N/Aand parse the value when you need it as double (parseN/Athe same way you would useNaN) - Use 2 columns: one
Stringand onedouble(you can have one column calculated based on the other) and use theStringcolumn as the hierarchy and the numeric column for measures.
Type the column as Object
You can also type the column as Object instead of Double, so it uses an object dictionary which compares values with Object.equals(...).
As NaN.equals(Nan) is true, the dictionary will be able to correctly match the NaN.