Append appends a Datum to the array, whose parameterized type must be consistent with the type of the Datum.
(v Datum)
| 5204 | // Append appends a Datum to the array, whose parameterized type must be |
| 5205 | // consistent with the type of the Datum. |
| 5206 | func (d *DArray) Append(v Datum) error { |
| 5207 | // v.ResolvedType() must be the left-hand side because EquivalentOrNull |
| 5208 | // only allows null tuple elements on the left-hand side. |
| 5209 | if !v.ResolvedType().EquivalentOrNull(d.ParamTyp, true /* allowNullTupleEquivalence */) { |
| 5210 | return errors.AssertionFailedf( |
| 5211 | "cannot append %s to array containing %s", |
| 5212 | v.ResolvedType().SQLStringForError(), d.ParamTyp.SQLStringForError(), |
| 5213 | ) |
| 5214 | } |
| 5215 | if d.Len() >= maxArrayLength { |
| 5216 | return errors.WithStack(errArrayTooLongError) |
| 5217 | } |
| 5218 | if d.ParamTyp.Family() == types.ArrayFamily { |
| 5219 | if v == DNull { |
| 5220 | return errNonHomogeneousArray |
| 5221 | } |
| 5222 | if d.Len() > 0 { |
| 5223 | prevItem := d.Array[d.Len()-1] |
| 5224 | if prevItem == DNull { |
| 5225 | return errNonHomogeneousArray |
| 5226 | } |
| 5227 | expectedLen := MustBeDArray(prevItem).Len() |
| 5228 | if MustBeDArray(v).Len() != expectedLen { |
| 5229 | return errNonHomogeneousArray |
| 5230 | } |
| 5231 | } |
| 5232 | } |
| 5233 | if v == DNull { |
| 5234 | d.HasNulls = true |
| 5235 | } else { |
| 5236 | d.HasNonNulls = true |
| 5237 | } |
| 5238 | d.Array = append(d.Array, v) |
| 5239 | return d.Validate() |
| 5240 | } |
| 5241 | |
| 5242 | // DVoid represents a void type. |
| 5243 | type DVoid struct{} |
no test coverage detected