Append appends a Datum to the array, whose parameterized type must be consistent with the type of the Datum.
(v Datum)
| 1752 | // Append appends a Datum to the array, whose parameterized type must be |
| 1753 | // consistent with the type of the Datum. |
| 1754 | func (d *DArray) Append(v Datum) error { |
| 1755 | if v != DNull && !d.ParamTyp.Equivalent(v.ResolvedType()) { |
| 1756 | return errors.AssertionFailedf("cannot append %s to array containing %s", d.ParamTyp, |
| 1757 | v.ResolvedType()) |
| 1758 | } |
| 1759 | if d.Len() >= maxArrayLength { |
| 1760 | return errors.WithStack(errArrayTooLongError) |
| 1761 | } |
| 1762 | if d.ParamTyp.Family() == types.ArrayFamily { |
| 1763 | if v == DNull { |
| 1764 | return errNonHomogeneousArray |
| 1765 | } |
| 1766 | if d.Len() > 0 { |
| 1767 | prevItem := d.Array[d.Len()-1] |
| 1768 | if prevItem == DNull { |
| 1769 | return errNonHomogeneousArray |
| 1770 | } |
| 1771 | expectedLen := MustBeDArray(prevItem).Len() |
| 1772 | if MustBeDArray(v).Len() != expectedLen { |
| 1773 | return errNonHomogeneousArray |
| 1774 | } |
| 1775 | } |
| 1776 | } |
| 1777 | if v == DNull { |
| 1778 | d.HasNulls = true |
| 1779 | } else { |
| 1780 | d.HasNonNulls = true |
| 1781 | } |
| 1782 | d.Array = append(d.Array, v) |
| 1783 | return d.Validate() |
| 1784 | } |
| 1785 | |
| 1786 | // DEnum represents an ENUM value. |
| 1787 | type DEnum struct { |
no test coverage detected