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

Function SampleDatum

pkg/sql/sem/tree/testutils.go:34–93  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

32// SampleDatum is intended to be a more lightweight version of RandDatum for
33// when you just need one consistent example of a datum.
34func SampleDatum(t *types.T) Datum {
35 switch t.Family() {
36 case types.BitFamily:
37 a, _ := NewDBitArrayFromInt(123, 40)
38 return a
39 case types.BoolFamily:
40 return MakeDBool(true)
41 case types.IntFamily:
42 return NewDInt(123)
43 case types.FloatFamily:
44 f := DFloat(123.456)
45 return &f
46 case types.DecimalFamily:
47 d := &DDecimal{}
48 // int64(rng.Uint64()) to get negative numbers, too
49 d.Decimal.SetFinite(3, 6)
50 return d
51 case types.StringFamily:
52 return NewDString("Carl")
53 case types.BytesFamily:
54 return NewDBytes("Princess")
55 case types.DateFamily:
56 return NewDDate(pgdate.MakeCompatibleDateFromDisk(123123))
57 case types.TimeFamily:
58 return MakeDTime(timeofday.FromInt(789))
59 case types.TimeTZFamily:
60 return NewDTimeTZFromOffset(timeofday.FromInt(345), 5*60*60 /* OffsetSecs */)
61 case types.TimestampFamily:
62 return MustMakeDTimestamp(timeutil.Unix(123, 123), time.Second)
63 case types.TimestampTZFamily:
64 return MustMakeDTimestampTZ(timeutil.Unix(123, 123), time.Second)
65 case types.IntervalFamily:
66 i, _ := ParseDInterval(duration.IntervalStyle_POSTGRES, "1h1m1s")
67 return i
68 case types.UuidFamily:
69 u, _ := ParseDUuidFromString("3189ad07-52f2-4d60-83e8-4a8347fef718")
70 return u
71 case types.INetFamily:
72 i, _ := ParseDIPAddrFromINetString("127.0.0.1")
73 return i
74 case types.JsonFamily:
75 j, _ := ParseDJSON(`{"a": "b"}`)
76 return j
77 case types.OidFamily:
78 return NewDOidWithType(1009, t)
79 case types.PGLSNFamily:
80 return NewDPGLSN(0x1000000100)
81 case types.RefCursorFamily:
82 return NewDRefCursor("Wheezer")
83 case types.Box2DFamily:
84 b := geo.NewCartesianBoundingBox().AddPoint(1, 2).AddPoint(3, 4)
85 return NewDBox2D(*b)
86 case types.GeographyFamily:
87 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")))
88 case types.GeometryFamily:
89 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")))
90 default:
91 panic(errors.AssertionFailedf("SampleDatum not implemented for %s", t))

Callers

nothing calls this directly

Calls 15

FromIntFunction · 0.92
UnixFunction · 0.92
NewCartesianBoundingBoxFunction · 0.92
NewDBitArrayFromIntFunction · 0.85
MakeDBoolFunction · 0.85
NewDIntFunction · 0.85
DFloatTypeAlias · 0.85
NewDStringFunction · 0.85
NewDBytesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…