-
Notifications
You must be signed in to change notification settings - Fork 15
/
any_value.go
93 lines (87 loc) · 3.13 KB
/
any_value.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package otlp
import (
"github.com/apache/arrow/go/v16/arrow/array"
"go.opentelemetry.io/collector/pdata/pcommon"
arrowutils "github.com/open-telemetry/otel-arrow/pkg/arrow"
"github.com/open-telemetry/otel-arrow/pkg/otel/common"
commonarrow "github.com/open-telemetry/otel-arrow/pkg/otel/common/arrow"
"github.com/open-telemetry/otel-arrow/pkg/werror"
)
func UpdateValueFrom(v pcommon.Value, vArr *array.SparseUnion, row int) error {
tcode := vArr.TypeCode(row)
fieldID := vArr.ChildID(row)
switch tcode {
case commonarrow.StrCode:
strArr := vArr.Field(fieldID)
if strArr == nil {
return werror.WrapWithContext(ErrInvalidFieldId, map[string]interface{}{"tcode": tcode, "fieldID": fieldID, "row": row})
}
val, err := arrowutils.StringFromArray(strArr, row)
if err != nil {
return werror.Wrap(err)
}
v.SetStr(val)
case commonarrow.I64Code:
i64Arr := vArr.Field(fieldID)
if i64Arr == nil {
return werror.WrapWithContext(ErrInvalidFieldId, map[string]interface{}{"tcode": tcode, "fieldID": fieldID, "row": row})
}
val, err := arrowutils.I64FromArray(i64Arr, row)
if err != nil {
return werror.Wrap(err)
}
v.SetInt(val)
case commonarrow.F64Code:
f64Arr := vArr.Field(fieldID)
if f64Arr == nil {
return werror.WrapWithContext(ErrInvalidFieldId, map[string]interface{}{"tcode": tcode, "fieldID": fieldID, "row": row})
}
val := f64Arr.(*array.Float64).Value(row)
v.SetDouble(val)
case commonarrow.BoolCode:
boolArr := vArr.Field(fieldID)
if boolArr == nil {
return werror.WrapWithContext(ErrInvalidFieldId, map[string]interface{}{"tcode": tcode, "fieldID": fieldID, "row": row})
}
val := boolArr.(*array.Boolean).Value(row)
v.SetBool(val)
case commonarrow.BinaryCode:
binArr := vArr.Field(fieldID)
if binArr == nil {
return werror.WrapWithContext(ErrInvalidFieldId, map[string]interface{}{"tcode": tcode, "fieldID": fieldID, "row": row})
}
val, err := arrowutils.BinaryFromArray(binArr, row)
if err != nil {
return werror.Wrap(err)
}
v.SetEmptyBytes().FromRaw(val)
case commonarrow.CborCode:
cborArr := vArr.Field(fieldID)
if cborArr == nil {
return werror.WrapWithContext(ErrInvalidFieldId, map[string]interface{}{"tcode": tcode, "fieldID": fieldID, "row": row})
}
val, err := arrowutils.BinaryFromArray(cborArr, row)
if err != nil {
return werror.Wrap(err)
}
if err = common.Deserialize(val, v); err != nil {
return werror.Wrap(err)
}
default:
return werror.WrapWithContext(ErrInvalidTypeCode, map[string]interface{}{"tcode": tcode, "fieldID": fieldID, "row": row})
}
return nil
}