本文整理匯總了Golang中github.com/cockroachdb/cockroach/pkg/sql/parser.DDecimal.SetString方法的典型用法代碼示例。如果您正苦於以下問題:Golang DDecimal.SetString方法的具體用法?Golang DDecimal.SetString怎麽用?Golang DDecimal.SetString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/pkg/sql/parser.DDecimal
的用法示例。
在下文中一共展示了DDecimal.SetString方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: BenchmarkDecodeBinaryDecimal
func BenchmarkDecodeBinaryDecimal(b *testing.B) {
wbuf := writeBuffer{bytecount: metric.NewCounter(metric.Metadata{Name: ""})}
expected := new(parser.DDecimal)
s := "-1728718718271827121233.1212121212"
if _, ok := expected.SetString(s); !ok {
b.Fatalf("could not set %q on decimal", s)
}
wbuf.writeBinaryDatum(expected, nil)
rbuf := readBuffer{msg: wbuf.wrapped.Bytes()}
plen, err := rbuf.getUint32()
if err != nil {
b.Fatal(err)
}
bytes, err := rbuf.getBytes(int(plen))
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StartTimer()
got, err := decodeOidDatum(oid.T_numeric, formatBinary, bytes)
b.StopTimer()
if err != nil {
b.Fatal(err)
} else if got.Compare(expected) != 0 {
b.Fatalf("expected %s, got %s", expected, got)
}
}
}
示例2: benchmarkWriteDecimal
func benchmarkWriteDecimal(b *testing.B, format formatCode) {
dec := new(parser.DDecimal)
s := "-1728718718271827121233.1212121212"
if _, ok := dec.SetString(s); !ok {
b.Fatalf("could not set %q on decimal", format)
}
benchmarkWriteType(b, dec, formatText)
}
示例3: TestBinaryDecimal
func TestBinaryDecimal(t *testing.T) {
defer leaktest.AfterTest(t)()
testBinaryDatumType(t, "decimal", func(val string) parser.Datum {
dec := new(parser.DDecimal)
if _, ok := dec.SetString(val); !ok {
t.Fatalf("could not set %q on decimal", val)
}
return dec
})
}
示例4: BenchmarkWriteBinaryDecimal
func BenchmarkWriteBinaryDecimal(b *testing.B) {
buf := writeBuffer{bytecount: metric.NewCounter(metric.Metadata{Name: ""})}
dec := new(parser.DDecimal)
s := "-1728718718271827121233.1212121212"
if _, ok := dec.SetString(s); !ok {
b.Fatalf("could not set %q on decimal", s)
}
// Warm up the buffer.
buf.writeBinaryDatum(dec, nil)
buf.wrapped.Reset()
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StartTimer()
buf.writeBinaryDatum(dec, nil)
b.StopTimer()
buf.wrapped.Reset()
}
}
示例5: TestRandomBinaryDecimal
func TestRandomBinaryDecimal(t *testing.T) {
defer leaktest.AfterTest(t)()
if *generateBinaryCmd == "" {
t.Skip("disabled")
}
fields := strings.Fields(*generateBinaryCmd)
if len(fields) < 1 {
t.Fatal("expected generate-binary arguments")
}
name, args := fields[0], fields[1:]
var tests []binaryTest
randutil.SeedForTests()
for {
var b bytes.Buffer
for n := rand.Intn(50); n >= 0; n-- {
fmt.Fprint(&b, rand.Intn(10))
}
v := b.String()
{
z := strings.Repeat("0", rand.Intn(10))
pos := rand.Intn(len(v) + 1)
v = v[:pos] + z + v[pos:]
}
if rand.Intn(2) == 0 {
pos := rand.Intn(len(v) + 1)
v = v[:pos] + "." + v[pos:]
}
cmdargs := append(args, `"`+v+`"`)
out, err := exec.Command(name, cmdargs...).CombinedOutput()
if err != nil {
t.Log(string(out))
t.Fatal(err)
}
if err := json.Unmarshal(out, &tests); err != nil {
t.Fatal(err)
}
if len(tests) != 1 {
t.Fatal("expected 1 test")
}
test := tests[0]
buf := writeBuffer{bytecount: metric.NewCounter(metric.Metadata{})}
dec := new(parser.DDecimal)
if _, ok := dec.SetString(test.In); !ok {
t.Fatalf("could not set %q on decimal", test.In)
}
buf.writeBinaryDatum(dec, time.UTC)
if buf.err != nil {
t.Fatal(buf.err)
}
if got := buf.wrapped.Bytes(); !bytes.Equal(got, test.Expect) {
t.Errorf("%q:\n\t%v found,\n\t%v expected", test.In, got, test.Expect)
} else if datum, err := decodeOidDatum(oid.T_numeric, formatBinary, got[4:]); err != nil {
t.Errorf("%q: unable to decode %v: %s", test.In, got[4:], err)
} else if dec.Compare(datum) != 0 {
t.Errorf("%q: expected %s, got %s", test.In, dec, datum)
}
}
}