This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git
The following commit(s) were added to refs/heads/main by this push:
new d5ea6de91 perf(variant): scan ASCII bytes before normalizing path
members (#2275)
d5ea6de91 is described below
commit d5ea6de914d83e72091e75e9f9058051cba5447f
Author: Minh Vu <[email protected]>
AuthorDate: Fri Oct 23 18:50:04 2026 +0200
perf(variant): scan ASCII bytes before normalizing path members (#2275)
* perf(variant): scan ASCII bytes before normalizing path members
Signed-off-by: Minh Vu <[email protected]>
* style(variant): use integer range for ASCII path scan
Signed-off-by: Minh Vu <[email protected]>
* style(variant): separate loop exit for nlreturn
---------
Signed-off-by: Minh Vu <[email protected]>
---
variant_path.go | 15 ++++++++++++---
variant_path_normalize_bench_test.go | 2 ++
variant_path_test.go | 3 +++
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/variant_path.go b/variant_path.go
index 2da9fad55..27d1407d4 100644
--- a/variant_path.go
+++ b/variant_path.go
@@ -54,9 +54,18 @@ func NormalizeVariantPath(fields []string) string {
// writeRFC9535Escaped writes directly to the path builder, avoiding a
temporary
// string for each escaped member. Preserve the rune-based escaping semantics.
func writeRFC9535Escaped(b *strings.Builder, name string) {
- if strings.IndexFunc(name, func(r rune) bool {
- return r < 0x20 || r == '\'' || r == '\\'
- }) < 0 {
+ // Only ASCII controls, quotes and backslashes require escaping.
+ // Scan bytes before decoding runes for the uncommon escaped case.
+ needsEscape := false
+ for i := range len(name) {
+ c := name[i]
+ if c < 0x20 || c == '\'' || c == '\\' {
+ needsEscape = true
+
+ break
+ }
+ }
+ if !needsEscape {
b.WriteString(name)
return
diff --git a/variant_path_normalize_bench_test.go
b/variant_path_normalize_bench_test.go
index f963b1f3f..105c4c24f 100644
--- a/variant_path_normalize_bench_test.go
+++ b/variant_path_normalize_bench_test.go
@@ -32,6 +32,8 @@ func BenchmarkNormalizeVariantPath(b *testing.B) {
{"single", []string{"event_id"}},
{"nested4", []string{"location", "latitude", "metadata",
"distance"}},
{"nested16", strings.Fields(strings.Repeat("partition_column ",
16))},
+ {"nested64", strings.Fields(strings.Repeat("partition_column ",
64))},
+ {"escapedUnicode", []string{"東京\n", "naïve\\field",
"🦊'report"}},
{"unicode", []string{"naïve", "地名", "la🦊"}},
{"escaped", []string{"o'brien", "a\\b", "a\nline", "a\x01b"}},
{"controls",
[]string{strings.Repeat("a\x01\x02\x03\x04\x05\x1f", 8)}},
diff --git a/variant_path_test.go b/variant_path_test.go
index 62ae7ede8..daacb63c2 100644
--- a/variant_path_test.go
+++ b/variant_path_test.go
@@ -41,6 +41,9 @@ func TestNormalizeVariantPathEscaping(t *testing.T) {
{"common control escapes", []string{"\b\t\f\n\r"},
"$['\\b\\t\\f\\n\\r']"},
{"nested escaped members", []string{"o'brien", "a\x00\x1fb",
"a\\b"}, "$['o\\'brien']['a\\u0000\\u001fb']['a\\\\b']"},
{"unicode members", []string{"naïve", "東京"},
"$['naïve']['東京']"},
+ {"unescaped invalid UTF8", []string{"bad\xff"}, "$['bad\xff']"},
+ {"escaped invalid UTF8", []string{"bad\xff'\x80"},
"$['bad\uFFFD\\'\uFFFD']"},
+ {"unicode with control", []string{"東京\n🦊"}, "$['東京\\n🦊']"},
{"empty member", []string{""}, "$['']"},
} {
t.Run(tt.name, func(t *testing.T) {