MCPcopy
hub / github.com/uber/aresdb / ConvertToHumanReadable

Method ConvertToHumanReadable

memstore/common/data_value.go:240–329  ·  view source on GitHub ↗

ConvertToHumanReadable convert DataValue to meaningful golang data types

(dataType DataType)

Source from the content-addressed store, hash-verified

238
239// ConvertToHumanReadable convert DataValue to meaningful golang data types
240func (v1 DataValue) ConvertToHumanReadable(dataType DataType) interface{} {
241 if !v1.Valid {
242 return nil
243 }
244
245 if v1.IsBool {
246 return v1.BoolVal
247 }
248
249 switch dataType {
250 case Int8:
251 return *(*int8)(v1.OtherVal)
252 case Uint8, SmallEnum:
253 return *(*uint8)(v1.OtherVal)
254 case Int16:
255 return *(*int16)(v1.OtherVal)
256 case Uint16, BigEnum:
257 return *(*uint16)(v1.OtherVal)
258 case Int32:
259 return *(*int32)(v1.OtherVal)
260 case Uint32:
261 return *(*uint32)(v1.OtherVal)
262 case Int64:
263 return *(*int64)(v1.OtherVal)
264 case Float32:
265 return *(*float32)(v1.OtherVal)
266 case UUID:
267 bys := *(*[16]byte)(v1.OtherVal)
268 uuidStr := hex.EncodeToString(bys[:])
269 if len(uuidStr) == 32 {
270 return fmt.Sprintf("%s-%s-%s-%s-%s",
271 uuidStr[:8],
272 uuidStr[8:12],
273 uuidStr[12:16],
274 uuidStr[16:20],
275 uuidStr[20:])
276 }
277 case GeoPoint:
278 latLngs := *(*[2]float32)(v1.OtherVal)
279 // in string format, lng goes first and lat second
280 return fmt.Sprintf("Point(%.4f,%.4f)", latLngs[1], latLngs[0])
281 case GeoShape:
282 shape, ok := (v1.GoVal).(*GeoShapeGo)
283 if ok {
284 polygons := make([]string, len(shape.Polygons))
285 for i, points := range shape.Polygons {
286 pointsStrs := make([]string, len(points))
287 for j, point := range points {
288 // in string format, lng goes first and lat second
289 // https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry
290 pointsStrs[j] = fmt.Sprintf("%.4f+%.4f", point[1], point[0])
291 }
292 polygons[i] = fmt.Sprintf("(%s)", strings.Join(pointsStrs, ","))
293 }
294 return fmt.Sprintf("Polygon(%s)", strings.Join(polygons, ","))
295 }
296 default:
297 if IsArrayType(dataType) {

Callers 12

sink_test.goFile · 0.80
SliceMethod · 0.80
DumpMethod · 0.80
SliceMethod · 0.80
DumpMethod · 0.80
toUpsertBatchMethod · 0.80
DumpMethod · 0.80
DumpMethod · 0.80
data_value_test.goFile · 0.80
ReadDataMethod · 0.80
formatWithDataValueFunction · 0.80

Calls 7

GetLengthMethod · 0.95
IsValidMethod · 0.95
GetBoolMethod · 0.95
GetMethod · 0.95
IsArrayTypeFunction · 0.85
NewArrayValueReaderFunction · 0.85
JoinMethod · 0.65

Tested by

no test coverage detected