@@ -69,6 +69,7 @@ var converterMap = map[string]data.FieldConverter{
69
69
"long" : longConverter ,
70
70
"real" : realConverter ,
71
71
"bool" : boolConverter ,
72
+ "decimal" : decimalConverter ,
72
73
}
73
74
74
75
var stringConverter = data.FieldConverter {
@@ -194,3 +195,41 @@ var longConverter = data.FieldConverter{
194
195
return & out , err
195
196
},
196
197
}
198
+
199
+ // decimalConverter converts the Kusto 128-bit type number to
200
+ // a float64. We do not have 128 bit numbers in our dataframe
201
+ // model yet (and even if we did, not sure how javascript would handle them).
202
+ // In the future, we may want to revisit storing this will proper precision,
203
+ // but for now it solves the case of people getting an error response.
204
+ // If we were to keep it a string, it would not work correctly with calls
205
+ // to functions like sdk's data.LongToWide.
206
+ var decimalConverter = data.FieldConverter {
207
+ OutputFieldType : data .FieldTypeNullableFloat64 ,
208
+ Converter : func (v interface {}) (interface {}, error ) {
209
+ var af * float64
210
+ if v == nil {
211
+ return af , nil
212
+ }
213
+
214
+ jS , sOk := v .(string )
215
+ if sOk {
216
+ out , err := strconv .ParseFloat (jS , 64 )
217
+ if err != nil {
218
+ return nil , err
219
+ }
220
+ return & out , err
221
+ }
222
+
223
+ // As far as I can tell this always comes in a string, but this is in the
224
+ // ADX code, so leaving this in case values do sometimes become a number somehow.
225
+ jN , nOk := v .(json.Number )
226
+ if ! nOk {
227
+ return nil , fmt .Errorf ("unexpected type, expected json.Number or string but got type %T with a value of %v" , v , v )
228
+ }
229
+ out , err := jN .Float64 () // Float64 calls strconv.ParseFloat64
230
+ if err != nil {
231
+ return nil , err
232
+ }
233
+ return & out , nil
234
+ },
235
+ }
0 commit comments