Files
traces/tempodb/backend/dedicated_columns_cache_test.go
A. StoewerandGitHub e181a50c19 vParquet5: remove well-known attribute columns (#5696)
* Define default dedicated attribute columns

* Use default dedicated columns in block config

* vp4 ignores well-known attrs in dedicated columns

* vp3 ignores well-known attrs in dedicated columns

* Improve tenantindex benchmarks

* Use LRU cache for unmarshaled JSON columns

* Set version to vParquet5-preview3

* Remove well-known attribute columns on span level

* Remove well-known attribute columns on resource level

* Convert vp5 test-data and re-enable find by ID test

* Generate manifest.md

* vp3 and vp4 ignore all unsupported attributes

* vp5 ignores unsupported attributes

* CHANGELOG.md
2025-10-17 15:05:26 +10:00

67 lines
1.5 KiB
Go

package backend
import (
"encoding/json"
"testing"
"unsafe"
"github.com/stretchr/testify/require"
)
func Test_getDedicatedColumnsFromCache(t *testing.T) {
tests := []struct {
name string
jsonStr string
isCached bool
expected DedicatedColumns
}{
{
name: "null",
jsonStr: `null`,
expected: nil,
},
{
name: "empty",
jsonStr: `[]`,
expected: DedicatedColumns{},
},
{
name: "not empty",
jsonStr: `[ {"s": "resource", "n": "namespace"}, {"n": "http.method"}, {"n": "namespace"} ]`,
isCached: true,
expected: DedicatedColumns{
{Scope: "resource", Name: "namespace", Type: "string"},
{Scope: "span", Name: "http.method", Type: "string"},
{Scope: "span", Name: "namespace", Type: "string"},
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
jsonBytes := []byte(tc.jsonStr)
// clear the map so we start with a clean slate
dedicatedColumnsCache.Purge()
if tc.isCached {
v, ok := getDedicatedColumnsFromCache(jsonBytes)
require.False(t, ok)
require.Nil(t, v)
}
dcs := DedicatedColumns{}
err := json.Unmarshal(jsonBytes, &dcs)
require.NoError(t, err)
require.Equal(t, tc.expected, dcs)
v, ok := getDedicatedColumnsFromCache(jsonBytes)
require.True(t, ok)
require.Equal(t, dcs, v)
if tc.isCached {
require.Equal(t, unsafe.Pointer(&dcs[0]), unsafe.Pointer(&v[0])) // check v was taken from the cache (pointers are the same)
}
})
}
}