Skip to content

Commit

Permalink
Remove deprecated pcommon.Value.Equal (#6860)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Jan 18, 2023
1 parent c251f3d commit 5c12f09
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 155 deletions.
11 changes: 11 additions & 0 deletions .chloggen/rmpdateequal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: pdata

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove deprecated pcommon.Value.Equal

# One or more tracking issues or pull requests related to the change
issues: [6860]
67 changes: 0 additions & 67 deletions pdata/pcommon/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package pcommon // import "go.opentelemetry.io/collector/pdata/pcommon"
// such as timestamps, attributes, etc.

import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -365,72 +364,6 @@ func (v Value) CopyTo(dest Value) {
}
}

// Equal checks for equality, it returns true if the objects are equal otherwise false.
// Deprecated: [1.0.0-rc2] Use reflect.DeepEqual(v1.AsRaw(), v2.AsRaw()) in tests.
// If you need this method where performance is critical, please share your use case in
// https://github.com/open-telemetry/opentelemetry-collector/issues/6811
func (v Value) Equal(av Value) bool {
if v.getOrig() == av.getOrig() {
return true
}

if v.getOrig().Value == nil || av.getOrig().Value == nil {
return v.getOrig().Value == av.getOrig().Value
}

if v.Type() != av.Type() {
return false
}

switch v := v.getOrig().Value.(type) {
case *otlpcommon.AnyValue_StringValue:
return v.StringValue == av.getOrig().GetStringValue()
case *otlpcommon.AnyValue_BoolValue:
return v.BoolValue == av.getOrig().GetBoolValue()
case *otlpcommon.AnyValue_IntValue:
return v.IntValue == av.getOrig().GetIntValue()
case *otlpcommon.AnyValue_DoubleValue:
return v.DoubleValue == av.getOrig().GetDoubleValue()
case *otlpcommon.AnyValue_ArrayValue:
vv := v.ArrayValue.GetValues()
avv := av.getOrig().GetArrayValue().GetValues()
if len(vv) != len(avv) {
return false
}

for i := range avv {
if !newValue(&vv[i]).Equal(newValue(&avv[i])) {
return false
}
}
return true
case *otlpcommon.AnyValue_KvlistValue:
cc := v.KvlistValue.GetValues()
avv := av.getOrig().GetKvlistValue().GetValues()
if len(cc) != len(avv) {
return false
}

m := newMap(&avv)

for i := range cc {
newAv, ok := m.Get(cc[i].Key)
if !ok {
return false
}

if !newAv.Equal(newValue(&cc[i].Value)) {
return false
}
}
return true
case *otlpcommon.AnyValue_BytesValue:
return bytes.Equal(v.BytesValue, av.getOrig().GetBytesValue())
}

return false
}

// AsString converts an OTLP Value object of any type to its equivalent string
// representation. This differs from GetString which only returns a non-empty value
// if the ValueType is ValueTypeStr.
Expand Down
88 changes: 0 additions & 88 deletions pdata/pcommon/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,94 +174,6 @@ func TestNilOrigSetValue(t *testing.T) {
assert.Equal(t, []interface{}{int64(1), "val"}, av.Slice().AsRaw())
}

func TestValueEqual(t *testing.T) {
av1 := NewValueEmpty()
assert.True(t, av1.Equal(av1)) // nolint:gocritic
av2 := NewValueEmpty()
assert.True(t, av1.Equal(av2))

av2 = NewValueStr("abc")
assert.False(t, av1.Equal(av2))
assert.False(t, av2.Equal(av1))

av1 = NewValueStr("abc")
assert.True(t, av1.Equal(av2))

av2 = NewValueStr("edf")
assert.False(t, av1.Equal(av2))

av2 = NewValueInt(123)
assert.False(t, av1.Equal(av2))
assert.False(t, av2.Equal(av1))

av1 = NewValueInt(234)
assert.False(t, av1.Equal(av2))

av1 = NewValueInt(123)
assert.True(t, av1.Equal(av2))

av2 = NewValueDouble(123)
assert.False(t, av1.Equal(av2))
assert.False(t, av2.Equal(av1))

av1 = NewValueDouble(234)
assert.False(t, av1.Equal(av2))

av1 = NewValueDouble(123)
assert.True(t, av1.Equal(av2))

av2 = NewValueBool(false)
assert.False(t, av1.Equal(av2))
assert.False(t, av2.Equal(av1))

av1 = NewValueBool(true)
assert.False(t, av1.Equal(av2))

av1 = NewValueBool(false)
assert.True(t, av1.Equal(av2))

av2 = NewValueBytes()
av2.Bytes().FromRaw([]byte{1, 2, 3})
assert.False(t, av1.Equal(av2))
assert.False(t, av2.Equal(av1))

av1 = NewValueBytes()
av1.Bytes().FromRaw([]byte{1, 2, 4})
assert.False(t, av1.Equal(av2))

av1.Bytes().SetAt(2, 3)
assert.True(t, av1.Equal(av2))

av1 = NewValueSlice()
av1.Slice().AppendEmpty().SetInt(123)
assert.False(t, av1.Equal(av2))
assert.False(t, av2.Equal(av1))

av2 = NewValueSlice()
av2.Slice().AppendEmpty().SetDouble(123)
assert.False(t, av1.Equal(av2))

NewValueInt(123).CopyTo(av2.Slice().At(0))
assert.True(t, av1.Equal(av2))

av1.CopyTo(av2.Slice().AppendEmpty())
assert.False(t, av1.Equal(av2))

av1 = NewValueMap()
av1.Map().PutStr("foo", "bar")
assert.False(t, av1.Equal(av2))
assert.False(t, av2.Equal(av1))

av2 = NewValueMap()
av2.Map().PutStr("foo", "bar")
assert.True(t, av1.Equal(av2))

fooVal, ok := av2.Map().Get("foo")
assert.True(t, ok)
fooVal.SetStr("not-bar")
assert.False(t, av1.Equal(av2))
}

func TestMap(t *testing.T) {
assert.EqualValues(t, 0, NewMap().Len())

Expand Down

0 comments on commit 5c12f09

Please sign in to comment.