TODO(justin): these might be improved by making arrays into an interface and then introducing a ConcatenatedArray implementation which just references two existing arrays. This would optimize the common case of appending an element (or array) to an array from O(n) to O(1).
()
| 247 | // existing arrays. This would optimize the common case of appending an element |
| 248 | // (or array) to an array from O(n) to O(1). |
| 249 | func initArrayElementConcatenation() { |
| 250 | for _, t := range types.Scalar { |
| 251 | typ := t |
| 252 | BinOps[Concat] = append(BinOps[Concat], &BinOp{ |
| 253 | LeftType: types.MakeArray(typ), |
| 254 | RightType: typ, |
| 255 | ReturnType: types.MakeArray(typ), |
| 256 | NullableArgs: true, |
| 257 | Fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) { |
| 258 | return AppendToMaybeNullArray(typ, left, right) |
| 259 | }, |
| 260 | }) |
| 261 | |
| 262 | BinOps[Concat] = append(BinOps[Concat], &BinOp{ |
| 263 | LeftType: typ, |
| 264 | RightType: types.MakeArray(typ), |
| 265 | ReturnType: types.MakeArray(typ), |
| 266 | NullableArgs: true, |
| 267 | Fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) { |
| 268 | return PrependToMaybeNullArray(typ, left, right) |
| 269 | }, |
| 270 | }) |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | // ConcatArrays concatenates two arrays. |
| 275 | func ConcatArrays(typ *types.T, left Datum, right Datum) (Datum, error) { |
no test coverage detected
searching dependent graphs…