MCPcopy Create free account
hub / github.com/dolthub/doltgresql / Update

Method Update

server/expression/array_agg.go:195–235  ·  view source on GitHub ↗

Update implements sql.AggregationBuffer

(ctx *sql.Context, row sql.Row)

Source from the content-addressed store, hash-verified

193
194// Update implements sql.AggregationBuffer
195func (a *arrayAggBuffer) Update(ctx *sql.Context, row sql.Row) error {
196 evalRow, err := evalExprs(ctx, a.a.selectExprs, row)
197 if err != nil {
198 return err
199 }
200
201 if a.a.Distinct {
202 val := evalRow[0]
203 if val == nil {
204 if a.seenNull {
205 return nil
206 }
207 a.seenNull = true
208 } else {
209 exprType := a.a.selectExprs[0].Type(ctx).(*types.DoltgresType)
210 lo, hi := 0, len(a.seen)
211 for lo < hi {
212 mid := (lo + hi) / 2
213 cmp, err := exprType.Compare(ctx, val, a.seen[mid])
214 if err != nil {
215 return err
216 }
217 if cmp == 0 {
218 return nil
219 } else if cmp < 0 {
220 hi = mid
221 } else {
222 lo = mid + 1
223 }
224 }
225 a.seen = append(a.seen, nil)
226 copy(a.seen[lo+1:], a.seen[lo:])
227 a.seen[lo] = val
228 }
229 }
230
231 // Append the current value to the end of the row. We want to preserve the row's original structure
232 // for sort ordering in the final step.
233 a.elements = append(a.elements, append(row, evalRow[0]))
234 return nil
235}
236
237// evalExprs evaluates the provided expressions against the given row and returns the results as a new row.
238func evalExprs(ctx *sql.Context, exprs []sql.Expression, row sql.Row) (sql.Row, error) {

Callers 4

EditTablesMapMethod · 0.45
writeCacheMethod · 0.45
writeCacheMethod · 0.45
getDmlResultFunction · 0.45

Calls 3

evalExprsFunction · 0.85
TypeMethod · 0.65
CompareMethod · 0.65

Tested by 1

getDmlResultFunction · 0.36