NewMemBatchWithCapacity allocates a new in-memory Batch with the given column size. Use for operators that have a precisely-sized output batch.
(typs []*types.T, capacity int, factory ColumnFactory)
| 214 | // NewMemBatchWithCapacity allocates a new in-memory Batch with the given |
| 215 | // column size. Use for operators that have a precisely-sized output batch. |
| 216 | func NewMemBatchWithCapacity(typs []*types.T, capacity int, factory ColumnFactory) Batch { |
| 217 | b := NewMemBatchNoCols(typs, capacity).(*MemBatch) |
| 218 | vecs := make([]Vec, len(typs)) |
| 219 | // numForCanonicalType will track how many times a particular canonical type |
| 220 | // family appears in typs. |
| 221 | // |
| 222 | //gcassert:noescape |
| 223 | var numForCanonicalType [numCanonicalTypes]int |
| 224 | for i, t := range typs { |
| 225 | vecs[i].t = t |
| 226 | vecs[i].canonicalTypeFamily = typeconv.TypeFamilyToCanonicalTypeFamily(t.Family()) |
| 227 | b.b[i] = &vecs[i] |
| 228 | allocIdx := toAllocIdx(vecs[i].canonicalTypeFamily, vecs[i].t.Width()) |
| 229 | numForCanonicalType[allocIdx]++ |
| 230 | } |
| 231 | var maxSame int |
| 232 | for _, numColumns := range numForCanonicalType { |
| 233 | maxSame = max(maxSame, numColumns) |
| 234 | } |
| 235 | // First, initialize columns that can be batch-allocated together for the |
| 236 | // same canonical type. |
| 237 | if maxSame > 1 { |
| 238 | scratchColumns := make([]Column, maxSame) |
| 239 | for allocIdx, numColumns := range numForCanonicalType { |
| 240 | if numColumns > 1 { |
| 241 | scratch := scratchColumns[:numColumns] |
| 242 | t := toCanonicalType(allocIdx) |
| 243 | factory.MakeColumns(scratch, t, capacity) |
| 244 | for i := range vecs { |
| 245 | if toAllocIdx(vecs[i].canonicalTypeFamily, vecs[i].t.Width()) == allocIdx { |
| 246 | vecs[i].col = scratch[0] |
| 247 | scratch = scratch[1:] |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | if numForCanonicalType[datumAllocIdx] > 1 { |
| 253 | // We need to set the correct type on each datum-backed vector. |
| 254 | for i := range vecs { |
| 255 | if vecs[i].canonicalTypeFamily == typeconv.DatumVecCanonicalTypeFamily { |
| 256 | vecs[i].Datum().SetType(vecs[i].t) |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | // Initialize all remaining columns while also initializing all Nulls |
| 262 | // bitmaps. |
| 263 | nullsCap := nullsStorageCap(capacity) |
| 264 | nullsAlloc := make([]byte, len(typs)*nullsCap) |
| 265 | for i := range vecs { |
| 266 | if vecs[i].col == nil { |
| 267 | vecs[i].col = factory.MakeColumn(vecs[i].t, capacity) |
| 268 | } |
| 269 | vecs[i].nulls = newNulls(nullsAlloc[:nullsCap:nullsCap]) |
| 270 | nullsAlloc = nullsAlloc[nullsCap:] |
| 271 | } |
| 272 | return b |
| 273 | } |
no test coverage detected
searching dependent graphs…