本文整理汇总了Golang中github.com/pingcap/tidb/util/types.Compare函数的典型用法代码示例。如果您正苦于以下问题:Golang Compare函数的具体用法?Golang Compare怎么用?Golang Compare使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Compare函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: handleComparisonOp
func (e *Evaluator) handleComparisonOp(o *ast.BinaryOperationExpr) bool {
a, b := types.Coerce(o.L.GetValue(), o.R.GetValue())
if types.IsNil(a) || types.IsNil(b) {
// for <=>, if a and b are both nil, return true.
// if a or b is nil, return false.
if o.Op == opcode.NullEQ {
if types.IsNil(a) || types.IsNil(b) {
o.SetValue(oneI64)
} else {
o.SetValue(zeroI64)
}
} else {
o.SetValue(nil)
}
return true
}
n, err := types.Compare(a, b)
if err != nil {
e.err = errors.Trace(err)
return false
}
r, err := getCompResult(o.Op, n)
if err != nil {
e.err = errors.Trace(err)
return false
}
if r {
o.SetValue(oneI64)
} else {
o.SetValue(zeroI64)
}
return true
}
开发者ID:lovedboy,项目名称:tidb,代码行数:35,代码来源:evaluator_binop.go
示例2: Less
// Less implements sort.Interface Less interface.
func (t *orderByTable) Less(i, j int) bool {
for index, asc := range t.Ascs {
v1 := t.Rows[i].Key[index]
v2 := t.Rows[j].Key[index]
ret, err := types.Compare(v1, v2)
if err != nil {
// we just have to log this error and skip it.
// TODO: record this error and handle it out later.
log.Errorf("compare %v %v err %v", v1, v2, err)
}
if !asc {
ret = -ret
}
if ret < 0 {
return true
} else if ret > 0 {
return false
}
}
return false
}
开发者ID:no2key,项目名称:tidb,代码行数:26,代码来源:orderby.go
示例3: replaceRow
func replaceRow(ctx context.Context, t table.Table, handle int64, replaceRow []interface{}) error {
row, err := t.Row(ctx, handle)
if err != nil {
return errors.Trace(err)
}
result := 0
isReplace := false
touched := make(map[int]bool, len(row))
for i, val := range row {
result, err = types.Compare(val, replaceRow[i])
if err != nil {
return errors.Trace(err)
}
if result != 0 {
touched[i] = true
isReplace = true
}
}
if isReplace {
variable.GetSessionVars(ctx).AddAffectedRows(1)
if err = t.UpdateRecord(ctx, handle, row, replaceRow, touched); err != nil {
return errors.Trace(err)
}
}
return nil
}
开发者ID:yzl11,项目名称:vessel,代码行数:29,代码来源:replace.go
示例4: caseExpr
func (e *Evaluator) caseExpr(v *ast.CaseExpr) bool {
var target interface{} = true
if v.Value != nil {
target = v.Value.GetValue()
}
if target != nil {
for _, val := range v.WhenClauses {
cmp, err := types.Compare(target, val.Expr.GetValue())
if err != nil {
e.err = errors.Trace(err)
return false
}
if cmp == 0 {
v.SetValue(val.Result.GetValue())
return true
}
}
}
if v.ElseClause != nil {
v.SetValue(v.ElseClause.GetValue())
} else {
v.SetValue(nil)
}
return true
}
开发者ID:mrtoms,项目名称:tidb,代码行数:25,代码来源:evaluator.go
示例5: checkAnyResult
func (e *Evaluator) checkAnyResult(cs *ast.CompareSubqueryExpr, lv interface{}, result []interface{}) (interface{}, error) {
hasNull := false
for _, v := range result {
if v == nil {
hasNull = true
continue
}
comRes, err := types.Compare(lv, v)
if err != nil {
return nil, errors.Trace(err)
}
res, err := getCompResult(cs.Op, comRes)
if err != nil {
return nil, errors.Trace(err)
}
if res {
return true, nil
}
}
if hasNull {
// If no matched but we get null, return null.
// Like `insert t (c) values (1),(2),(null)`, then
// `select 0 > any (select c from t)`, returns null.
return nil, nil
}
return false, nil
}
开发者ID:xudongQiu,项目名称:tidb,代码行数:31,代码来源:evaluator.go
示例6: checkInList
func (e *Evaluator) checkInList(not bool, in interface{}, list []interface{}) (interface{}, error) {
hasNull := false
for _, v := range list {
if types.IsNil(v) {
hasNull = true
continue
}
r, err := types.Compare(in, v)
if err != nil {
return nil, errors.Trace(err)
}
if r == 0 {
return !not, nil
}
}
if hasNull {
// if no matched but we got null in In, return null
// e.g 1 in (null, 2, 3) returns null
return nil, nil
}
return not, nil
}
开发者ID:mrtoms,项目名称:tidb,代码行数:26,代码来源:evaluator.go
示例7: indexCompare
// comparison function that takes minNotNullVal and maxVal into account.
func indexCompare(a interface{}, b interface{}) int {
if a == nil && b == nil {
return 0
} else if b == nil {
return 1
} else if b == nil {
return -1
}
// a and b both not nil
if a == minNotNullVal && b == minNotNullVal {
return 0
} else if b == minNotNullVal {
return 1
} else if a == minNotNullVal {
return -1
}
// a and b both not min value
if a == maxVal && b == maxVal {
return 0
} else if a == maxVal {
return 1
} else if b == maxVal {
return -1
}
n, err := types.Compare(a, b)
if err != nil {
// Old compare panics if err, so here we do the same thing now.
// TODO: return err instead of panic.
panic(fmt.Sprintf("should never happend %v", err))
}
return n
}
开发者ID:kevinhuo88888,项目名称:tidb,代码行数:35,代码来源:index.go
示例8: evalComparisonOp
// operator: >=, >, <=, <, !=, <>, = <=>, etc.
// see https://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html
func (o *BinaryOperation) evalComparisonOp(ctx context.Context, args map[interface{}]interface{}) (interface{}, error) {
//TODO: support <=> later
a, b, err := o.get2(ctx, args)
if err != nil {
return nil, err
}
if a == nil || b == nil {
// TODO: for <=>, if a and b are both nil, return true
return nil, nil
}
n, err := types.Compare(a, b)
if err != nil {
return nil, o.traceErr(err)
}
switch o.Op {
case opcode.LT:
return n < 0, nil
case opcode.LE:
return n <= 0, nil
case opcode.GE:
return n >= 0, nil
case opcode.GT:
return n > 0, nil
case opcode.EQ:
return n == 0, nil
case opcode.NE:
return n != 0, nil
default:
return nil, o.errorf("invalid op %v in comparision operation", o.Op)
}
}
开发者ID:eeertekin,项目名称:tidb,代码行数:36,代码来源:binop.go
示例9: checkInList
func (n *PatternIn) checkInList(in interface{}, list []interface{}) (interface{}, error) {
hasNull := false
for _, v := range list {
if types.IsNil(v) {
hasNull = true
continue
}
r, err := types.Compare(in, v)
if err != nil {
return nil, err
}
if r == 0 {
return !n.Not, nil
}
}
if hasNull {
// if no matched but we got null in In, return null
// e.g 1 in (null, 2, 3) returns null
return nil, nil
}
return n.Not, nil
}
开发者ID:fuxiaohei,项目名称:tidb,代码行数:26,代码来源:in.go
示例10: evalComparisonOp
// operator: >=, >, <=, <, !=, <>, = <=>, etc.
// see https://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html
func (o *BinaryOperation) evalComparisonOp(ctx context.Context, args map[interface{}]interface{}) (interface{}, error) {
//TODO: support <=> later
a, b, err := o.get2(ctx, args)
if err != nil {
return nil, err
}
if a == nil || b == nil {
// for <=>, if a and b are both nil, return true.
// if a or b is nil, return false.
if o.Op == opcode.NullEQ {
return a == b, nil
}
return nil, nil
}
n, err := types.Compare(a, b)
if err != nil {
return nil, o.traceErr(err)
}
r, err := getCompResult(o.Op, n)
if err != nil {
return nil, o.errorf(err.Error())
}
return r, nil
}
开发者ID:nengwang,项目名称:tidb,代码行数:31,代码来源:binop.go
示例11: updateMaxMin
func (n *AggregateFuncExpr) updateMaxMin(max bool) error {
ctx := n.GetContext()
if len(n.Args) != 1 {
return errors.New("Wrong number of args for AggFuncFirstRow")
}
v := n.Args[0].GetValue()
if !ctx.evaluated {
ctx.Value = v
ctx.evaluated = true
return nil
}
c, err := types.Compare(ctx.Value, v)
if err != nil {
return errors.Trace(err)
}
if max {
if c == -1 {
ctx.Value = v
}
} else {
if c == 1 {
ctx.Value = v
}
}
return nil
}
开发者ID:astaxie,项目名称:tidb,代码行数:27,代码来源:functions.go
示例12: patternIn
func (e *Evaluator) patternIn(n *ast.PatternInExpr) bool {
lhs := n.Expr.GetValue()
if types.IsNil(lhs) {
n.SetValue(nil)
return true
}
hasNull := false
for _, v := range n.List {
if types.IsNil(v.GetValue()) {
hasNull = true
continue
}
r, err := types.Compare(n.Expr.GetValue(), v.GetValue())
if err != nil {
e.err = errors.Trace(err)
return false
}
if r == 0 {
n.SetValue(boolToInt64(!n.Not))
return true
}
}
if hasNull {
// if no matched but we got null in In, return null
// e.g 1 in (null, 2, 3) returns null
n.SetValue(nil)
return true
}
n.SetValue(boolToInt64(n.Not))
return true
}
开发者ID:mrtoms,项目名称:tidb,代码行数:31,代码来源:evaluator.go
示例13: indexCompare
// comparison function that takes minNotNullVal and maxVal into account.
func indexCompare(a interface{}, b interface{}) int {
if a == nil && b == nil {
return 0
} else if b == nil {
return 1
} else if b == nil {
return -1
}
// a and b both not nil
if a == minNotNullVal && b == minNotNullVal {
return 0
} else if b == minNotNullVal {
return 1
} else if a == minNotNullVal {
return -1
}
// a and b both not min value
if a == maxVal && b == maxVal {
return 0
} else if a == maxVal {
return 1
} else if b == maxVal {
return -1
}
return types.Compare(a, b)
}
开发者ID:npk,项目名称:tidb,代码行数:29,代码来源:index.go
示例14: indexColumnCompare
// comparison function that takes minNotNullVal and maxVal into account.
func indexColumnCompare(a interface{}, b interface{}) (int, error) {
if a == nil && b == nil {
return 0, nil
} else if b == nil {
return 1, nil
} else if a == nil {
return -1, nil
}
// a and b both not nil
if a == plan.MinNotNullVal && b == plan.MinNotNullVal {
return 0, nil
} else if b == plan.MinNotNullVal {
return 1, nil
} else if a == plan.MinNotNullVal {
return -1, nil
}
// a and b both not min value
if a == plan.MaxVal && b == plan.MaxVal {
return 0, nil
} else if a == plan.MaxVal {
return 1, nil
} else if b == plan.MaxVal {
return -1, nil
}
n, err := types.Compare(a, b)
if err != nil {
return 0, errors.Trace(err)
}
return n, nil
}
开发者ID:lovedboy,项目名称:tidb,代码行数:34,代码来源:executor.go
示例15: Update
// Update implements AggregationFunction interface.
func (mmf *maxMinFunction) Update(row []types.Datum, groupKey []byte, ectx context.Context) error {
ctx := mmf.getContext(groupKey)
if len(mmf.Args) != 1 {
return errors.New("Wrong number of args for AggFuncMaxMin")
}
a := mmf.Args[0]
value, err := a.Eval(row, ectx)
if err != nil {
return errors.Trace(err)
}
if !ctx.Evaluated {
ctx.Value = value.GetValue()
}
if value.GetValue() == nil {
return nil
}
var c int
c, err = types.Compare(ctx.Value, value.GetValue())
if err != nil {
return errors.Trace(err)
}
if (mmf.isMax && c == -1) || (!mmf.isMax && c == 1) {
ctx.Value = value.GetValue()
}
ctx.Evaluated = true
return nil
}
开发者ID:duzhanyuan,项目名称:tidb,代码行数:28,代码来源:aggregation.go
示例16: buildTableRanges
func (r *rangeBuilder) buildTableRanges(rangePoints []rangePoint) []TableRange {
tableRanges := make([]TableRange, 0, len(rangePoints)/2)
for i := 0; i < len(rangePoints); i += 2 {
startPoint := rangePoints[i]
if startPoint.value == nil || startPoint.value == MinNotNullVal {
startPoint.value = math.MinInt64
}
startInt, err := types.ToInt64(startPoint.value)
if err != nil {
r.err = errors.Trace(err)
return tableRanges
}
cmp, err := types.Compare(startInt, startPoint.value)
if err != nil {
r.err = errors.Trace(err)
return tableRanges
}
if cmp < 0 || (cmp == 0 && startPoint.excl) {
startInt++
}
endPoint := rangePoints[i+1]
if endPoint.value == nil {
endPoint.value = math.MinInt64
} else if endPoint.value == MaxVal {
endPoint.value = math.MaxInt64
}
endInt, err := types.ToInt64(endPoint.value)
if err != nil {
r.err = errors.Trace(err)
return tableRanges
}
cmp, err = types.Compare(endInt, endPoint.value)
if err != nil {
r.err = errors.Trace(err)
return tableRanges
}
if cmp > 0 || (cmp == 0 && endPoint.excl) {
endInt--
}
if startInt > endInt {
continue
}
tableRanges = append(tableRanges, TableRange{LowVal: startInt, HighVal: endInt})
}
return tableRanges
}
开发者ID:52Jolynn,项目名称:tidb,代码行数:46,代码来源:range.go
示例17: isPointLookup
func (r *indexPlan) isPointLookup(span *indexSpan) bool {
equalOp := span.lowVal == span.highVal && !span.lowExclude && !span.highExclude
if !equalOp || !r.unique || span.lowVal == nil {
return false
}
n, err := types.Compare(span.seekVal, span.lowVal)
if err != nil {
return false
}
return n == 0
}
开发者ID:huozhe3136,项目名称:tidb,代码行数:11,代码来源:index.go
示例18: isPointLookup
func (r *indexPlan) isPointLookup(span *indexSpan) bool {
if span.lowExclude || span.highExclude || span.lowVal == nil || !r.unique {
return false
}
n, err := types.Compare(span.seekVal, span.highVal)
if err != nil {
return false
}
// 'seekVal==highVal' means that 'seekVal==lowVal && lowVal==highVal'
return n == 0
}
开发者ID:lovedboy,项目名称:tidb,代码行数:11,代码来源:index.go
示例19: builtinNullIf
// See https://dev.mysql.com/doc/refman/5.7/en/control-flow-functions.html#function_nullif
func builtinNullIf(args []interface{}, m map[interface{}]interface{}) (interface{}, error) {
// nullif(expr1, expr2)
// returns null if expr1 = expr2 is true, otherwise returns expr1
v1 := args[0]
v2 := args[1]
if types.IsNil(v1) || types.IsNil(v2) {
return v1, nil
}
if n, err := types.Compare(v1, v2); err != nil || n == 0 {
return nil, err
}
return v1, nil
}
开发者ID:lovedboy,项目名称:tidb,代码行数:17,代码来源:control.go
示例20: Less
// Less implements sort.Interface Less interface.
func (t *orderByTable) Less(i, j int) bool {
for index, asc := range t.Ascs {
v1 := t.Rows[i].Key[index]
v2 := t.Rows[j].Key[index]
ret := types.Compare(v1, v2)
if !asc {
ret = -ret
}
if ret < 0 {
return true
} else if ret > 0 {
return false
}
}
return false
}
开发者ID:npk,项目名称:tidb,代码行数:20,代码来源:orderby.go
注:本文中的github.com/pingcap/tidb/util/types.Compare函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论