diff --git a/pkg/parquetquery/intern/intern.go b/pkg/parquetquery/intern/intern.go index caf61ac823b..d146fffd59d 100644 --- a/pkg/parquetquery/intern/intern.go +++ b/pkg/parquetquery/intern/intern.go @@ -1,5 +1,4 @@ // Package intern is a utility for interning byte slices for pq.Value's. -// It is not safe for concurrent use. // // The Interner is used to intern byte slices for pq.Value's. This is useful // for reducing memory usage and improving performance when working with @@ -18,7 +17,9 @@ func New() *Interner { return &Interner{} } -func (i *Interner) UnsafeClone(v *pq.Value) pq.Value { +// Clone returns a unique shalow copy of the input pq.Value or derefernces the +// received pointer. +func (i *Interner) Clone(v *pq.Value) pq.Value { switch v.Kind() { case pq.ByteArray, pq.FixedLenByteArray: return *unique.Make(v).Value() diff --git a/pkg/parquetquery/intern/intern_test.go b/pkg/parquetquery/intern/intern_test.go index 349b85ca974..5decc3e11b4 100644 --- a/pkg/parquetquery/intern/intern_test.go +++ b/pkg/parquetquery/intern/intern_test.go @@ -13,8 +13,8 @@ func TestInterner_UnsafeClone(t *testing.T) { value1 := pq.ByteArrayValue([]byte("foo")) value2 := pq.ByteArrayValue([]byte("foo")) - clone1 := i.UnsafeClone(&value1) - clone2 := i.UnsafeClone(&value2) + clone1 := i.Clone(&value1) + clone2 := i.Clone(&value2) if clone1.ByteArray()[0] != clone2.ByteArray()[0] { // Values are interned, so the memory address should be the same @@ -65,7 +65,7 @@ func BenchmarkIntern(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { value := tc.valueFn(i) - _ = interner.UnsafeClone(&value) + _ = interner.Clone(&value) } }) } diff --git a/pkg/parquetquery/iters.go b/pkg/parquetquery/iters.go index 4b77bd4776f..bef5f7d0202 100644 --- a/pkg/parquetquery/iters.go +++ b/pkg/parquetquery/iters.go @@ -1248,7 +1248,7 @@ func (c *SyncIterator) makeResult(t RowNumber, v *pq.Value) *IteratorResult { // always have length 0 or 1. if len(c.at.Entries) == 1 { if c.intern { - c.at.Entries[0].Value = c.interner.UnsafeClone(v) + c.at.Entries[0].Value = c.interner.Clone(v) } else { c.at.Entries[0].Value = v.Clone() }