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

support pushing bitwise operators and LogicXor down to kv #1846

Merged
merged 12 commits into from
Oct 27, 2016

Conversation

XuHuaiyu
Copy link
Contributor

This commit

  1. splits ./distsql/xeval/eval.go into some small files to make the function of every file more explicit.
  2. supports pushing bitwise operators and LogicXor down to kv.
    PTAL @hanfei1991 @coocood @shenli @zimulala @tiancaiamao

@XuHuaiyu XuHuaiyu changed the title support pushing bitwise operators and LogicXor down to kv [DNM]support pushing bitwise operators and LogicXor down to kv Oct 19, 2016
@XuHuaiyu
Copy link
Contributor Author

I split eval.go into five small files to classify different type of operators.
eval_bit_ops.go is a new file.
I didn't modify the other four files, except for adding a evalXXX() function in every file to classify specific ops.

@hanfei1991 @coocood @shenli @zimulala @tiancaiamao

@XuHuaiyu XuHuaiyu force-pushed the xhy/push_bit_ops_down branch from ca90c6a to fddb483 Compare October 19, 2016 10:18
if expr.GetTp() == tipb.ExprType_BitNeg {
var result types.Datum
if len(expr.Children) != 1 {
err := ErrInvalid.Gen("need 2 operands but got %d", len(expr.Children))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need 1 operand ...


func (e *Evaluator) evalIn(expr *tipb.Expr) (types.Datum, error) {
if len(expr.Children) != 2 {
return types.Datum{}, ErrInvalid.Gen("IN need 2 operand, got %d", len(expr.Children))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

operand -> operands

return
}

// if any is not integer, we round the operands and then use uint64 to calculate.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If either...

@XuHuaiyu XuHuaiyu force-pushed the xhy/push_bit_ops_down branch from dde3894 to 561ad6d Compare October 20, 2016 06:55
@@ -395,3 +395,207 @@ func ComputeIntDiv(a, b Datum) (d Datum, err error) {
d.SetInt64(iVal)
return d, nil
}

// decimal2RoundUint convert a MyDecimal to a uint64 after rounding.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a uint64 -> an uint64

return
}

// if either is not integer, we round the operands and then use uint64 to calculate.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change all if to If

return d, nil
}

// ComputeLeftShift computes the result of a >> b.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a useless blank in a >> b

@XuHuaiyu XuHuaiyu changed the title [DNM]support pushing bitwise operators and LogicXor down to kv support pushing bitwise operators and LogicXor down to kv Oct 21, 2016
if expr.GetTp() == tipb.ExprType_BitNeg {
var result types.Datum
if len(expr.Children) != 1 {
err := ErrInvalid.Gen("need 1 operands but got %d", len(expr.Children))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 operand not operands

@hanfei1991
Copy link
Member

rest LGTM

return e.evalNot(expr)
case tipb.ExprType_In:
return e.evalIn(expr)
// data type.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/data/Data or remove .
The same as line57, line62, line65, line69 and the same as some comments in plan_test.go

@XuHuaiyu
Copy link
Contributor Author

PTAL
@zimulala @hanfei1991 @coocood

@XuHuaiyu XuHuaiyu changed the title support pushing bitwise operators and LogicXor down to kv [DNM]support pushing bitwise operators and LogicXor down to kv Oct 24, 2016
@XuHuaiyu
Copy link
Contributor Author

I'll rewrite this PR after another PRs have been merged.

…h_bit_ops_down

Conflicts:
	distsql/xeval/eval.go
	distsql/xeval/eval_compare_ops.go
	distsql/xeval/eval_logic_ops.go
	plan/expr_to_pb.go

`:q!
�:q!
@XuHuaiyu XuHuaiyu force-pushed the xhy/push_bit_ops_down branch from 0597580 to a547d0d Compare October 25, 2016 17:25
@XuHuaiyu XuHuaiyu changed the title [DNM]support pushing bitwise operators and LogicXor down to kv support pushing bitwise operators and LogicXor down to kv Oct 25, 2016
@XuHuaiyu
Copy link
Contributor Author

PTAL @hanfei1991 @coocood @shenli @zimulala @tiancaiamao
This commit only involves logical changes.

if expr.GetTp() == tipb.ExprType_BitNeg {
var result types.Datum
if len(expr.Children) != 1 {
err := ErrInvalid.Gen("need 1 operand but got %d", len(expr.Children))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add operator name in the error message.

@shenli
Copy link
Member

shenli commented Oct 26, 2016

@hanfei1991 PTAL

@XuHuaiyu XuHuaiyu force-pushed the xhy/push_bit_ops_down branch from 3a1d2de to 5f8ee14 Compare October 26, 2016 02:04
@hanfei1991
Copy link
Member

LGTM

@XuHuaiyu
Copy link
Contributor Author

@coocood PTAL

Copy link
Member

@shenli shenli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM

}
return types.ComputeBitNeg(a)
}
var result types.Datum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to the beginning and remove line 24.

return
}
// If either is not integer, we round the operands and then use uint64 to calculate.
x, err := a.ToDecimal()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a function to replace the following code block, then we could save a lot of works in ComputeXXX.

…h_bit_ops_down

Conflicts:
	distsql/xeval/eval.go
	plan/expr_to_pb.go

�:q!
@XuHuaiyu
Copy link
Contributor Author

PTAL @shenli

Copy link
Member

@shenli shenli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM

return d, errors.Trace(err)
}

y, err := b.ToDecimal()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use convertNonInt2RoundUint64 instead.

return d, errors.Trace(err)
}

uintX, err := decimal2RoundUint(x)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convertNonInt2RoundUint64

@XuHuaiyu
Copy link
Contributor Author

@shenli PTAL

@shenli
Copy link
Member

shenli commented Oct 27, 2016

LGTM

@XuHuaiyu XuHuaiyu merged commit d38cc3f into master Oct 27, 2016
@XuHuaiyu XuHuaiyu deleted the xhy/push_bit_ops_down branch October 27, 2016 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants