本文整理匯總了Golang中github.com/cockroachdb/cockroach/pkg/sql/parser.Datum.Compare方法的典型用法代碼示例。如果您正苦於以下問題:Golang Datum.Compare方法的具體用法?Golang Datum.Compare怎麽用?Golang Datum.Compare使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/pkg/sql/parser.Datum
的用法示例。
在下文中一共展示了Datum.Compare方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestEncDatumCompare
func TestEncDatumCompare(t *testing.T) {
defer leaktest.AfterTest(t)()
a := &DatumAlloc{}
rng, _ := randutil.NewPseudoRand()
for kind := range ColumnType_Kind_name {
kind := ColumnType_Kind(kind)
// TODO(cuongdo,eisen): we don't support persistence for arrays or collated
// strings yet
if kind == ColumnType_COLLATEDSTRING || kind == ColumnType_INT_ARRAY {
continue
}
typ := ColumnType{Kind: kind}
// Generate two datums d1 < d2
var d1, d2 parser.Datum
for {
d1 = RandDatum(rng, typ, false)
d2 = RandDatum(rng, typ, false)
if cmp := d1.Compare(d2); cmp < 0 {
break
}
}
v1 := DatumToEncDatum(typ, d1)
v2 := DatumToEncDatum(typ, d2)
if val, err := v1.Compare(a, &v2); err != nil {
t.Fatal(err)
} else if val != -1 {
t.Errorf("compare(1, 2) = %d", val)
}
asc := DatumEncoding_ASCENDING_KEY
desc := DatumEncoding_DESCENDING_KEY
noncmp := DatumEncoding_VALUE
checkEncDatumCmp(t, a, &v1, &v2, asc, asc, -1, false)
checkEncDatumCmp(t, a, &v2, &v1, asc, asc, +1, false)
checkEncDatumCmp(t, a, &v1, &v1, asc, asc, 0, false)
checkEncDatumCmp(t, a, &v2, &v2, asc, asc, 0, false)
checkEncDatumCmp(t, a, &v1, &v2, desc, desc, -1, false)
checkEncDatumCmp(t, a, &v2, &v1, desc, desc, +1, false)
checkEncDatumCmp(t, a, &v1, &v1, desc, desc, 0, false)
checkEncDatumCmp(t, a, &v2, &v2, desc, desc, 0, false)
checkEncDatumCmp(t, a, &v1, &v2, noncmp, noncmp, -1, true)
checkEncDatumCmp(t, a, &v2, &v1, desc, noncmp, +1, true)
checkEncDatumCmp(t, a, &v1, &v1, asc, desc, 0, true)
checkEncDatumCmp(t, a, &v2, &v2, desc, asc, 0, true)
}
}
示例2: TestEncDatumCompare
func TestEncDatumCompare(t *testing.T) {
a := &DatumAlloc{}
rng, _ := randutil.NewPseudoRand()
for typ := range ColumnType_Kind_name {
typ := ColumnType_Kind(typ)
// TODO(cuongdo): we don't support persistence for arrays yet
if typ == ColumnType_INT_ARRAY {
continue
}
// Generate two datums d1 < d2
var d1, d2 parser.Datum
for {
d1 = RandDatum(rng, typ, false)
d2 = RandDatum(rng, typ, false)
if cmp := d1.Compare(d2); cmp < 0 {
break
}
}
v1 := &EncDatum{}
v1.SetDatum(typ, d1)
v2 := &EncDatum{}
v2.SetDatum(typ, d2)
if val, err := v1.Compare(a, v2); err != nil {
t.Fatal(err)
} else if val != -1 {
t.Errorf("compare(1, 2) = %d", val)
}
asc := DatumEncoding_ASCENDING_KEY
desc := DatumEncoding_DESCENDING_KEY
noncmp := DatumEncoding_VALUE
checkEncDatumCmp(t, a, v1, v2, asc, asc, -1, false)
checkEncDatumCmp(t, a, v2, v1, asc, asc, +1, false)
checkEncDatumCmp(t, a, v1, v1, asc, asc, 0, false)
checkEncDatumCmp(t, a, v2, v2, asc, asc, 0, false)
checkEncDatumCmp(t, a, v1, v2, desc, desc, -1, false)
checkEncDatumCmp(t, a, v2, v1, desc, desc, +1, false)
checkEncDatumCmp(t, a, v1, v1, desc, desc, 0, false)
checkEncDatumCmp(t, a, v2, v2, desc, desc, 0, false)
checkEncDatumCmp(t, a, v1, v2, noncmp, noncmp, -1, true)
checkEncDatumCmp(t, a, v2, v1, desc, noncmp, +1, true)
checkEncDatumCmp(t, a, v1, v1, asc, desc, 0, true)
checkEncDatumCmp(t, a, v2, v2, desc, asc, 0, true)
}
}
示例3: TestEncDatumCompare
func TestEncDatumCompare(t *testing.T) {
a := &DatumAlloc{}
rng, _ := randutil.NewPseudoRand()
for typ := ColumnType_Kind(0); int(typ) < len(ColumnType_Kind_value); typ++ {
// Generate two datums d1 < d2
var d1, d2 parser.Datum
for {
d1 = RandDatum(rng, typ, false)
d2 = RandDatum(rng, typ, false)
if cmp := d1.Compare(d2); cmp < 0 {
break
}
}
v1 := &EncDatum{}
v1.SetDatum(typ, d1)
v2 := &EncDatum{}
v2.SetDatum(typ, d2)
if val, err := v1.Compare(a, v2); err != nil {
t.Fatal(err)
} else if val != -1 {
t.Errorf("compare(1, 2) = %d", val)
}
asc := DatumEncoding_ASCENDING_KEY
desc := DatumEncoding_DESCENDING_KEY
noncmp := DatumEncoding_VALUE
checkEncDatumCmp(t, a, v1, v2, asc, asc, -1, false)
checkEncDatumCmp(t, a, v2, v1, asc, asc, +1, false)
checkEncDatumCmp(t, a, v1, v1, asc, asc, 0, false)
checkEncDatumCmp(t, a, v2, v2, asc, asc, 0, false)
checkEncDatumCmp(t, a, v1, v2, desc, desc, -1, false)
checkEncDatumCmp(t, a, v2, v1, desc, desc, +1, false)
checkEncDatumCmp(t, a, v1, v1, desc, desc, 0, false)
checkEncDatumCmp(t, a, v2, v2, desc, desc, 0, false)
checkEncDatumCmp(t, a, v1, v2, noncmp, noncmp, -1, true)
checkEncDatumCmp(t, a, v2, v1, desc, noncmp, +1, true)
checkEncDatumCmp(t, a, v1, v1, asc, desc, 0, true)
checkEncDatumCmp(t, a, v2, v2, desc, asc, 0, true)
}
}