diff --git a/pkg/col/coldata/vec.go b/pkg/col/coldata/vec.go index 5d4437778f7a..46b2831c5c1e 100644 --- a/pkg/col/coldata/vec.go +++ b/pkg/col/coldata/vec.go @@ -12,6 +12,7 @@ package coldata import ( "fmt" + "time" "github.com/cockroachdb/apd" "github.com/cockroachdb/cockroach/pkg/col/coltypes" @@ -93,6 +94,8 @@ type Vec interface { // TODO(jordan): should this be [][]byte? // Decimal returns an apd.Decimal slice. Decimal() []apd.Decimal + // Timestamp returns a time.Time slice. + Timestamp() []time.Time // Col returns the raw, typeless backing storage for this Vec. Col() interface{} @@ -172,6 +175,8 @@ func NewMemColumn(t coltypes.T, n int) Vec { return &memColumn{t: t, col: make([]float64, n), nulls: nulls} case coltypes.Decimal: return &memColumn{t: t, col: make([]apd.Decimal, n), nulls: nulls} + case coltypes.Timestamp: + return &memColumn{t: t, col: make([]time.Time, n), nulls: nulls} default: panic(fmt.Sprintf("unhandled type %s", t)) } @@ -221,6 +226,10 @@ func (m *memColumn) Decimal() []apd.Decimal { return m.col.([]apd.Decimal) } +func (m *memColumn) Timestamp() []time.Time { + return m.col.([]time.Time) +} + func (m *memColumn) Col() interface{} { return m.col } diff --git a/pkg/col/coldata/vec_tmpl.go b/pkg/col/coldata/vec_tmpl.go index cd113382438d..bd0bb684a643 100644 --- a/pkg/col/coldata/vec_tmpl.go +++ b/pkg/col/coldata/vec_tmpl.go @@ -21,6 +21,7 @@ package coldata import ( "fmt" + "time" "github.com/cockroachdb/apd" "github.com/cockroachdb/cockroach/pkg/col/coltypes" @@ -45,6 +46,9 @@ type _GOTYPESLICE interface{} // Dummy import to pull in "apd" package. var _ apd.Decimal +// Dummy import to pull in "time" package. +var _ time.Time + // */}} func (m *memColumn) Append(args AppendArgs) { diff --git a/pkg/col/colserde/arrowbatchconverter_test.go b/pkg/col/colserde/arrowbatchconverter_test.go index e3440f8e225b..ba812c9bb00e 100644 --- a/pkg/col/colserde/arrowbatchconverter_test.go +++ b/pkg/col/colserde/arrowbatchconverter_test.go @@ -30,8 +30,8 @@ func randomBatch() ([]coltypes.T, coldata.Batch) { availableTyps := make([]coltypes.T, 0, len(coltypes.AllTypes)) for _, typ := range coltypes.AllTypes { - // TODO(asubiotto): We do not support decimal conversion yet. - if typ == coltypes.Decimal { + // TODO(asubiotto,jordan): We do not support decimal, timestamp conversion yet. + if typ == coltypes.Decimal || typ == coltypes.Timestamp { continue } availableTyps = append(availableTyps, typ) @@ -117,7 +117,7 @@ func assertEqualBatches(t *testing.T, expected, actual coldata.Batch) { func TestArrowBatchConverterRejectsUnsupportedTypes(t *testing.T) { defer leaktest.AfterTest(t)() - typs := []coltypes.T{coltypes.Decimal} + typs := []coltypes.T{coltypes.Decimal, coltypes.Timestamp} _, err := NewArrowBatchConverter(typs) require.Error(t, err) } diff --git a/pkg/col/colserde/record_batch_test.go b/pkg/col/colserde/record_batch_test.go index 2916b84c2cbd..5b7ee2b4d50f 100644 --- a/pkg/col/colserde/record_batch_test.go +++ b/pkg/col/colserde/record_batch_test.go @@ -194,9 +194,9 @@ func TestRecordBatchSerializerSerializeDeserializeRandom(t *testing.T) { buf = bytes.Buffer{} ) - // We do not support decimals yet. + // We do not support decimals or timestamps yet. for _, t := range coltypes.AllTypes { - if t == coltypes.Decimal { + if t == coltypes.Decimal || t == coltypes.Timestamp { continue } supportedTypes = append(supportedTypes, t) diff --git a/pkg/col/coltypes/t_string.go b/pkg/col/coltypes/t_string.go index f0aeef44d59b..46b7f30f7253 100644 --- a/pkg/col/coltypes/t_string.go +++ b/pkg/col/coltypes/t_string.go @@ -17,12 +17,13 @@ func _() { _ = x[Int64-6] _ = x[Float32-7] _ = x[Float64-8] - _ = x[Unhandled-9] + _ = x[Timestamp-9] + _ = x[Unhandled-10] } -const _T_name = "BoolBytesDecimalInt8Int16Int32Int64Float32Float64Unhandled" +const _T_name = "BoolBytesDecimalInt8Int16Int32Int64Float32Float64TimestampUnhandled" -var _T_index = [...]uint8{0, 4, 9, 16, 20, 25, 30, 35, 42, 49, 58} +var _T_index = [...]uint8{0, 4, 9, 16, 20, 25, 30, 35, 42, 49, 58, 67} func (i T) String() string { if i < 0 || i >= T(len(_T_index)-1) { diff --git a/pkg/col/coltypes/types.go b/pkg/col/coltypes/types.go index fc7fb72503d1..5a7e1cc41e74 100644 --- a/pkg/col/coltypes/types.go +++ b/pkg/col/coltypes/types.go @@ -12,6 +12,7 @@ package coltypes import ( "fmt" + "time" "github.com/cockroachdb/apd" ) @@ -40,6 +41,8 @@ const ( Float32 // Float64 is a column of type float64 Float64 + // Timestamp is a column of type time.Time + Timestamp // Unhandled is a temporary value that represents an unhandled type. // TODO(jordan): this should be replaced by a panic once all types are @@ -78,6 +81,7 @@ func init() { CompatibleTypes[Int64] = append(CompatibleTypes[Int64], NumberTypes...) CompatibleTypes[Float32] = append(CompatibleTypes[Float32], NumberTypes...) CompatibleTypes[Float64] = append(CompatibleTypes[Float64], NumberTypes...) + CompatibleTypes[Timestamp] = append(CompatibleTypes[Timestamp], Timestamp) } // FromGoType returns the type for a Go value, if applicable. Shouldn't be used at @@ -104,6 +108,8 @@ func FromGoType(v interface{}) T { return Bytes case apd.Decimal: return Decimal + case time.Time: + return Timestamp default: panic(fmt.Sprintf("type %T not supported yet", t)) } @@ -130,6 +136,8 @@ func (t T) GoTypeName() string { return "float32" case Float64: return "float64" + case Timestamp: + return "time.Time" default: panic(fmt.Sprintf("unhandled type %d", t)) } diff --git a/pkg/sql/colencoding/key_encoding.go b/pkg/sql/colencoding/key_encoding.go index 39367652440d..4b777fc19874 100644 --- a/pkg/sql/colencoding/key_encoding.go +++ b/pkg/sql/colencoding/key_encoding.go @@ -11,6 +11,8 @@ package colencoding import ( + "time" + "github.com/cockroachdb/apd" "github.com/cockroachdb/cockroach/pkg/col/coldata" "github.com/cockroachdb/cockroach/pkg/roachpb" @@ -227,6 +229,14 @@ func decodeTableKeyToCol( rkey, t, err = encoding.DecodeVarintDescending(key) } vec.Int64()[idx] = t + case types.TimestampFamily: + var t time.Time + if dir == sqlbase.IndexDescriptor_ASC { + rkey, t, err = encoding.DecodeTimeAscending(key) + } else { + rkey, t, err = encoding.DecodeTimeDescending(key) + } + vec.Timestamp()[idx] = t default: return rkey, errors.AssertionFailedf("unsupported type %+v", log.Safe(valType)) } diff --git a/pkg/sql/colencoding/value_encoding.go b/pkg/sql/colencoding/value_encoding.go index 1a3e9e6e0045..8d9449ba254d 100644 --- a/pkg/sql/colencoding/value_encoding.go +++ b/pkg/sql/colencoding/value_encoding.go @@ -11,6 +11,8 @@ package colencoding import ( + "time" + "github.com/cockroachdb/cockroach/pkg/col/coldata" "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/cockroach/pkg/util/encoding" @@ -84,6 +86,10 @@ func decodeUntaggedDatumToCol(vec coldata.Vec, idx uint16, t *types.T, buf []byt // We map these to 64-bit INT now. See #34161. vec.Int64()[idx] = i } + case types.TimestampFamily: + var t time.Time + buf, t, err = encoding.DecodeUntaggedTimeValue(buf) + vec.Timestamp()[idx] = t default: return buf, errors.AssertionFailedf( "couldn't decode type: %s", log.Safe(t)) diff --git a/pkg/sql/exec/any_not_null_agg_tmpl.go b/pkg/sql/exec/any_not_null_agg_tmpl.go index 95c900d23e9b..40e71b288c83 100644 --- a/pkg/sql/exec/any_not_null_agg_tmpl.go +++ b/pkg/sql/exec/any_not_null_agg_tmpl.go @@ -20,6 +20,8 @@ package exec import ( + "time" + "github.com/cockroachdb/apd" "github.com/cockroachdb/cockroach/pkg/col/coldata" "github.com/cockroachdb/cockroach/pkg/col/coltypes" @@ -45,6 +47,9 @@ func newAnyNotNullAgg(t coltypes.T) (aggregateFunc, error) { // Dummy import to pull in "apd" package. var _ apd.Decimal +// Dummy import to pull in "time" package. +var _ time.Time + // _GOTYPESLICE is the template Go type slice variable for this operator. It // will be replaced by the Go slice representation for each type in coltypes.T, for // example []int64 for coltypes.Int64. diff --git a/pkg/sql/exec/const_tmpl.go b/pkg/sql/exec/const_tmpl.go index 9d36986e4de8..7975a617c940 100644 --- a/pkg/sql/exec/const_tmpl.go +++ b/pkg/sql/exec/const_tmpl.go @@ -21,6 +21,7 @@ package exec import ( "context" + "time" "github.com/cockroachdb/apd" "github.com/cockroachdb/cockroach/pkg/col/coldata" @@ -36,6 +37,9 @@ import ( // Dummy import to pull in "apd" package. var _ apd.Decimal +// Dummy import to pull in "time" package. +var _ time.Time + // _TYPES_T is the template type variable for coltypes.T. It will be replaced by // coltypes.Foo for each type Foo in the coltypes.T type. const _TYPES_T = coltypes.Unhandled diff --git a/pkg/sql/exec/distinct_tmpl.go b/pkg/sql/exec/distinct_tmpl.go index 77b90068581e..1d58e3c18bb6 100644 --- a/pkg/sql/exec/distinct_tmpl.go +++ b/pkg/sql/exec/distinct_tmpl.go @@ -23,6 +23,7 @@ import ( "bytes" "context" "math" + "time" "github.com/cockroachdb/apd" "github.com/cockroachdb/cockroach/pkg/col/coldata" @@ -104,6 +105,9 @@ var _ bytes.Buffer // Dummy import to pull in "apd" package. var _ apd.Decimal +// Dummy import to pull in "time" package. +var _ time.Time + // Dummy import to pull in "tree" package. var _ tree.Datum diff --git a/pkg/sql/exec/execgen/cmd/execgen/overloads.go b/pkg/sql/exec/execgen/cmd/execgen/overloads.go index a7d57ec2ba05..34990fd31a40 100644 --- a/pkg/sql/exec/execgen/cmd/execgen/overloads.go +++ b/pkg/sql/exec/execgen/cmd/execgen/overloads.go @@ -583,6 +583,9 @@ type floatIntCustomizer struct{} // side and a float right-hand side. type intFloatCustomizer struct{} +// timestampCustomizer is necessary since time.Time doesn't have infix operators. +type timestampCustomizer struct{} + func (boolCustomizer) getCmpOpCompareFunc() compareFunc { return func(target, l, r string) string { args := map[string]string{"Target": target, "Left": l, "Right": r} @@ -1046,11 +1049,43 @@ func (c intFloatCustomizer) getCmpOpCompareFunc() compareFunc { return getFloatCmpOpCompareFunc(false /* checkLeftNan */, true /* checkRightNan */) } +func (c timestampCustomizer) getCmpOpCompareFunc() compareFunc { + return func(target, l, r string) string { + args := map[string]string{"Target": target, "Left": l, "Right": r} + buf := strings.Builder{} + // Inline the code from tree.compareTimestamps. + t := template.Must(template.New("").Parse(` + if {{.Left}}.Before({{.Right}}) { + {{.Target}} = -1 + } else if {{.Right}}.Before({{.Left}}) { + {{.Target}} = 1 + } else { + {{.Target}} = 0 + }`)) + + if err := t.Execute(&buf, args); err != nil { + execerror.VectorizedInternalPanic(err) + } + return buf.String() + } +} + +func (timestampCustomizer) getHashAssignFunc() assignFunc { + return func(op overload, target, v, _ string) string { + return fmt.Sprintf(` + s, ns := %[2]s.Second(), %[2]s.Nanosecond() + %[1]s = memhash64(noescape(unsafe.Pointer(&s)), %[1]s) + %[1]s = memhash64(noescape(unsafe.Pointer(&ns)), %[1]s) + `, target, v) + } +} + func registerTypeCustomizers() { typeCustomizers = make(map[coltypePair]typeCustomizer) registerTypeCustomizer(coltypePair{coltypes.Bool, coltypes.Bool}, boolCustomizer{}) registerTypeCustomizer(coltypePair{coltypes.Bytes, coltypes.Bytes}, bytesCustomizer{}) registerTypeCustomizer(coltypePair{coltypes.Decimal, coltypes.Decimal}, decimalCustomizer{}) + registerTypeCustomizer(coltypePair{coltypes.Timestamp, coltypes.Timestamp}, timestampCustomizer{}) for _, leftFloatType := range coltypes.FloatTypes { for _, rightFloatType := range coltypes.FloatTypes { registerTypeCustomizer(coltypePair{leftFloatType, rightFloatType}, floatCustomizer{width: 64}) diff --git a/pkg/sql/exec/execgen/cmd/execgen/overloads_test_utils_gen.go b/pkg/sql/exec/execgen/cmd/execgen/overloads_test_utils_gen.go index 2ac3081ec669..958a27a7d2a7 100644 --- a/pkg/sql/exec/execgen/cmd/execgen/overloads_test_utils_gen.go +++ b/pkg/sql/exec/execgen/cmd/execgen/overloads_test_utils_gen.go @@ -23,6 +23,7 @@ import ( "math" "github.com/cockroachdb/apd" + "time" "github.com/cockroachdb/cockroach/pkg/sql/exec/execerror" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" ) diff --git a/pkg/sql/exec/execgen/cmd/execgen/projection_ops_gen.go b/pkg/sql/exec/execgen/cmd/execgen/projection_ops_gen.go index 439e89cb4a52..c0f474c2fa26 100644 --- a/pkg/sql/exec/execgen/cmd/execgen/projection_ops_gen.go +++ b/pkg/sql/exec/execgen/cmd/execgen/projection_ops_gen.go @@ -21,9 +21,10 @@ const projTemplate = ` package exec import ( - "bytes" + "bytes" "context" "math" + "time" "github.com/cockroachdb/apd" "github.com/cockroachdb/cockroach/pkg/col/coldata" diff --git a/pkg/sql/exec/execgen/cmd/execgen/selection_ops_gen.go b/pkg/sql/exec/execgen/cmd/execgen/selection_ops_gen.go index 258be71af554..5608c6284d32 100644 --- a/pkg/sql/exec/execgen/cmd/execgen/selection_ops_gen.go +++ b/pkg/sql/exec/execgen/cmd/execgen/selection_ops_gen.go @@ -21,9 +21,10 @@ const selTemplate = ` package exec import ( - "bytes" + "bytes" "context" "math" + "time" "github.com/cockroachdb/apd" "github.com/cockroachdb/cockroach/pkg/col/coldata" diff --git a/pkg/sql/exec/mem_estimation.go b/pkg/sql/exec/mem_estimation.go index 1ff99f8befbe..f6d8cca65a45 100644 --- a/pkg/sql/exec/mem_estimation.go +++ b/pkg/sql/exec/mem_estimation.go @@ -61,6 +61,9 @@ func EstimateBatchSizeBytes(vecTypes []coltypes.T, batchLength int) int { // Similar to byte arrays, we can't tell how much space is used // to hold the arbitrary precision decimal objects. acc += 50 + case coltypes.Timestamp: + // time.Time has 2 int64s and a pointer. + acc += sizeOfInt64 * 3 default: execerror.VectorizedInternalPanic(fmt.Sprintf("unhandled type %s", t)) } diff --git a/pkg/sql/exec/mergejoinbase_tmpl.go b/pkg/sql/exec/mergejoinbase_tmpl.go index 90e70e833a80..7229c517c95b 100644 --- a/pkg/sql/exec/mergejoinbase_tmpl.go +++ b/pkg/sql/exec/mergejoinbase_tmpl.go @@ -23,6 +23,7 @@ import ( "bytes" "fmt" "math" + "time" "github.com/cockroachdb/apd" "github.com/cockroachdb/cockroach/pkg/col/coldata" @@ -44,6 +45,9 @@ var _ tree.Datum // Dummy import to pull in "apd" package. var _ apd.Decimal +// Dummy import to pull in "time" package. +var _ time.Time + // Dummy import to pull in "math" package. var _ = math.MaxInt64 diff --git a/pkg/sql/exec/mergejoiner_tmpl.go b/pkg/sql/exec/mergejoiner_tmpl.go index e85e21babfad..2233e4ddbcec 100644 --- a/pkg/sql/exec/mergejoiner_tmpl.go +++ b/pkg/sql/exec/mergejoiner_tmpl.go @@ -24,6 +24,7 @@ import ( "context" "fmt" "math" + "time" "github.com/cockroachdb/apd" "github.com/cockroachdb/cockroach/pkg/col/coldata" @@ -46,6 +47,9 @@ var _ tree.Datum // Dummy import to pull in "apd" package. var _ apd.Decimal +// Dummy import to pull in "time" package. +var _ time.Time + // Dummy import to pull in "math" package. var _ = math.MaxInt64 diff --git a/pkg/sql/exec/min_max_agg_tmpl.go b/pkg/sql/exec/min_max_agg_tmpl.go index 8edb72ad3a42..0a63ce39a921 100644 --- a/pkg/sql/exec/min_max_agg_tmpl.go +++ b/pkg/sql/exec/min_max_agg_tmpl.go @@ -22,6 +22,7 @@ package exec import ( "bytes" "math" + "time" "github.com/cockroachdb/apd" "github.com/cockroachdb/cockroach/pkg/col/coldata" @@ -43,6 +44,9 @@ var _ bytes.Buffer // Dummy import to pull in "apd" package. var _ apd.Decimal +// Dummy import to pull in "time" package. +var _ time.Time + // Dummy import to pull in "tree" package. var _ tree.Datum diff --git a/pkg/sql/exec/random_testutils.go b/pkg/sql/exec/random_testutils.go index b68fd87241dd..da377f33ee7f 100644 --- a/pkg/sql/exec/random_testutils.go +++ b/pkg/sql/exec/random_testutils.go @@ -18,6 +18,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/col/coldata" "github.com/cockroachdb/cockroach/pkg/col/coltypes" "github.com/cockroachdb/cockroach/pkg/sql/exec/execerror" + "github.com/cockroachdb/cockroach/pkg/util/timeutil" ) // maxVarLen specifies a length limit for variable length types (e.g. byte slices). @@ -94,6 +95,11 @@ func RandomVec(rng *rand.Rand, typ coltypes.T, vec coldata.Vec, n int, nullProba for i := 0; i < n; i++ { floats[i] = rng.Float64() } + case coltypes.Timestamp: + timestamps := vec.Timestamp() + for i := 0; i < n; i++ { + timestamps[i] = timeutil.Unix(rng.Int63n(1000000), rng.Int63n(1000000)) + } default: execerror.VectorizedInternalPanic(fmt.Sprintf("unhandled type %s", typ)) } diff --git a/pkg/sql/exec/rowstovec_tmpl.go b/pkg/sql/exec/rowstovec_tmpl.go index da8555931e16..904760fa723c 100644 --- a/pkg/sql/exec/rowstovec_tmpl.go +++ b/pkg/sql/exec/rowstovec_tmpl.go @@ -21,6 +21,7 @@ package exec import ( "fmt" + "time" "github.com/cockroachdb/apd" "github.com/cockroachdb/cockroach/pkg/col/coldata" @@ -37,6 +38,9 @@ import ( // Dummy import to pull in "apd" package. var _ apd.Decimal +// Dummy import to pull in "time" package. +var _ time.Time + const ( _FAMILY = types.Family(0) _WIDTH = int32(0) diff --git a/pkg/sql/exec/select_in_tmpl.go b/pkg/sql/exec/select_in_tmpl.go index e1b5b5c94dbf..eae7e97ebf7b 100644 --- a/pkg/sql/exec/select_in_tmpl.go +++ b/pkg/sql/exec/select_in_tmpl.go @@ -23,6 +23,7 @@ import ( "bytes" "context" "math" + "time" "github.com/cockroachdb/apd" "github.com/cockroachdb/cockroach/pkg/col/coldata" @@ -45,6 +46,9 @@ type _TYPE interface{} // Dummy import to pull in "apd" package. var _ apd.Decimal +// Dummy import to pull in "time" package. +var _ time.Time + // Dummy import to pull in "coltypes" package var _ coltypes.T diff --git a/pkg/sql/exec/sort_tmpl.go b/pkg/sql/exec/sort_tmpl.go index 43f48c84b2ab..1f2e64edfb44 100644 --- a/pkg/sql/exec/sort_tmpl.go +++ b/pkg/sql/exec/sort_tmpl.go @@ -24,6 +24,7 @@ import ( "context" "fmt" "math" + "time" "github.com/cockroachdb/apd" "github.com/cockroachdb/cockroach/pkg/col/coldata" @@ -44,6 +45,9 @@ var _ bytes.Buffer // Dummy import to pull in "apd" package. var _ apd.Decimal +// Dummy import to pull in "time" package. +var _ time.Time + // Dummy import to pull in "tree" package. var _ tree.Datum diff --git a/pkg/sql/exec/typeconv/typeconv.go b/pkg/sql/exec/typeconv/typeconv.go index 9fec57042842..703ab8c5dee5 100644 --- a/pkg/sql/exec/typeconv/typeconv.go +++ b/pkg/sql/exec/typeconv/typeconv.go @@ -47,6 +47,8 @@ func FromColumnType(ct *types.T) coltypes.T { execerror.VectorizedInternalPanic(fmt.Sprintf("integer with unknown width %d", ct.Width())) case types.FloatFamily: return coltypes.Float64 + case types.TimestampFamily: + return coltypes.Timestamp } return coltypes.Unhandled } @@ -166,6 +168,14 @@ func GetDatumToPhysicalFn(ct *types.T) func(tree.Datum) (interface{}, error) { } return d.Decimal, nil } + case types.TimestampFamily: + return func(datum tree.Datum) (interface{}, error) { + d, ok := datum.(*tree.DTimestamp) + if !ok { + return nil, errors.Errorf("expected *tree.DTimestamp, found %s", reflect.TypeOf(datum)) + } + return d.Time, nil + } } // It would probably be more correct to return an error here, rather than a // function which always returns an error. But since the function tends to be diff --git a/pkg/sql/exec/vec_comparators_tmpl.go b/pkg/sql/exec/vec_comparators_tmpl.go index b94abc1d860d..d5e2d0b630bb 100644 --- a/pkg/sql/exec/vec_comparators_tmpl.go +++ b/pkg/sql/exec/vec_comparators_tmpl.go @@ -23,6 +23,7 @@ import ( "bytes" "fmt" "math" + "time" "github.com/cockroachdb/apd" "github.com/cockroachdb/cockroach/pkg/col/coldata" @@ -42,6 +43,9 @@ var _ bytes.Buffer // Dummy import to pull in "apd" package. var _ apd.Decimal +// Dummy import to pull in "time" package. +var _ time.Time + // Dummy import to pull in "tree" package. var _ tree.Datum diff --git a/pkg/sql/exec/zerocolumns_tmpl.go b/pkg/sql/exec/zerocolumns_tmpl.go index 67733aa30bc7..73878b1b3456 100644 --- a/pkg/sql/exec/zerocolumns_tmpl.go +++ b/pkg/sql/exec/zerocolumns_tmpl.go @@ -20,6 +20,8 @@ package exec import ( + "time" + "github.com/cockroachdb/apd" "github.com/cockroachdb/cockroach/pkg/col/coldata" ) @@ -30,6 +32,9 @@ import ( // Dummy import to pull in "apd" package. var _ apd.Decimal +// Dummy import to pull in "time" package. +var _ time.Time + // */}} // {{range .}} diff --git a/pkg/sql/sqlbase/testutils.go b/pkg/sql/sqlbase/testutils.go index 7af7e2f4db94..8f181b19d3d3 100644 --- a/pkg/sql/sqlbase/testutils.go +++ b/pkg/sql/sqlbase/testutils.go @@ -159,7 +159,7 @@ func RandDatumWithNullChance(rng *rand.Rand, typ *types.T, nullChance int) tree. case types.TimeFamily: return tree.MakeDTime(timeofday.Random(rng)) case types.TimestampFamily: - return &tree.DTimestamp{Time: timeutil.Unix(rng.Int63n(1000000), rng.Int63n(1000000))} + return tree.MakeDTimestamp(timeutil.Unix(rng.Int63n(1000000), rng.Int63n(1000000)), time.Microsecond) case types.IntervalFamily: sign := 1 - rng.Int63n(2)*2 return &tree.DInterval{Duration: duration.MakeDuration(