本文整理匯總了Golang中github.com/influxdata/influxdb/tsdb/engine/tsm1.Values函數的典型用法代碼示例。如果您正苦於以下問題:Golang Values函數的具體用法?Golang Values怎麽用?Golang Values使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Values函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestEncoding_BooleanBlock_Basic
func TestEncoding_BooleanBlock_Basic(t *testing.T) {
valueCount := 1000
times := getTimes(valueCount, 60, time.Second)
values := make([]tsm1.Value, len(times))
for i, t := range times {
v := true
if i%2 == 0 {
v = false
}
values[i] = tsm1.NewValue(t, v)
}
b, err := tsm1.Values(values).Encode(nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
var decodedValues []tsm1.Value
decodedValues, err = tsm1.DecodeBlock(b, decodedValues)
if err != nil {
t.Fatalf("unexpected error decoding block: %v", err)
}
if !reflect.DeepEqual(decodedValues, values) {
t.Fatalf("unexpected results:\n\tgot: %v\n\texp: %v\n", decodedValues, values)
}
}
示例2: TestEncoding_IntBlock_Basic
func TestEncoding_IntBlock_Basic(t *testing.T) {
valueCount := 1000
times := getTimes(valueCount, 60, time.Second)
values := make([]tsm1.Value, len(times))
for i, t := range times {
values[i] = tsm1.NewValue(t, int64(i))
}
b, err := tsm1.Values(values).Encode(nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
var decodedValues []tsm1.Value
decodedValues, err = tsm1.DecodeBlock(b, decodedValues)
if err != nil {
t.Fatalf("unexpected error decoding block: %v", err)
}
if len(decodedValues) != len(values) {
t.Fatalf("unexpected results length:\n\tgot: %v\n\texp: %v\n", len(decodedValues), len(values))
}
for i := 0; i < len(decodedValues); i++ {
if decodedValues[i].UnixNano() != values[i].UnixNano() {
t.Fatalf("unexpected results:\n\tgot: %v\n\texp: %v\n", decodedValues[i].UnixNano(), values[i].UnixNano())
}
if decodedValues[i].Value() != values[i].Value() {
t.Fatalf("unexpected results:\n\tgot: %v\n\texp: %v\n", decodedValues[i].Value(), values[i].Value())
}
}
}
示例3: TestEncoding_Count
func TestEncoding_Count(t *testing.T) {
tests := []struct {
value interface{}
blockType byte
}{
{value: float64(1.0), blockType: tsm1.BlockFloat64},
{value: int64(1), blockType: tsm1.BlockInteger},
{value: true, blockType: tsm1.BlockBoolean},
{value: "string", blockType: tsm1.BlockString},
}
for _, test := range tests {
var values []tsm1.Value
values = append(values, tsm1.NewValue(0, test.value))
b, err := tsm1.Values(values).Encode(nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got, exp := tsm1.BlockCount(b), 1; got != exp {
t.Fatalf("block count mismatch: got %v, exp %v", got, exp)
}
}
}
示例4: TestEncoding_BlockType
func TestEncoding_BlockType(t *testing.T) {
tests := []struct {
value interface{}
blockType byte
}{
{value: float64(1.0), blockType: tsm1.BlockFloat64},
{value: int64(1), blockType: tsm1.BlockInteger},
{value: true, blockType: tsm1.BlockBoolean},
{value: "string", blockType: tsm1.BlockString},
}
for _, test := range tests {
var values []tsm1.Value
values = append(values, tsm1.NewValue(time.Unix(0, 0), test.value))
b, err := tsm1.Values(values).Encode(nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
bt, err := tsm1.BlockType(b)
if err != nil {
t.Fatalf("unexpected error decoding block type: %v", err)
}
if got, exp := bt, test.blockType; got != exp {
t.Fatalf("block type mismatch: got %v, exp %v", got, exp)
}
}
_, err := tsm1.BlockType([]byte{10})
if err == nil {
t.Fatalf("expected error decoding block type, got nil")
}
}
示例5: BenchmarkValues_Deduplicate
func BenchmarkValues_Deduplicate(b *testing.B) {
valueCount := 1000
times := getTimes(valueCount, 60, time.Second)
values := make([]tsm1.Value, len(times))
for i, t := range times {
values[i] = tsm1.NewValue(t, fmt.Sprintf("value %d", i))
}
values = append(values, values...)
b.ResetTimer()
for i := 0; i < b.N; i++ {
tsm1.Values(values).Deduplicate()
}
}
示例6: BenchmarkValues_EncodeString
func BenchmarkValues_EncodeString(b *testing.B) {
valueCount := 1024
times := getTimes(valueCount, 60, time.Second)
a := make([]tsm1.Value, len(times))
for i, t := range times {
a[i] = tsm1.NewValue(t, fmt.Sprintf("%d", i))
}
buf := make([]byte, 1024*8)
b.ResetTimer()
for i := 0; i < b.N; i++ {
tsm1.Values(a).Encode(buf)
}
}
示例7: BenchmarkValues_Merge
func BenchmarkValues_Merge(b *testing.B) {
valueCount := 1000
times := getTimes(valueCount, 60, time.Second)
a := make([]tsm1.Value, len(times))
c := make([]tsm1.Value, len(times))
for i, t := range times {
a[i] = tsm1.NewValue(t, float64(i))
c[i] = tsm1.NewValue(t+1, float64(i))
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
tsm1.Values(a).Merge(c)
}
}
示例8: BenchmarkValues_EncodeBool
func BenchmarkValues_EncodeBool(b *testing.B) {
valueCount := 1024
times := getTimes(valueCount, 60, time.Second)
a := make([]tsm1.Value, len(times))
for i, t := range times {
if i%2 == 0 {
a[i] = tsm1.NewValue(t, true)
} else {
a[i] = tsm1.NewValue(t, false)
}
}
buf := make([]byte, 1024*8)
b.ResetTimer()
for i := 0; i < b.N; i++ {
tsm1.Values(a).Encode(buf)
}
}
示例9: TestEncoding_FloatBlock_ZeroTime
func TestEncoding_FloatBlock_ZeroTime(t *testing.T) {
values := make([]tsm1.Value, 3)
for i := 0; i < 3; i++ {
values[i] = tsm1.NewValue(0, float64(i))
}
b, err := tsm1.Values(values).Encode(nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
var decodedValues []tsm1.Value
decodedValues, err = tsm1.DecodeBlock(b, decodedValues)
if err != nil {
t.Fatalf("unexpected error decoding block: %v", err)
}
if !reflect.DeepEqual(decodedValues, values) {
t.Fatalf("unexpected results:\n\tgot: %v\n\texp: %v\n", decodedValues, values)
}
}
示例10: BenchmarkDecodeBlock_String_TypeSpecific
func BenchmarkDecodeBlock_String_TypeSpecific(b *testing.B) {
valueCount := 1000
times := getTimes(valueCount, 60, time.Second)
values := make([]tsm1.Value, len(times))
for i, t := range times {
values[i] = tsm1.NewValue(t, fmt.Sprintf("value %d", i))
}
bytes, err := tsm1.Values(values).Encode(nil)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
decodedValues := make([]tsm1.StringValue, len(values))
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = tsm1.DecodeStringBlock(bytes, &decodedValues)
if err != nil {
b.Fatalf("unexpected error decoding block: %v", err)
}
}
}
示例11: BenchmarkDecodeBlock_Boolean_EqualSize
func BenchmarkDecodeBlock_Boolean_EqualSize(b *testing.B) {
valueCount := 1000
times := getTimes(valueCount, 60, time.Second)
values := make([]tsm1.Value, len(times))
for i, t := range times {
values[i] = tsm1.NewValue(t, true)
}
bytes, err := tsm1.Values(values).Encode(nil)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
decodedValues := make([]tsm1.Value, len(values))
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = tsm1.DecodeBlock(bytes, decodedValues)
if err != nil {
b.Fatalf("unexpected error decoding block: %v", err)
}
}
}
示例12: BenchmarkDecodeBlock_Integer_TypeSpecific
func BenchmarkDecodeBlock_Integer_TypeSpecific(b *testing.B) {
valueCount := 1000
times := getTimes(valueCount, 60, time.Second)
values := make([]tsm1.Value, len(times))
for i, t := range times {
values[i] = tsm1.NewValue(t, int64(i))
}
bytes, err := tsm1.Values(values).Encode(nil)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
decodedValues := make([]tsm1.IntegerValue, len(values))
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = tsm1.DecodeIntegerBlock(bytes, tsm1.NewTimeDecoder(), &tsm1.IntegerDecoder{}, &decodedValues)
if err != nil {
b.Fatalf("unexpected error decoding block: %v", err)
}
}
}
示例13: TestEncoding_FloatBlock_SimilarFloats
func TestEncoding_FloatBlock_SimilarFloats(t *testing.T) {
values := make([]tsm1.Value, 5)
values[0] = tsm1.NewValue(1444238178437870000, 6.00065e+06)
values[1] = tsm1.NewValue(1444238185286830000, 6.000656e+06)
values[2] = tsm1.NewValue(1444238188441501000, 6.000657e+06)
values[3] = tsm1.NewValue(1444238195286811000, 6.000659e+06)
values[4] = tsm1.NewValue(1444238198439917000, 6.000661e+06)
b, err := tsm1.Values(values).Encode(nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
var decodedValues []tsm1.Value
decodedValues, err = tsm1.DecodeBlock(b, decodedValues)
if err != nil {
t.Fatalf("unexpected error decoding block: %v", err)
}
if !reflect.DeepEqual(decodedValues, values) {
t.Fatalf("unexpected results:\n\tgot: %v\n\texp: %v\n", decodedValues, values)
}
}
示例14: TestEncoding_FloatBlock
func TestEncoding_FloatBlock(t *testing.T) {
valueCount := 1000
times := getTimes(valueCount, 60, time.Second)
values := make([]tsm1.Value, len(times))
for i, t := range times {
values[i] = tsm1.NewValue(t, float64(i))
}
b, err := tsm1.Values(values).Encode(nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
var decodedValues []tsm1.Value
decodedValues, err = tsm1.DecodeBlock(b, decodedValues)
if err != nil {
t.Fatalf("unexpected error decoding block: %v", err)
}
if !reflect.DeepEqual(decodedValues, values) {
t.Fatalf("unexpected results:\n\tgot: %s\n\texp: %s\n", spew.Sdump(decodedValues), spew.Sdump(values))
}
}
示例15: TestValues_MergeFloat
func TestValues_MergeFloat(t *testing.T) {
tests := []struct {
a, b, exp []tsm1.Value
}{
{ // empty a
a: []tsm1.Value{},
b: []tsm1.Value{
tsm1.NewValue(1, 1.2),
tsm1.NewValue(2, 2.2),
},
exp: []tsm1.Value{
tsm1.NewValue(1, 1.2),
tsm1.NewValue(2, 2.2),
},
},
{ // empty b
a: []tsm1.Value{
tsm1.NewValue(1, 1.1),
tsm1.NewValue(2, 2.1),
},
b: []tsm1.Value{},
exp: []tsm1.Value{
tsm1.NewValue(1, 1.1),
tsm1.NewValue(2, 2.1),
},
},
{
a: []tsm1.Value{
tsm1.NewValue(0, 0.0),
tsm1.NewValue(1, 1.1),
tsm1.NewValue(2, 2.1),
},
b: []tsm1.Value{
tsm1.NewValue(2, 2.2),
tsm1.NewValue(2, 2.2), // duplicate data
},
exp: []tsm1.Value{
tsm1.NewValue(0, 0.0),
tsm1.NewValue(1, 1.1),
tsm1.NewValue(2, 2.2),
},
},
{
a: []tsm1.Value{
tsm1.NewValue(0, 0.0),
tsm1.NewValue(1, 1.1),
tsm1.NewValue(1, 1.1), // duplicate data
tsm1.NewValue(2, 2.1),
},
b: []tsm1.Value{
tsm1.NewValue(2, 2.2),
tsm1.NewValue(2, 2.2), // duplicate data
},
exp: []tsm1.Value{
tsm1.NewValue(0, 0.0),
tsm1.NewValue(1, 1.1),
tsm1.NewValue(2, 2.2),
},
},
{
a: []tsm1.Value{
tsm1.NewValue(1, 1.1),
},
b: []tsm1.Value{
tsm1.NewValue(0, 0.0),
tsm1.NewValue(1, 1.2), // overwrites a
tsm1.NewValue(2, 2.2),
tsm1.NewValue(3, 3.2),
tsm1.NewValue(4, 4.2),
},
exp: []tsm1.Value{
tsm1.NewValue(0, 0.0),
tsm1.NewValue(1, 1.2),
tsm1.NewValue(2, 2.2),
tsm1.NewValue(3, 3.2),
tsm1.NewValue(4, 4.2),
},
},
{
a: []tsm1.Value{
tsm1.NewValue(1, 1.1),
tsm1.NewValue(2, 2.1),
tsm1.NewValue(3, 3.1),
tsm1.NewValue(4, 4.1),
},
b: []tsm1.Value{
tsm1.NewValue(1, 1.2), // overwrites a
tsm1.NewValue(2, 2.2), // overwrites a
},
exp: []tsm1.Value{
tsm1.NewValue(1, 1.2),
tsm1.NewValue(2, 2.2),
tsm1.NewValue(3, 3.1),
tsm1.NewValue(4, 4.1),
},
//.........這裏部分代碼省略.........