mirror of
https://github.com/hanzo-ds/native.git
synced 2026-10-30 20:00:34 +00:00
Ports the SigNoz dd-sketch proto types (DD, IndexMapping, Store), the AggregateFunction(quantilesDD) column codec, and signed varint helpers (Buffer.PutVarInt, Reader.VarInt) onto the upstream ch-go v0.71.0 base. Byte-identical to SigNoz/ch-go v0.66.0-dd-sketch (KAT-verified encode, round-trip, column codec, and ColumnType.Conflicts parity) so the SigNoz-derived OTel collectors can depend on hanzo-ds/native instead of the ClickHouse-named ch-go without losing DDSketch metric serialization. Orthogonal: new files plus additive methods/const and one new AggregateFunction branch in Conflicts; existing consumers unaffected.
82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
package proto
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// AggregateFunctionDD implements Column interface.
|
|
type AggregateFunctionDD struct {
|
|
data []DD
|
|
args []interface{}
|
|
typ ColumnType
|
|
}
|
|
|
|
// NewAggregateFunctionDD returns new AggregateFunctionDD.
|
|
func NewAggregateFunctionDD(args []interface{}, typ ColumnType) *AggregateFunctionDD {
|
|
return &AggregateFunctionDD{args: args, typ: typ}
|
|
}
|
|
|
|
// Append appends DD to column.
|
|
func (a *AggregateFunctionDD) Append(v DD) {
|
|
a.data = append(a.data, v)
|
|
}
|
|
|
|
// AppendArr appends DD array to column.
|
|
func (a *AggregateFunctionDD) AppendArr(v []DD) {
|
|
a.data = append(a.data, v...)
|
|
}
|
|
|
|
// Row returns DD at index i.
|
|
func (a AggregateFunctionDD) Row(i int) DD {
|
|
return a.data[i]
|
|
}
|
|
|
|
// Type returns ColumnTypeAggregateFunction.
|
|
func (a AggregateFunctionDD) Type() ColumnType {
|
|
argsStr := make([]string, len(a.args))
|
|
for i, arg := range a.args {
|
|
argsStr[i] = fmt.Sprintf("%v", arg)
|
|
}
|
|
return ColumnType(fmt.Sprintf("%s(%s, %s)", string(ColumnTypeAggregateFunction), strings.Join(argsStr, ", "), a.typ))
|
|
}
|
|
|
|
// Rows returns number of rows in column.
|
|
func (a AggregateFunctionDD) Rows() int { return len(a.data) }
|
|
|
|
// DecodeColumn decodes column from reader.
|
|
func (a *AggregateFunctionDD) DecodeColumn(r *Reader, rows int) error {
|
|
for i := 0; i < rows; i++ {
|
|
var v DD
|
|
if err := v.Decode(r); err != nil {
|
|
return err
|
|
}
|
|
a.Append(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Reset resets column data.
|
|
func (a *AggregateFunctionDD) Reset() {
|
|
a.data = nil
|
|
}
|
|
|
|
// EncodeColumn encodes column to buffer.
|
|
func (a AggregateFunctionDD) EncodeColumn(b *Buffer) {
|
|
if b == nil {
|
|
return
|
|
}
|
|
for _, v := range a.data {
|
|
v.Encode(b)
|
|
}
|
|
}
|
|
|
|
// Debug returns string representation of column.
|
|
func (a AggregateFunctionDD) Debug() string {
|
|
var sketches = make([]string, len(a.data))
|
|
for _, sketch := range a.data {
|
|
sketches = append(sketches, sketch.Debug())
|
|
}
|
|
return strings.Join(sketches, "\n")
|
|
}
|