-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support pushing bitwise operators and LogicXor down to kv (#1846)
- Loading branch information
Showing
10 changed files
with
471 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2016 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package xeval | ||
|
||
import ( | ||
"github.com/juju/errors" | ||
"github.com/pingcap/tidb/util/types" | ||
"github.com/pingcap/tipb/go-tipb" | ||
) | ||
|
||
func (e *Evaluator) evalBitOps(expr *tipb.Expr) (types.Datum, error) { | ||
var result types.Datum | ||
if expr.GetTp() == tipb.ExprType_BitNeg { | ||
if len(expr.Children) != 1 { | ||
err := ErrInvalid.Gen("BitNeg(~) need 1 operand but got %d", len(expr.Children)) | ||
return result, err | ||
} | ||
operand, err := e.Eval(expr.Children[0]) | ||
if err != nil { | ||
return types.Datum{}, errors.Trace(err) | ||
} | ||
a, err := types.CoerceArithmetic(operand) | ||
if err != nil { | ||
return result, errors.Trace(err) | ||
} | ||
return types.ComputeBitNeg(a) | ||
} | ||
left, right, err := e.evalTwoChildren(expr) | ||
if err != nil { | ||
return result, errors.Trace(err) | ||
} | ||
return ComputeBit(expr.GetTp(), left, right) | ||
} | ||
|
||
// ComputeBit computes the bitwise operation on two datums. | ||
func ComputeBit(op tipb.ExprType, left, right types.Datum) (types.Datum, error) { | ||
var result types.Datum | ||
a, err := types.CoerceArithmetic(left) | ||
if err != nil { | ||
return result, errors.Trace(err) | ||
} | ||
|
||
b, err := types.CoerceArithmetic(right) | ||
if err != nil { | ||
return result, errors.Trace(err) | ||
} | ||
a, b, err = types.CoerceDatum(a, b) | ||
if err != nil { | ||
return result, errors.Trace(err) | ||
} | ||
if a.IsNull() || b.IsNull() { | ||
return result, nil | ||
} | ||
|
||
switch op { | ||
case tipb.ExprType_BitAnd: | ||
return types.ComputeBitAnd(a, b) | ||
case tipb.ExprType_BitOr: | ||
return types.ComputeBitOr(a, b) | ||
case tipb.ExprType_BitXor: | ||
return types.ComputeBitXor(a, b) | ||
case tipb.ExprType_LeftShift: | ||
return types.ComputeLeftShift(a, b) | ||
case tipb.ExprType_RighShift: | ||
return types.ComputeRightShift(a, b) | ||
default: | ||
return result, errors.Errorf("Unknown binop type: %v", op) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.