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

Function SampleDatum

pkg/sql/sem/tree/testutils.go:37–85  ·  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

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

Callers

nothing calls this directly

Calls 15

FromIntFunction · 0.92
UnixFunction · 0.92
NewDBitArrayFromIntFunction · 0.85
MakeDBoolFunction · 0.85
NewDIntFunction · 0.85
DFloatTypeAlias · 0.85
NewDStringFunction · 0.85
NewDBytesFunction · 0.85
NewDDateFunction · 0.85
MakeDTimeFunction · 0.85
NewDTimeTZFromOffsetFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…