@@ -79,7 +79,7 @@ func nullValueFromYDB(x *Ydb.Value, t types.Type) (_ Value, ok bool) {
7979 }
8080}
8181
82- //nolint:funlen
82+ //nolint:funlen,gocyclo
8383func primitiveValueFromYDB (t types.Primitive , v * Ydb.Value ) (Value , error ) {
8484 switch t {
8585 case types .Bool :
@@ -112,15 +112,24 @@ func primitiveValueFromYDB(t types.Primitive, v *Ydb.Value) (Value, error) {
112112 case types .Date :
113113 return DateValue (v .GetUint32Value ()), nil
114114
115+ case types .Date32 :
116+ return Date32Value (v .GetInt32Value ()), nil
117+
115118 case types .Datetime :
116119 return DatetimeValue (v .GetUint32Value ()), nil
117120
121+ case types .Datetime64 :
122+ return Datetime64Value (v .GetInt64Value ()), nil
123+
118124 case types .Interval :
119125 return IntervalValue (v .GetInt64Value ()), nil
120126
121127 case types .Timestamp :
122128 return TimestampValue (v .GetUint64Value ()), nil
123129
130+ case types .Timestamp64 :
131+ return Timestamp64Value (v .GetInt64Value ()), nil
132+
124133 case types .Float :
125134 return FloatValue (v .GetFloatValue ()), nil
126135
@@ -423,6 +432,66 @@ func DateValueFromTime(t time.Time) dateValue {
423432 return dateValue (uint64 (t .Sub (epoch )/ time .Second ) / secondsPerDay )
424433}
425434
435+ type date32Value int32
436+
437+ func (v date32Value ) castTo (dst any ) error {
438+ switch vv := dst .(type ) {
439+ case * time.Time :
440+ * vv = Date32ToTime (int32 (v )).UTC ()
441+
442+ return nil
443+ case * driver.Value :
444+ * vv = Date32ToTime (int32 (v )).UTC ()
445+
446+ return nil
447+ case * int64 :
448+ * vv = int64 (v )
449+
450+ return nil
451+ case * int32 :
452+ * vv = int32 (v )
453+
454+ return nil
455+ case * int :
456+ * vv = int (v )
457+
458+ return nil
459+ default :
460+ return xerrors .WithStackTrace (fmt .Errorf (
461+ "%w '%s(%+v)' to '%T' destination" ,
462+ ErrCannotCast , v .Type ().Yql (), v , vv ,
463+ ))
464+ }
465+ }
466+
467+ func (v date32Value ) Yql () string {
468+ return fmt .Sprintf ("%s(%q)" , v .Type ().Yql (), Date32ToTime (int32 (v )).UTC ().Format (LayoutDate ))
469+ }
470+
471+ func (date32Value ) Type () types.Type {
472+ return types .Date32
473+ }
474+
475+ func (v date32Value ) toYDB (a * allocator.Allocator ) * Ydb.Value {
476+ vv := a .Int32 ()
477+
478+ vv .Int32Value = int32 (v )
479+
480+ vvv := a .Value ()
481+ vvv .Value = vv
482+
483+ return vvv
484+ }
485+
486+ // Date32Value returns ydb date value by given days since Epoch
487+ func Date32Value (v int32 ) date32Value {
488+ return date32Value (v )
489+ }
490+
491+ func Date32ValueFromTime (t time.Time ) date32Value {
492+ return date32Value (uint64 (t .Unix () / 24 / 60 / 60 ))
493+ }
494+
426495type datetimeValue uint32
427496
428497func (v datetimeValue ) castTo (dst any ) error {
@@ -482,6 +551,57 @@ func DatetimeValueFromTime(t time.Time) datetimeValue {
482551 return datetimeValue (t .Unix ())
483552}
484553
554+ type datetime64Value int64
555+
556+ func (v datetime64Value ) castTo (dst any ) error {
557+ switch vv := dst .(type ) {
558+ case * time.Time :
559+ * vv = Datetime64ToTime (int64 (v ))
560+
561+ return nil
562+ case * driver.Value :
563+ * vv = Datetime64ToTime (int64 (v ))
564+
565+ return nil
566+ case * int64 :
567+ * vv = int64 (v )
568+
569+ return nil
570+ default :
571+ return xerrors .WithStackTrace (fmt .Errorf (
572+ "%w '%s(%+v)' to '%T' destination" ,
573+ ErrCannotCast , v .Type ().Yql (), v , vv ,
574+ ))
575+ }
576+ }
577+
578+ func (v datetime64Value ) Yql () string {
579+ return fmt .Sprintf ("%s(%q)" , v .Type ().Yql (), Datetime64ToTime (int64 (v )).UTC ().Format (LayoutDatetime ))
580+ }
581+
582+ func (datetime64Value ) Type () types.Type {
583+ return types .Datetime64
584+ }
585+
586+ func (v datetime64Value ) toYDB (a * allocator.Allocator ) * Ydb.Value {
587+ vv := a .Int64 ()
588+ vv .Int64Value = int64 (v )
589+
590+ vvv := a .Value ()
591+ vvv .Value = vv
592+
593+ return vvv
594+ }
595+
596+ // Datetime64Value makes ydb datetime value from seconds since Epoch
597+ func Datetime64Value (v int64 ) datetime64Value {
598+ return datetime64Value (v )
599+ }
600+
601+ func Datetime64ValueFromTime (t time.Time ) datetime64Value {
602+ return datetime64Value (t .Unix ())
603+ }
604+
485605var _ DecimalValuer = (* decimalValue )(nil )
486606
487607type decimalValue struct {
@@ -1757,6 +1877,57 @@ func TimestampValueFromTime(t time.Time) timestampValue {
17571877 return timestampValue (t .Sub (epoch ) / time .Microsecond )
17581878}
17591879
1880+ type timestamp64Value int64
1881+
1882+ func (v timestamp64Value ) castTo (dst any ) error {
1883+ switch vv := dst .(type ) {
1884+ case * time.Time :
1885+ * vv = Timestamp64ToTime (int64 (v ))
1886+
1887+ return nil
1888+ case * driver.Value :
1889+ * vv = Timestamp64ToTime (int64 (v ))
1890+
1891+ return nil
1892+ case * int64 :
1893+ * vv = int64 (v )
1894+
1895+ return nil
1896+ default :
1897+ return xerrors .WithStackTrace (fmt .Errorf (
1898+ "%w '%s(%+v)' to '%T' destination" ,
1899+ ErrCannotCast , v .Type ().Yql (), v , vv ,
1900+ ))
1901+ }
1902+ }
1903+
1904+ func (v timestamp64Value ) Yql () string {
1905+ return fmt .Sprintf ("%s(%q)" , v .Type ().Yql (), Timestamp64ToTime (int64 (v )).UTC ().Format (LayoutTimestamp ))
1906+ }
1907+
1908+ func (timestamp64Value ) Type () types.Type {
1909+ return types .Timestamp64
1910+ }
1911+
1912+ func (v timestamp64Value ) toYDB (a * allocator.Allocator ) * Ydb.Value {
1913+ vv := a .Int64 ()
1914+ vv .Int64Value = int64 (v )
1915+
1916+ vvv := a .Value ()
1917+ vvv .Value = vv
1918+
1919+ return vvv
1920+ }
1921+
1922+ // Timestamp64Value makes ydb timestamp value by given microseconds since Epoch
1923+ func Timestamp64Value (v int64 ) timestamp64Value {
1924+ return timestamp64Value (v )
1925+ }
1926+
1927+ func Timestamp64ValueFromTime (t time.Time ) timestamp64Value {
1928+ return timestamp64Value (t .UnixMicro ())
1929+ }
1930+
17601931type tupleValue struct {
17611932 t types.Type
17621933 items []Value
0 commit comments