in transforms.go [258:312]
func (t BucketTransform) Transformer(src Type) func(any) Optional[int32] {
var h func(any) uint32
switch src.(type) {
case Int32Type:
h = hashHelperInt[int32]
case DateType:
h = hashHelperInt[Date]
case Int64Type:
h = hashHelperInt[int64]
case TimeType:
h = hashHelperInt[Time]
case TimestampType:
h = hashHelperInt[Timestamp]
case TimestampTzType:
h = hashHelperInt[Timestamp]
case DecimalType:
h = func(v any) uint32 {
b, _ := DecimalLiteral(v.(Decimal)).MarshalBinary()
return murmur3.Sum32(b)
}
case StringType, FixedType, BinaryType:
h = func(v any) uint32 {
if v, ok := v.([]byte); ok {
return murmur3.Sum32(v)
}
str := v.(string)
return murmur3.Sum32(unsafe.Slice(unsafe.StringData(str), len(str)))
}
case UUIDType:
h = func(v any) uint32 {
if v, ok := v.([]byte); ok {
return murmur3.Sum32(v)
}
u := v.(uuid.UUID)
return murmur3.Sum32(u[:])
}
}
return func(v any) Optional[int32] {
if v == nil {
return Optional[int32]{}
}
return Optional[int32]{
Valid: true,
Val: int32((int32(h(v)) & math.MaxInt32) % int32(t.NumBuckets)),
}
}
}