本文整理汇总了Golang中github.com/pingcap/tidb/ast.BinaryOperationExpr.GetType方法的典型用法代码示例。如果您正苦于以下问题:Golang BinaryOperationExpr.GetType方法的具体用法?Golang BinaryOperationExpr.GetType怎么用?Golang BinaryOperationExpr.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/ast.BinaryOperationExpr
的用法示例。
在下文中一共展示了BinaryOperationExpr.GetType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleLogicOperation
func (e *Evaluator) handleLogicOperation(o *ast.BinaryOperationExpr) bool {
leftVal, err := types.Convert(o.L.GetValue(), o.GetType())
if err != nil {
e.err = err
return false
}
rightVal, err := types.Convert(o.R.GetValue(), o.GetType())
if err != nil {
e.err = err
return false
}
if leftVal == nil || rightVal == nil {
o.SetValue(nil)
return true
}
var boolVal bool
switch o.Op {
case opcode.AndAnd:
boolVal = leftVal != zeroI64 && rightVal != zeroI64
case opcode.OrOr:
boolVal = leftVal != zeroI64 || rightVal != zeroI64
case opcode.LogicXor:
boolVal = (leftVal == zeroI64 && rightVal != zeroI64) || (leftVal != zeroI64 && rightVal == zeroI64)
default:
panic("should never happen")
}
if boolVal {
o.SetValue(oneI64)
} else {
o.SetValue(zeroI64)
}
return true
}
示例2: binaryOperation
func (e *Evaluator) binaryOperation(o *ast.BinaryOperationExpr) bool {
// all operands must have same column.
if e.err = hasSameColumnCount(o.L, o.R); e.err != nil {
return false
}
// row constructor only supports comparison operation.
switch o.Op {
case opcode.LT, opcode.LE, opcode.GE, opcode.GT, opcode.EQ, opcode.NE, opcode.NullEQ:
default:
if !checkAllOneColumn(o.L) {
e.err = errors.Errorf("Operand should contain 1 column(s)")
return false
}
}
leftVal, err := types.Convert(o.L.GetValue(), o.GetType())
if err != nil {
e.err = err
return false
}
rightVal, err := types.Convert(o.R.GetValue(), o.GetType())
if err != nil {
e.err = err
return false
}
if leftVal == nil || rightVal == nil {
o.SetValue(nil)
return true
}
switch o.Op {
case opcode.AndAnd, opcode.OrOr, opcode.LogicXor:
return e.handleLogicOperation(o)
case opcode.LT, opcode.LE, opcode.GE, opcode.GT, opcode.EQ, opcode.NE, opcode.NullEQ:
return e.handleComparisonOp(o)
case opcode.RightShift, opcode.LeftShift, opcode.And, opcode.Or, opcode.Xor:
// TODO: MySQL doesn't support and not, we should remove it later.
return e.handleBitOp(o)
case opcode.Plus, opcode.Minus, opcode.Mod, opcode.Div, opcode.Mul, opcode.IntDiv:
return e.handleArithmeticOp(o)
default:
panic("should never happen")
}
}