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

fix bug in parser and expression #7

Merged
merged 1 commit into from
Oct 26, 2019
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
10 changes: 5 additions & 5 deletions expression/builtin_arithmetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,15 +670,15 @@ func (c *arithmeticIntDivideFunctionClass) GetFunction(ctx sessionctx.Context, a
bf.Tp.Flag |= mysql.UnsignedFlag
}
sig := &builtinArithmeticIntDivideIntSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_IntDivideInt)
sig.SetPbCode(tipb.ScalarFuncSig_IntDivideInt)
return sig, nil
}
bf := NewBaseBuiltinFuncWithTp(ctx, args, types.ETInt, types.ETDecimal, types.ETDecimal)
if mysql.HasUnsignedFlag(lhsTp.Flag) || mysql.HasUnsignedFlag(rhsTp.Flag) {
bf.Tp.Flag |= mysql.UnsignedFlag
}
sig := &builtinArithmeticIntDivideDecimalSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_IntDivideDecimal)
sig.SetPbCode(tipb.ScalarFuncSig_IntDivideDecimal)
return sig, nil
}

Expand Down Expand Up @@ -836,7 +836,7 @@ func (c *arithmeticModFunctionClass) GetFunction(ctx sessionctx.Context, args []
bf.Tp.Flag |= mysql.UnsignedFlag
}
sig := &builtinArithmeticModRealSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_ModReal)
sig.SetPbCode(tipb.ScalarFuncSig_ModReal)
return sig, nil
} else if lhsEvalTp == types.ETDecimal || rhsEvalTp == types.ETDecimal {
bf := NewBaseBuiltinFuncWithTp(ctx, args, types.ETDecimal, types.ETDecimal, types.ETDecimal)
Expand All @@ -845,15 +845,15 @@ func (c *arithmeticModFunctionClass) GetFunction(ctx sessionctx.Context, args []
bf.Tp.Flag |= mysql.UnsignedFlag
}
sig := &builtinArithmeticModDecimalSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_ModDecimal)
sig.SetPbCode(tipb.ScalarFuncSig_ModDecimal)
return sig, nil
} else {
bf := NewBaseBuiltinFuncWithTp(ctx, args, types.ETInt, types.ETInt, types.ETInt)
if mysql.HasUnsignedFlag(lhsTp.Flag) {
bf.Tp.Flag |= mysql.UnsignedFlag
}
sig := &builtinArithmeticModIntSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_ModInt)
sig.SetPbCode(tipb.ScalarFuncSig_ModInt)
return sig, nil
}
}
Expand Down
6 changes: 3 additions & 3 deletions expression/builtin_arithmetic_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ func (b *builtinArithmeticMultiplyIntUnsignedSig) vectorized() bool {
}

func (b *builtinArithmeticMultiplyIntUnsignedSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalInt(b.ctx, input, result); err != nil {
if err := b.Args[0].VecEvalInt(b.Ctx, input, result); err != nil {
return err
}
n := input.NumRows()
Expand All @@ -597,7 +597,7 @@ func (b *builtinArithmeticMultiplyIntUnsignedSig) vecEvalInt(input *chunk.Chunk,
}
defer b.bufAllocator.put(buf)

if err := b.args[1].VecEvalInt(b.ctx, input, buf); err != nil {
if err := b.Args[1].VecEvalInt(b.Ctx, input, buf); err != nil {
return err
}

Expand All @@ -612,7 +612,7 @@ func (b *builtinArithmeticMultiplyIntUnsignedSig) vecEvalInt(input *chunk.Chunk,

res = x[i] * y[i]
if x[i] != 0 && res/x[i] != y[i] {
return types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s * %s)", b.args[0].String(), b.args[1].String()))
return types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s * %s)", b.Args[0].String(), b.Args[1].String()))
}
x[i] = res
}
Expand Down
12 changes: 6 additions & 6 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,30 +320,30 @@ func (b *builtinCastIntAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk.
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalInt(b.ctx, input, buf); err != nil {
if err := b.Args[0].VecEvalInt(b.Ctx, input, buf); err != nil {
return err
}

result.ResizeTime(n, false)
result.MergeNulls(buf)
times := result.Times()
i64s := buf.Int64s()
stmt := b.ctx.GetSessionVars().StmtCtx
fsp := int8(b.tp.Decimal)
stmt := b.Ctx.GetSessionVars().StmtCtx
fsp := int8(b.Tp.Decimal)
for i := 0; i < n; i++ {
if buf.IsNull(i) {
continue
}
tm, err := types.ParseTimeFromNum(stmt, i64s[i], b.tp.Tp, fsp)
tm, err := types.ParseTimeFromNum(stmt, i64s[i], b.Tp.Tp, fsp)
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
if err = handleInvalidTimeError(b.Ctx, err); err != nil {
return err
}
result.SetNull(i, true)
continue
}
times[i] = tm
if b.tp.Tp == mysql.TypeDate {
if b.Tp.Tp == mysql.TypeDate {
// Truncate hh:mm:ss part if the type is Date.
times[i].Time = types.FromDate(tm.Time.Year(), tm.Time.Month(), tm.Time.Day(), 0, 0, 0, 0)
}
Expand Down
16 changes: 8 additions & 8 deletions expression/builtin_json_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,19 @@ func (b *builtinJSONObjectSig) vectorized() bool {

func (b *builtinJSONObjectSig) vecEvalJSON(input *chunk.Chunk, result *chunk.Column) error {
nr := input.NumRows()
if len(b.args)&1 == 1 {
if len(b.Args)&1 == 1 {
err := ErrIncorrectParameterCount.GenWithStackByArgs(ast.JSONObject)
return err
}

jsons := make([]map[string]interface{}, nr)
for i := 0; i < nr; i++ {
jsons[i] = make(map[string]interface{}, len(b.args)>>1)
jsons[i] = make(map[string]interface{}, len(b.Args)>>1)
}

argBuffers := make([]*chunk.Column, len(b.args))
argBuffers := make([]*chunk.Column, len(b.Args))
var err error
for i := 0; i < len(b.args); i++ {
for i := 0; i < len(b.Args); i++ {
if i&1 == 0 {
if argBuffers[i], err = b.bufAllocator.get(types.ETString, nr); err != nil {
return err
Expand All @@ -181,7 +181,7 @@ func (b *builtinJSONObjectSig) vecEvalJSON(input *chunk.Chunk, result *chunk.Col
b.bufAllocator.put(buf)
}(argBuffers[i])

if err = b.args[i].VecEvalString(b.ctx, input, argBuffers[i]); err != nil {
if err = b.Args[i].VecEvalString(b.Ctx, input, argBuffers[i]); err != nil {
return err
}
} else {
Expand All @@ -192,14 +192,14 @@ func (b *builtinJSONObjectSig) vecEvalJSON(input *chunk.Chunk, result *chunk.Col
b.bufAllocator.put(buf)
}(argBuffers[i])

if err = b.args[i].VecEvalJSON(b.ctx, input, argBuffers[i]); err != nil {
if err = b.Args[i].VecEvalJSON(b.Ctx, input, argBuffers[i]); err != nil {
return err
}
}
}

result.ReserveJSON(nr)
for i := 0; i < len(b.args); i++ {
for i := 0; i < len(b.Args); i++ {
if i&1 == 1 {
keyCol := argBuffers[i-1]
valueCol := argBuffers[i]
Expand Down Expand Up @@ -329,7 +329,7 @@ func (b *builtinJSONUnquoteSig) vecEvalString(input *chunk.Chunk, result *chunk.
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalJSON(b.ctx, input, buf); err != nil {
if err := b.Args[0].VecEvalJSON(b.Ctx, input, buf); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion expression/builtin_time_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ func (b *builtinSecondSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column)
return err
}
defer b.bufAllocator.put(buf)
if err = b.args[0].VecEvalDuration(b.ctx, input, buf); err != nil {
if err = b.Args[0].VecEvalDuration(b.Ctx, input, buf); err != nil {
return err
}

Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548
github.com/cznic/sortutil v0.0.0-20150617083342-4c7342852e65
github.com/davecgh/go-spew v1.1.1
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
Expand Down Expand Up @@ -83,3 +84,5 @@ require (
)

go 1.13

replace github.com/pingcap/parser => github.com/wph95/parser v0.0.0-20191026144906-452a5e63db22
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb
github.com/urfave/negroni v0.3.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/vektah/goparsify v0.0.0-20180611020250-3e20a3b9244a h1:kjtLFYYtOh6EJz4svAJjY4apt9SJFQxe23e0mzTnlng=
github.com/vektah/goparsify v0.0.0-20180611020250-3e20a3b9244a/go.mod h1:DSfslQMj3gv774kof/dg5pwh62XUjimkRBoF2DgdyaY=
github.com/wph95/parser v0.0.0-20191026144119-08a4ef6b0dfd h1:fTMV1YxJuu82EkDOTqwfDBFFzZkG1UpXZ3qi+TTCYNs=
github.com/wph95/parser v0.0.0-20191026144119-08a4ef6b0dfd/go.mod h1:QzHD0t19d+m/hPD328+lDpBkKwX/UqXGY+ZP6Kk9JCk=
github.com/wph95/parser v0.0.0-20191026144906-452a5e63db22 h1:ueuGfjYancts9k28SpxzCx4i8FqxPcxcP0+FjLsJU6c=
github.com/wph95/parser v0.0.0-20191026144906-452a5e63db22/go.mod h1:QzHD0t19d+m/hPD328+lDpBkKwX/UqXGY+ZP6Kk9JCk=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/yookoala/realpath v1.0.0/go.mod h1:gJJMA9wuX7AcqLy1+ffPatSCySA1FQ2S8Ya9AIoYBpE=
Expand Down