MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / Append

Method Append

pkg/sql/sem/tree/datum.go:5206–5240  ·  view source on GitHub ↗

Append appends a Datum to the array, whose parameterized type must be consistent with the type of the Datum.

(v Datum)

Source from the content-addressed store, hash-verified

5204// Append appends a Datum to the array, whose parameterized type must be
5205// consistent with the type of the Datum.
5206func (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.
5243type DVoid struct{}

Callers 4

AppendToMaybeNullArrayFunction · 0.95
PrependToMaybeNullArrayFunction · 0.95
ConcatArraysFunction · 0.95
parseElementMethod · 0.45

Calls 8

LenMethod · 0.95
ValidateMethod · 0.95
MustBeDArrayFunction · 0.85
EquivalentOrNullMethod · 0.80
SQLStringForErrorMethod · 0.80
FamilyMethod · 0.80
ResolvedTypeMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected