Skip to content

Commit

Permalink
[pdata] Rename ValueTypeArray to ValueTypeSlice (#5066)
Browse files Browse the repository at this point in the history
* [pdata] Rename ValueTypeArray to ValueTypeSlice

`pdata.ValueTypeArray` is not deprecated because it was introduced few commits before and not released yet.

* Update CHANGELOG.md
  • Loading branch information
dmitryax authored Mar 23, 2022
1 parent 328ca94 commit 1b76187
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 39 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
- Deprecate `pdata.AttributeValueSlice` struct in favor of `pdata.Slice`
- Deprecate `pdata.NewAttributeValueSlice` func in favor of `pdata.NewSlice`
- Deprecate LogRecord.Name(), it was deprecated in the data model (#5054)
- Rename `Array` type of `pdata.Value` to `Slice` (#5067)
- Deprecate `pdata.AttributeValueTypeArray` type in favor of `pdata.ValueTypeSlice`
- Deprecate `pdata.NewAttributeValueArray` func in favor of `pdata.NewValueSlice`
- Deprecate global flag in `featuregates` (#5060)

### 💡 Enhancements 💡
Expand Down
2 changes: 1 addition & 1 deletion internal/otlptext/databuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func attributeValueToString(v pdata.Value) string {
return strconv.FormatFloat(v.DoubleVal(), 'f', -1, 64)
case pdata.ValueTypeInt:
return strconv.FormatInt(v.IntVal(), 10)
case pdata.ValueTypeArray:
case pdata.ValueTypeSlice:
return sliceToString(v.SliceVal())
case pdata.ValueTypeMap:
return mapToString(v.MapVal())
Expand Down
4 changes: 2 additions & 2 deletions internal/otlptext/databuffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
)

func TestNestedArraySerializesCorrectly(t *testing.T) {
ava := pdata.NewValueArray()
ava := pdata.NewValueSlice()
ava.SliceVal().AppendEmpty().SetStringVal("foo")
ava.SliceVal().AppendEmpty().SetIntVal(42)

ava2 := pdata.NewValueArray()
ava2 := pdata.NewValueSlice()
ava2.SliceVal().AppendEmpty().SetStringVal("bar")
ava2.CopyTo(ava.SliceVal().AppendEmpty())

Expand Down
4 changes: 2 additions & 2 deletions model/internal/cmd/pdatagen/internal/common_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var commonFile = &File{
},
structs: []baseStruct{
instrumentationLibrary,
attributeValueArray,
attributeValueSlice,
},
}

Expand Down Expand Up @@ -109,7 +109,7 @@ var anyValue = &messageValueStruct{
originFullName: "otlpcommon.AnyValue",
}

var attributeValueArray = &sliceOfValues{
var attributeValueSlice = &sliceOfValues{
structName: "Slice",
element: anyValue,
}
Expand Down
24 changes: 12 additions & 12 deletions model/internal/pdata/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
ValueTypeDouble
ValueTypeBool
ValueTypeMap
ValueTypeArray
ValueTypeSlice
ValueTypeBytes
)

Expand All @@ -58,8 +58,8 @@ func (avt ValueType) String() string {
return "DOUBLE"
case ValueTypeMap:
return "MAP"
case ValueTypeArray:
return "ARRAY"
case ValueTypeSlice:
return "SLICE"
case ValueTypeBytes:
return "BYTES"
}
Expand Down Expand Up @@ -120,8 +120,8 @@ func NewValueMap() Value {
return Value{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_KvlistValue{KvlistValue: &otlpcommon.KeyValueList{}}}}
}

// NewValueArray creates a new Value of array type.
func NewValueArray() Value {
// NewValueSlice creates a new Value of array type.
func NewValueSlice() Value {
return Value{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_ArrayValue{ArrayValue: &otlpcommon.ArrayValue{}}}}
}

Expand Down Expand Up @@ -171,7 +171,7 @@ func newValueFromRaw(iv interface{}) Value {
NewMapFromRaw(tv).CopyTo(mv.MapVal())
return mv
case []interface{}:
av := NewValueArray()
av := NewValueSlice()
newSliceFromRaw(tv).CopyTo(av.SliceVal())
return av
default:
Expand All @@ -197,7 +197,7 @@ func (v Value) Type() ValueType {
case *otlpcommon.AnyValue_KvlistValue:
return ValueTypeMap
case *otlpcommon.AnyValue_ArrayValue:
return ValueTypeArray
return ValueTypeSlice
case *otlpcommon.AnyValue_BytesValue:
return ValueTypeBytes
}
Expand Down Expand Up @@ -246,7 +246,7 @@ func (v Value) MapVal() Map {
}

// SliceVal returns the slice value associated with this Value.
// If the Type() is not ValueTypeArray then returns an invalid slice. Note that using
// If the Type() is not ValueTypeSlice then returns an invalid slice. Note that using
// such slice can cause panic.
//
// Calling this function on zero-initialized Value will cause a panic.
Expand Down Expand Up @@ -376,7 +376,7 @@ func (v Value) Equal(av Value) bool {
newAv := newValue(&vv[i])

// According to the specification, array values must be scalar.
if avType := newAv.Type(); avType == ValueTypeArray || avType == ValueTypeMap {
if avType := newAv.Type(); avType == ValueTypeSlice || avType == ValueTypeMap {
return false
}

Expand Down Expand Up @@ -439,7 +439,7 @@ func (v Value) AsString() string {
case ValueTypeBytes:
return base64.StdEncoding.EncodeToString(v.BytesVal())

case ValueTypeArray:
case ValueTypeSlice:
jsonStr, _ := json.Marshal(v.SliceVal().asRaw())
return string(jsonStr)

Expand Down Expand Up @@ -495,7 +495,7 @@ func (v Value) asRaw() interface{} {
return v.BytesVal()
case ValueTypeMap:
v.MapVal().AsRaw()
case ValueTypeArray:
case ValueTypeSlice:
v.SliceVal().asRaw()
}
return fmt.Sprintf("<Unknown OpenTelemetry value type %q>", v.Type())
Expand Down Expand Up @@ -939,7 +939,7 @@ func (m Map) AsRaw() map[string]interface{} {
rawMap[k] = nil
case ValueTypeMap:
rawMap[k] = v.MapVal().AsRaw()
case ValueTypeArray:
case ValueTypeSlice:
rawMap[k] = v.SliceVal().asRaw()
}
return true
Expand Down
32 changes: 16 additions & 16 deletions model/internal/pdata/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestAttributeValueType(t *testing.T) {
assert.EqualValues(t, "INT", ValueTypeInt.String())
assert.EqualValues(t, "DOUBLE", ValueTypeDouble.String())
assert.EqualValues(t, "MAP", ValueTypeMap.String())
assert.EqualValues(t, "ARRAY", ValueTypeArray.String())
assert.EqualValues(t, "SLICE", ValueTypeSlice.String())
assert.EqualValues(t, "BYTES", ValueTypeBytes.String())
}

Expand Down Expand Up @@ -234,12 +234,12 @@ func TestAttributeValueEqual(t *testing.T) {
av1 = NewValueBytes([]byte{1, 2, 3})
assert.True(t, av1.Equal(av2))

av1 = NewValueArray()
av1 = NewValueSlice()
av1.SliceVal().AppendEmpty().SetIntVal(123)
assert.False(t, av1.Equal(av2))
assert.False(t, av2.Equal(av1))

av2 = NewValueArray()
av2 = NewValueSlice()
av2.SliceVal().AppendEmpty().SetDoubleVal(123)
assert.False(t, av1.Equal(av2))

Expand Down Expand Up @@ -976,17 +976,17 @@ func generateTestBytesMap() Map {
})
}

func TestAttributeValueArray(t *testing.T) {
a1 := NewValueArray()
assert.EqualValues(t, ValueTypeArray, a1.Type())
func TestAttributeValueSlice(t *testing.T) {
a1 := NewValueSlice()
assert.EqualValues(t, ValueTypeSlice, a1.Type())
assert.EqualValues(t, NewSlice(), a1.SliceVal())
assert.EqualValues(t, 0, a1.SliceVal().Len())

a1.SliceVal().AppendEmpty().SetDoubleVal(123)
assert.EqualValues(t, 1, a1.SliceVal().Len())
assert.EqualValues(t, NewValueDouble(123), a1.SliceVal().At(0))
// Create a second array.
a2 := NewValueArray()
a2 := NewValueSlice()
assert.EqualValues(t, 0, a2.SliceVal().Len())

a2.SliceVal().AppendEmpty().SetStringVal("somestr")
Expand All @@ -1001,7 +1001,7 @@ func TestAttributeValueArray(t *testing.T) {

// Check that the array was correctly inserted.
childArray := a1.SliceVal().At(1)
assert.EqualValues(t, ValueTypeArray, childArray.Type())
assert.EqualValues(t, ValueTypeSlice, childArray.Type())
assert.EqualValues(t, 1, childArray.SliceVal().Len())

v := childArray.SliceVal().At(0)
Expand Down Expand Up @@ -1084,12 +1084,12 @@ func TestAsString(t *testing.T) {
},
{
name: "empty_array",
input: NewValueArray(),
input: NewValueSlice(),
expected: "[]",
},
{
name: "simple_array",
input: simpleValueArray(),
input: simpleValueSlice(),
expected: "[\"strVal\",7,18.6,false,null]",
},
{
Expand Down Expand Up @@ -1254,7 +1254,7 @@ func TestNewValueFromRaw(t *testing.T) {
name: "slice",
input: []interface{}{"v1", "v2"},
expected: (func() Value {
s := NewValueArray()
s := NewValueSlice()
newSliceFromRaw([]interface{}{"v1", "v2"}).CopyTo(s.SliceVal())
return s
})(),
Expand All @@ -1281,8 +1281,8 @@ func simpleValueMap() Value {
return ret
}

func simpleValueArray() Value {
ret := NewValueArray()
func simpleValueSlice() Value {
ret := NewValueSlice()
attrArr := ret.SliceVal()
attrArr.AppendEmpty().SetStringVal("strVal")
attrArr.AppendEmpty().SetIntVal(7)
Expand All @@ -1300,7 +1300,7 @@ func constructTestAttributeSubmap() Value {
}

func constructTestAttributeSubarray() Value {
value := NewValueArray()
value := NewValueSlice()
value.SliceVal().AppendEmpty().SetStringVal("strOne")
value.SliceVal().AppendEmpty().SetStringVal("strTwo")
return value
Expand All @@ -1315,8 +1315,8 @@ func BenchmarkAttributeValueMapAccessor(b *testing.B) {
}
}

func BenchmarkAttributeValueArrayAccessor(b *testing.B) {
val := simpleValueArray()
func BenchmarkAttributeValueSliceAccessor(b *testing.B) {
val := simpleValueSlice()

b.ResetTimer()
for n := 0; n < b.N; n++ {
Expand Down
12 changes: 6 additions & 6 deletions model/pdata/common_alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
ValueTypeDouble = pdata.ValueTypeDouble
ValueTypeBool = pdata.ValueTypeBool
ValueTypeMap = pdata.ValueTypeMap
ValueTypeArray = pdata.ValueTypeArray
ValueTypeSlice = pdata.ValueTypeSlice
ValueTypeBytes = pdata.ValueTypeBytes

// Deprecated: [v0.48.0] Use ValueTypeEmpty instead.
Expand All @@ -54,8 +54,8 @@ const (
// Deprecated: [v0.48.0] Use ValueTypeMap instead.
AttributeValueTypeMap = pdata.ValueTypeMap

// Deprecated: [v0.48.0] Use ValueTypeArray instead.
AttributeValueTypeArray = pdata.ValueTypeArray
// Deprecated: [v0.48.0] Use ValueTypeSlice instead.
AttributeValueTypeArray = pdata.ValueTypeSlice

// Deprecated: [v0.48.0] Use ValueTypeBytes instead.
AttributeValueTypeBytes = pdata.ValueTypeBytes
Expand All @@ -75,7 +75,7 @@ var (
NewValueDouble = pdata.NewValueDouble
NewValueBool = pdata.NewValueBool
NewValueMap = pdata.NewValueMap
NewValueArray = pdata.NewValueArray
NewValueSlice = pdata.NewValueSlice
NewValueBytes = pdata.NewValueBytes

// Deprecated: [v0.48.0] Use NewValueEmpty instead.
Expand All @@ -96,8 +96,8 @@ var (
// Deprecated: [v0.48.0] Use NewValueMap instead.
NewAttributeValueMap = pdata.NewValueMap

// Deprecated: [v0.48.0] Use NewValueArray instead.
NewAttributeValueArray = pdata.NewValueArray
// Deprecated: [v0.48.0] Use NewValueSlice instead.
NewAttributeValueArray = pdata.NewValueSlice

// Deprecated: [v0.48.0] Use NewValueBytes instead.
NewAttributeValueBytes = pdata.NewValueBytes
Expand Down

0 comments on commit 1b76187

Please sign in to comment.