(t *testing.T)
| 92 | } |
| 93 | |
| 94 | func TestBufferStringInterning(t *testing.T) { |
| 95 | // Create test data with repeated categorical values |
| 96 | data := [][]string{ |
| 97 | {"Category", "Value"}, |
| 98 | {"A", "100"}, |
| 99 | {"B", "200"}, |
| 100 | {"A", "300"}, // Repeated |
| 101 | {"C", "400"}, |
| 102 | {"A", "500"}, // Repeated |
| 103 | {"B", "600"}, // Repeated |
| 104 | } |
| 105 | |
| 106 | // Add more rows to make it worthwhile |
| 107 | for i := 0; i < 100; i++ { |
| 108 | data = append(data, []string{"A", fmt.Sprintf("%d", i)}) |
| 109 | data = append(data, []string{"B", fmt.Sprintf("%d", i+1000)}) |
| 110 | data = append(data, []string{"C", fmt.Sprintf("%d", i+2000)}) |
| 111 | } |
| 112 | |
| 113 | b, err := createNewBufferWithData(data, false) |
| 114 | if err != nil { |
| 115 | t.Fatalf("Failed to create buffer: %v", err) |
| 116 | } |
| 117 | |
| 118 | b.rowFreeze = 1 |
| 119 | |
| 120 | // Enable string interning |
| 121 | b.enableStringInterning() |
| 122 | |
| 123 | // Check that interning is enabled |
| 124 | stats := b.getInterningStats() |
| 125 | if !stats["enabled"].(bool) { |
| 126 | t.Error("String interning should be enabled") |
| 127 | } |
| 128 | |
| 129 | // Category column (0) should be interned (low cardinality) |
| 130 | if !b.internCols[0] { |
| 131 | t.Error("Category column should be interned") |
| 132 | } |
| 133 | |
| 134 | // Value column (1) should NOT be interned (high cardinality) |
| 135 | if b.internCols[1] { |
| 136 | t.Error("Value column should not be interned") |
| 137 | } |
| 138 | |
| 139 | t.Logf("Interning stats: %+v", stats) |
| 140 | } |
| 141 | |
| 142 | func TestStringInterningMemorySavings(t *testing.T) { |
| 143 | // Create large dataset with repeated values |
nothing calls this directly
no test coverage detected