Files
zeekay 0c90ebe02e debrand: finish the rename across source, docs and dev infra
Source: the unexported clickhouse struct becomes client, the ch receiver and
chproto import alias follow, error message prefixes read datastore, and the
JSON serializer interface drops the vendor infix. resources' metadata key and
its accessor are renamed together, with a test proving the embedded YAML still
unmarshals — a silent drift there would have made every connection take the
unsupported-server-version branch.

Codegen: all three templates still emitted the upstream module paths, so
regenerating would have quietly undone the rename. Note the templates have
drifted from the files they produce (regenerating today drops QBit and
scanTypeDuration), so the generated files are left as tracked and only the
templates are corrected.

Dead links: an earlier mechanical pass invented URLs that do not resolve —
github.com/ClickHouse/datastore-go, hanzo-ds/driver issue numbers that belong to
upstream, and mangled names of independent projects (mailru, uptrace, nikepan,
EpicStep). Third-party names are not ours to rewrite, so those directories are
removed rather than repaired, and provenance comments now point at real files.

Dev infra: compose runs our own server image at the tag production runs, since
the vendor's alpine tag does not exist in our registry. Cluster hostnames,
nginx upstreams and server configs are renamed as one set.

CHANGELOG.md is upstream's release history for versions this module never
released; rewriting it would fabricate a lineage, so it is dropped and the
upstream base recorded in README instead.

The two long-standing vet findings are fixed by keying the struct literals
rather than suppressed. LICENSE and contributors/list keep the vendor name on
purpose: one is the copyright notice Apache-2.0 requires, the other is real
people's names. CI now enforces build, vet, test, gofmt and a grep gate.
2026-07-26 11:46:39 -07:00

189 lines
4.2 KiB
Go

package column
import (
"database/sql"
"database/sql/driver"
"fmt"
"reflect"
"strconv"
"strings"
"time"
"github.com/hanzo-ds/native/proto"
)
type Time64 struct {
chType Type
name string
col proto.ColTime64
}
func (col *Time64) Reset() {
col.col.Reset()
}
func (col *Time64) Name() string {
return col.name
}
func (col *Time64) parse(t Type) (_ Interface, err error) {
col.chType = t
// if no precision is given say just Time64 (instead of Time64(3|6|9))
// it is treated as 3 (milliseconds)
precision := int64(3)
if strings.HasPrefix(string(t), "Time64(") {
params := strings.TrimSuffix(strings.TrimPrefix(string(t), "Time64("), ")")
precision, err = strconv.ParseInt(params, 10, 8)
if err != nil {
return nil, err
}
}
p := byte(precision)
col.col.WithPrecision(proto.Precision(p))
return col, nil
}
func (col *Time64) Type() Type {
return col.chType
}
func (col *Time64) ScanType() reflect.Type {
return scanTypeDuration
}
func (col *Time64) Precision() (int64, bool) {
return int64(col.col.Precision), col.col.PrecisionSet
}
func (col *Time64) Rows() int {
return col.col.Rows()
}
func (col *Time64) Row(i int, ptr bool) any {
value := col.row(i)
if ptr {
return &value
}
return value
}
// ScanRow implements column.Interface.
// It is used to read a single column value of the row and store in
// `dest` Go variable.
func (col *Time64) ScanRow(dest any, row int) error {
switch d := dest.(type) {
case *time.Duration:
*d = col.row(row)
case **time.Duration:
*d = new(time.Duration)
**d = col.row(row)
default:
if scan, ok := dest.(sql.Scanner); ok {
return scan.Scan(col.row(row))
}
return &ColumnConverterError{
Op: "ScanRow",
To: fmt.Sprintf("%T", dest),
From: "Time64",
}
}
return nil
}
// Append implements column.Interface.
// It is used for columnar inserts. Insert multiple Go value for
// single Datastore Time64 type.
func (col *Time64) Append(v any) (nulls []uint8, err error) {
switch v := v.(type) {
case []time.Duration:
nulls = make([]uint8, len(v)) // default all zeros, meaning no null values
for i := range v {
col.col.Append(proto.IntoTime64WithPrecision(v[i], col.col.Precision))
}
case []*time.Duration:
nulls = make([]uint8, len(v))
for i := range v {
switch {
case v[i] != nil:
col.col.Append(proto.IntoTime64WithPrecision(*v[i], col.col.Precision))
default:
col.col.Append(proto.IntoTime64WithPrecision(time.Duration(0), col.col.Precision))
nulls[i] = 1
}
}
default:
if valuer, ok := v.(driver.Valuer); ok {
val, err := valuer.Value()
if err != nil {
return nil, &ColumnConverterError{
Op: "Append",
To: "Time64",
From: fmt.Sprintf("%T", v),
Hint: "could not get driver.Valuer value",
}
}
return col.Append(val)
}
return nil, &ColumnConverterError{
Op: "Append",
To: "Time64",
From: fmt.Sprintf("%T", v),
}
}
return
}
// AppendRow implements column.Interface.
// It is used to insert column value in a row.
// Converts Go type into Datastore type to be inserted.
func (col *Time64) AppendRow(v any) error {
switch v := v.(type) {
case time.Duration:
col.col.Append(proto.IntoTime64WithPrecision(v, col.col.Precision))
case *time.Duration:
switch {
case v != nil:
col.col.Append(proto.IntoTime64WithPrecision(*v, col.col.Precision))
default:
col.col.Append(proto.IntoTime64WithPrecision(time.Duration(0), col.col.Precision))
}
default:
if valuer, ok := v.(driver.Valuer); ok {
val, err := valuer.Value()
if err != nil {
return &ColumnConverterError{
Op: "AppendRow",
To: "Time64",
From: fmt.Sprintf("%T", v),
Hint: "could not get driver.Valuer value",
}
}
return col.AppendRow(val)
}
return &ColumnConverterError{
Op: "AppendRow",
To: "Time64",
From: fmt.Sprintf("%T", v),
}
}
return nil
}
func (col *Time64) Decode(reader *proto.Reader, rows int) error {
return col.col.DecodeColumn(reader, rows)
}
func (col *Time64) Encode(buffer *proto.Buffer) {
col.col.EncodeColumn(buffer)
}
func (col *Time64) row(i int) time.Duration {
return col.col.Row(i).ToDurationWithPrecision(col.col.Precision)
}
func (col *Time64) parseTime(value string) (time.Duration, error) {
return parseDuration(value)
}