From 405dbca5feb8b99eb16a7fe1fbb376ad4ab573f9 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Wed, 8 Jan 2025 09:33:38 +0100 Subject: [PATCH] fix after rebase Signed-off-by: odubajDT --- pkg/ottl/e2e/e2e_test.go | 11 +++++------ pkg/ottl/ottlfuncs/func_flatten.go | 7 ++++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/ottl/e2e/e2e_test.go b/pkg/ottl/e2e/e2e_test.go index d6b188572904..80934b0bd8ef 100644 --- a/pkg/ottl/e2e/e2e_test.go +++ b/pkg/ottl/e2e/e2e_test.go @@ -126,13 +126,12 @@ func Test_e2e_editors(t *testing.T) { m.PutStr("test.conflict.conflict1.conflict2", "pass") m.PutStr("test.conflict.conflict1.conflict2.0", "nopass") - m1 := m.PutEmptyMap("test.things") - m1.PutStr("name", "foo") - m1.PutInt("value", 2) + m.PutStr("test.things.0.name", "foo") + m.PutInt("test.things.0.value", 2) + + m.PutStr("test.things.1.name", "bar") + m.PutInt("test.things.1.value", 5) - m2 := m.PutEmptyMap("test.things.0") - m2.PutStr("name", "bar") - m2.PutInt("value", 5) m.CopyTo(tCtx.GetLogRecord().Attributes()) }, }, diff --git a/pkg/ottl/ottlfuncs/func_flatten.go b/pkg/ottl/ottlfuncs/func_flatten.go index f4c6cd993c4d..fce1ab3594a9 100644 --- a/pkg/ottl/ottlfuncs/func_flatten.go +++ b/pkg/ottl/ottlfuncs/func_flatten.go @@ -96,7 +96,12 @@ func flattenValue(k string, v pcommon.Value, currentDepth int64, maxDepth int64, case v.Slice().At(i).Type() == pcommon.ValueTypeSlice && currentDepth+1 < maxDepth: flattenSlice(v.Slice().At(i).Slice(), result, fmt.Sprintf("%v.%v", prefix+k, i), currentDepth+2, maxDepth, conflict, existingKeys) default: - v.Slice().At(i).CopyTo(result.PutEmpty(fmt.Sprintf("%v.%v", prefix+k, i))) + key := prefix + k + if conflict { + handleConflict(existingKeys, key, v.Slice().At(i), &result) + } else { + v.Slice().At(i).CopyTo(result.PutEmpty(fmt.Sprintf("%v.%v", key, i))) + } } } default: