SampleDatum is intended to be a more lightweight version of RandDatum for when you just need one consistent example of a datum.
(t *types.T)
| 50 | // SampleDatum is intended to be a more lightweight version of RandDatum for |
| 51 | // when you just need one consistent example of a datum. |
| 52 | func SampleDatum(t *types.T) Datum { |
| 53 | switch t.Family() { |
| 54 | case types.BitFamily: |
| 55 | a, _ := NewDBitArrayFromInt(123, 40) |
| 56 | return a |
| 57 | case types.BoolFamily: |
| 58 | return MakeDBool(true) |
| 59 | case types.IntFamily: |
| 60 | return NewDInt(123) |
| 61 | case types.FloatFamily: |
| 62 | f := DFloat(123.456) |
| 63 | return &f |
| 64 | case types.DecimalFamily: |
| 65 | d := &DDecimal{} |
| 66 | // int64(rng.Uint64()) to get negative numbers, too |
| 67 | d.Decimal.SetFinite(3, 6) |
| 68 | return d |
| 69 | case types.StringFamily: |
| 70 | return NewDString("Carl") |
| 71 | case types.BytesFamily: |
| 72 | return NewDBytes("Princess") |
| 73 | case types.DateFamily: |
| 74 | return NewDDate(pgdate.MakeCompatibleDateFromDisk(123123)) |
| 75 | case types.TimeFamily: |
| 76 | return MakeDTime(timeofday.FromInt(789)) |
| 77 | case types.TimeTZFamily: |
| 78 | return NewDTimeTZFromOffset(timeofday.FromInt(345), 5*60*60 /* OffsetSecs */) |
| 79 | case types.TimestampFamily: |
| 80 | return MustMakeDTimestamp(time.Unix(123, 123).UTC(), time.Second) |
| 81 | case types.TimestampTZFamily: |
| 82 | return MustMakeDTimestampTZ(time.Unix(123, 123).UTC(), time.Second) |
| 83 | case types.IntervalFamily: |
| 84 | i, _ := ParseDInterval("1h1m1s") |
| 85 | return i |
| 86 | case types.UuidFamily: |
| 87 | u, _ := ParseDUuidFromString("3189ad07-52f2-4d60-83e8-4a8347fef718") |
| 88 | return u |
| 89 | case types.INetFamily: |
| 90 | i, _ := ParseDIPAddrFromINetString("127.0.0.1") |
| 91 | return i |
| 92 | case types.JsonFamily: |
| 93 | j, _ := ParseDJSON(`{"a": "b"}`) |
| 94 | return j |
| 95 | case types.OidFamily: |
| 96 | return NewDOid(DInt(1009)) |
| 97 | case types.Box2DFamily: |
| 98 | b := geo.NewCartesianBoundingBox().AddPoint(1, 2).AddPoint(3, 4) |
| 99 | return NewDBox2D(*b) |
| 100 | case types.GeographyFamily: |
| 101 | return NewDGeography(geo.MustParseGeographyFromEWKB([]byte("\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\x3f\x00\x00\x00\x00\x00\x00\xf0\x3f"))) |
| 102 | case types.GeometryFamily: |
| 103 | return NewDGeometry(geo.MustParseGeometryFromEWKB([]byte("\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\x3f\x00\x00\x00\x00\x00\x00\xf0\x3f"))) |
| 104 | default: |
| 105 | panic(errors.AssertionFailedf("SampleDatum not implemented for %s", t)) |
| 106 | } |
| 107 | } |
nothing calls this directly
no test coverage detected