Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: remove redundant "errors.Trace()" in "expression" package #8609

Merged
merged 2 commits into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions expression/aggregation/aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package aggregation
import (
"bytes"
"fmt"

"github.com/pingcap/errors"
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/charset"
Expand Down Expand Up @@ -63,7 +64,7 @@ func NewDistAggFunc(expr *tipb.Expr, fieldTps []*types.FieldType, sc *stmtctx.St
for _, child := range expr.Children {
arg, err := expression.PBToExpr(child, fieldTps, sc)
if err != nil {
return nil, errors.Trace(err)
return nil, err
}
args = append(args, arg)
}
Expand Down Expand Up @@ -152,23 +153,23 @@ func (af *aggFunction) updateSum(sc *stmtctx.StatementContext, evalCtx *AggEvalu
a := af.Args[0]
value, err := a.Eval(row)
if err != nil {
return errors.Trace(err)
return err
}
if value.IsNull() {
return nil
}
if af.HasDistinct {
d, err1 := evalCtx.DistinctChecker.Check([]types.Datum{value})
if err1 != nil {
return errors.Trace(err1)
return err1
}
if !d {
return nil
}
}
evalCtx.Value, err = calculateSum(sc, evalCtx.Value, value)
if err != nil {
return errors.Trace(err)
return err
}
evalCtx.Count++
return nil
Expand Down
13 changes: 6 additions & 7 deletions expression/aggregation/avg.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package aggregation

import (
"github.com/cznic/mathutil"
"github.com/pingcap/errors"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/sessionctx/stmtctx"
Expand All @@ -31,18 +30,18 @@ func (af *avgFunction) updateAvg(sc *stmtctx.StatementContext, evalCtx *AggEvalu
a := af.Args[1]
value, err := a.Eval(row)
if err != nil {
return errors.Trace(err)
return err
}
if value.IsNull() {
return nil
}
evalCtx.Value, err = calculateSum(sc, evalCtx.Value, value)
if err != nil {
return errors.Trace(err)
return err
}
count, err := af.Args[0].Eval(row)
if err != nil {
return errors.Trace(err)
return err
}
evalCtx.Count += count.GetInt64()
return nil
Expand All @@ -66,7 +65,7 @@ func (af *avgFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.Statement
case DedupMode:
panic("DedupMode is not supported now.")
}
return errors.Trace(err)
return err
}

// GetResult implements Aggregation interface.
Expand All @@ -81,13 +80,13 @@ func (af *avgFunction) GetResult(evalCtx *AggEvaluateContext) (d types.Datum) {
y := types.NewDecFromInt(evalCtx.Count)
to := new(types.MyDecimal)
err := types.DecimalDiv(x, y, to, types.DivFracIncr)
terror.Log(errors.Trace(err))
terror.Log(err)
frac := af.RetTp.Decimal
if frac == -1 {
frac = mysql.MaxDecimalScale
}
err = to.Round(to, mathutil.Min(frac, mysql.MaxDecimalScale), types.ModeHalfEven)
terror.Log(errors.Trace(err))
terror.Log(err)
d.SetMysqlDecimal(to)
}
return
Expand Down
5 changes: 2 additions & 3 deletions expression/aggregation/bit_and.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package aggregation
import (
"math"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
Expand All @@ -41,15 +40,15 @@ func (bf *bitAndFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.Statem
a := bf.Args[0]
value, err := a.Eval(row)
if err != nil {
return errors.Trace(err)
return err
}
if !value.IsNull() {
if value.Kind() == types.KindUint64 {
evalCtx.Value.SetUint64(evalCtx.Value.GetUint64() & value.GetUint64())
} else {
int64Value, err := value.ToInt64(sc)
if err != nil {
return errors.Trace(err)
return err
}
evalCtx.Value.SetUint64(evalCtx.Value.GetUint64() & uint64(int64Value))
}
Expand Down
5 changes: 2 additions & 3 deletions expression/aggregation/bit_or.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package aggregation

import (
"github.com/pingcap/errors"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
Expand All @@ -39,15 +38,15 @@ func (bf *bitOrFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.Stateme
a := bf.Args[0]
value, err := a.Eval(row)
if err != nil {
return errors.Trace(err)
return err
}
if !value.IsNull() {
if value.Kind() == types.KindUint64 {
evalCtx.Value.SetUint64(evalCtx.Value.GetUint64() | value.GetUint64())
} else {
int64Value, err := value.ToInt64(sc)
if err != nil {
return errors.Trace(err)
return err
}
evalCtx.Value.SetUint64(evalCtx.Value.GetUint64() | uint64(int64Value))
}
Expand Down
5 changes: 2 additions & 3 deletions expression/aggregation/bit_xor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package aggregation

import (
"github.com/pingcap/errors"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
Expand All @@ -39,15 +38,15 @@ func (bf *bitXorFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.Statem
a := bf.Args[0]
value, err := a.Eval(row)
if err != nil {
return errors.Trace(err)
return err
}
if !value.IsNull() {
if value.Kind() == types.KindUint64 {
evalCtx.Value.SetUint64(evalCtx.Value.GetUint64() ^ value.GetUint64())
} else {
int64Value, err := value.ToInt64(sc)
if err != nil {
return errors.Trace(err)
return err
}
evalCtx.Value.SetUint64(evalCtx.Value.GetUint64() ^ uint64(int64Value))
}
Expand Down
10 changes: 5 additions & 5 deletions expression/aggregation/concat.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ func (cf *concatFunction) initSeparator(sc *stmtctx.StatementContext, row chunk.
sepArg := cf.Args[len(cf.Args)-1]
sepDatum, err := sepArg.Eval(row)
if err != nil {
return errors.Trace(err)
return err
}
if sepDatum.IsNull() {
return errors.Errorf("Invalid separator argument.")
}
cf.separator, err = sepDatum.ToString()
return errors.Trace(err)
return err
}

// Update implements Aggregation interface.
Expand All @@ -63,7 +63,7 @@ func (cf *concatFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.Statem
if !cf.sepInited {
err := cf.initSeparator(sc, row)
if err != nil {
return errors.Trace(err)
return err
}
cf.sepInited = true
}
Expand All @@ -72,7 +72,7 @@ func (cf *concatFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.Statem
for i, length := 0, len(cf.Args)-1; i < length; i++ {
value, err := cf.Args[i].Eval(row)
if err != nil {
return errors.Trace(err)
return err
}
if value.IsNull() {
return nil
Expand All @@ -82,7 +82,7 @@ func (cf *concatFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.Statem
if cf.HasDistinct {
d, err := evalCtx.DistinctChecker.Check(datumBuf)
if err != nil {
return errors.Trace(err)
return err
}
if !d {
return nil
Expand Down
5 changes: 2 additions & 3 deletions expression/aggregation/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package aggregation

import (
"github.com/pingcap/errors"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
Expand All @@ -33,7 +32,7 @@ func (cf *countFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.Stateme
for _, a := range cf.Args {
value, err := a.Eval(row)
if err != nil {
return errors.Trace(err)
return err
}
if value.IsNull() {
return nil
Expand All @@ -48,7 +47,7 @@ func (cf *countFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.Stateme
if cf.HasDistinct {
d, err := evalCtx.DistinctChecker.Check(datumBuf)
if err != nil {
return errors.Trace(err)
return err
}
if !d {
return nil
Expand Down
2 changes: 1 addition & 1 deletion expression/aggregation/first_row.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (ff *firstRowFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.Stat
}
value, err := ff.Args[0].Eval(row)
if err != nil {
return errors.Trace(err)
return err
}
evalCtx.Value = types.CopyDatum(value)
evalCtx.GotFirstRow = true
Expand Down
5 changes: 2 additions & 3 deletions expression/aggregation/max_min.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package aggregation

import (
"github.com/pingcap/errors"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
Expand All @@ -40,7 +39,7 @@ func (mmf *maxMinFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.State
a := mmf.Args[0]
value, err := a.Eval(row)
if err != nil {
return errors.Trace(err)
return err
}
if evalCtx.Value.IsNull() {
evalCtx.Value = *(&value).Copy()
Expand All @@ -51,7 +50,7 @@ func (mmf *maxMinFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.State
var c int
c, err = evalCtx.Value.CompareDatum(sc, &value)
if err != nil {
return errors.Trace(err)
return err
}
if (mmf.isMax && c == -1) || (!mmf.isMax && c == 1) {
evalCtx.Value = *(&value).Copy()
Expand Down
4 changes: 2 additions & 2 deletions expression/aggregation/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (d *distinctChecker) Check(values []types.Datum) (bool, error) {
var err error
d.key, err = codec.EncodeValue(d.sc, d.key, values...)
if err != nil {
return false, errors.Trace(err)
return false, err
}
d.vals = d.existingKeys.Get(d.key, d.vals[:0])
if len(d.vals) > 0 {
Expand Down Expand Up @@ -78,7 +78,7 @@ func calculateSum(sc *stmtctx.StatementContext, sum, v types.Datum) (data types.
}

if err != nil {
return data, errors.Trace(err)
return data, err
}
if data.IsNull() {
return sum, nil
Expand Down
Loading