MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestNormalizeQueryHash

Function TestNormalizeQueryHash

server/querylog_test.go:53–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51 if got != tt.want {
52 t.Errorf("classifyQuery(%q) = %q, want %q", tt.cmdType, got, tt.want)
53 }
54 })
55 }
56}
57
58func TestNormalizeQueryHash(t *testing.T) {
59 // Same query with different literal values should produce the same hash
60 h1 := normalizeQueryHash("SELECT * FROM users WHERE id = 1")
61 h2 := normalizeQueryHash("SELECT * FROM users WHERE id = 2")
62 if h1 != h2 {
63 t.Errorf("Expected same hash for queries differing only in literals, got %d and %d", h1, h2)
64 }
65
66 // Same query with different string literals
67 h3 := normalizeQueryHash("SELECT * FROM users WHERE name = 'alice'")
68 h4 := normalizeQueryHash("SELECT * FROM users WHERE name = 'bob'")
69 if h3 != h4 {
70 t.Errorf("Expected same hash for queries differing only in string literals, got %d and %d", h3, h4)
71 }
72
73 // Different queries should produce different hashes
74 h5 := normalizeQueryHash("SELECT * FROM users WHERE id = 1")
75 h6 := normalizeQueryHash("SELECT * FROM orders WHERE id = 1")
76 if h5 == h6 {
77 t.Errorf("Expected different hashes for different queries, both got %d", h5)
78 }
79
80 // Whitespace normalization
81 h7 := normalizeQueryHash("SELECT * FROM users WHERE id = 1")
82 h8 := normalizeQueryHash("SELECT * FROM users WHERE id = 1")
83 if h7 != h8 {
84 t.Errorf("Expected same hash after whitespace normalization, got %d and %d", h7, h8)
85 }
86
87 // Case normalization
88 h9 := normalizeQueryHash("select * from users where id = 1")
89 h10 := normalizeQueryHash("SELECT * FROM users WHERE id = 1")
90 if h9 != h10 {
91 t.Errorf("Expected same hash after case normalization, got %d and %d", h9, h10)
92 }
93
94 // Keywords in IS predicates should not be normalized away as literals.
95 h11 := normalizeQueryHash("SELECT * FROM users WHERE active IS TRUE")
96 h12 := normalizeQueryHash("SELECT * FROM users WHERE active IS NULL")
97 if h11 == h12 {
98 t.Errorf("Expected different hashes for IS TRUE vs IS NULL predicates, both got %d", h11)

Callers

nothing calls this directly

Calls 1

normalizeQueryHashFunction · 0.85

Tested by

no test coverage detected