From 3e237af952b6d4d42cf1df0ab88373f73e6f8d33 Mon Sep 17 00:00:00 2001 From: Rohan Verma Date: Sun, 28 Sep 2025 01:56:09 +0530 Subject: [PATCH] Improve variable naming and documentation in writeResults function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename variables for clarity: - resCols → rowValues (holds actual data values) - resPointers → scanPointers (holds pointers for scanning) Update documentation to clearly explain the indirection pattern: sql.Rows.Scan() requires pointers to write into, but we need the actual values for WriteRow(). Solution: scanPointers holds pointers to each element in rowValues, allowing Scan() to write through the pointers while we use the actual values from rowValues. No functional changes - pure readability improvement. --- internal/core/core.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/internal/core/core.go b/internal/core/core.go index de0423c..f338632 100644 --- a/internal/core/core.go +++ b/internal/core/core.go @@ -543,21 +543,24 @@ func (co *Core) writeResults(jobID string, task Task, ttl time.Duration, rows *s return numRows, fmt.Errorf("error writing columns to result backend: %v", err) } - // Gymnastics to read arbitrary types from the row. + // Create indirection for scanning arbitrary column types. + // sql.Rows.Scan() requires pointers to write into, but we need the actual values for WriteRow(). + // Solution: scanPointers holds pointers to each element in rowValues, allowing Scan() to + // write through the pointers while we use the actual values from rowValues. var ( - resCols = make([]interface{}, numCols) - resPointers = make([]interface{}, numCols) + rowValues = make([]interface{}, numCols) + scanPointers = make([]interface{}, numCols) ) for i := 0; i < numCols; i++ { - resPointers[i] = &resCols[i] + scanPointers[i] = &rowValues[i] } // Scan each row and write to the results backend. for rows.Next() { - if err := rows.Scan(resPointers...); err != nil { + if err := rows.Scan(scanPointers...); err != nil { return numRows, err } - if err := w.WriteRow(resCols); err != nil { + if err := w.WriteRow(rowValues); err != nil { return numRows, fmt.Errorf("error writing row to result backend: %v", err) }