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, plan: support builtin aggregation function 'bit_or' #5145

Merged
merged 33 commits into from
Dec 19, 2017

Conversation

spongedu
Copy link
Contributor

support builtin aggregation function 'bit_or'

@sre-bot
Copy link
Contributor

sre-bot commented Nov 18, 2017

Hi contributor, thanks for your PR.

This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically.

@shenli
Copy link
Member

shenli commented Nov 18, 2017

@spongedu Thanks!
Please fix CI.

@zz-jason
Copy link
Member

/run-all-tests

@zz-jason
Copy link
Member

/run-sqllogic-test

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason zz-jason added contribution This PR is from a community contributor. status/LGT1 Indicates that a PR has LGTM 1. labels Nov 20, 2017
@zz-jason zz-jason added this to the 1.1 milestone Nov 20, 2017
@@ -78,7 +78,7 @@ func (c *CopClient) supportExpr(exprType tipb.ExprType) bool {
case tipb.ExprType_Case, tipb.ExprType_If, tipb.ExprType_IfNull, tipb.ExprType_Coalesce:
return true
// aggregate functions.
case tipb.ExprType_Count, tipb.ExprType_First, tipb.ExprType_Max, tipb.ExprType_Min, tipb.ExprType_Sum, tipb.ExprType_Avg:
case tipb.ExprType_Count, tipb.ExprType_First, tipb.ExprType_Max, tipb.ExprType_Min, tipb.ExprType_Sum, tipb.ExprType_Avg, tipb.ExprType_Agg_BitOr:
Copy link
Member

Choose a reason for hiding this comment

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

TiKV doesn't support ExprType_Agg_BitOr.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shenli how about this:

  • Step1: disable FinalMode for BIT_OR so that it's not calculated in TIKV.
  • Step2: take another pr in TiKV to support BIT_OR IN TIKV.
  • Step3: re-enable FinalMode for BIT_OR

Copy link
Member

Choose a reason for hiding this comment

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

If the agg is bit_or, we return c.store.mock so as to push it to mock tikv instead of real tikv.

Copy link
Contributor Author

@spongedu spongedu Nov 23, 2017

Choose a reason for hiding this comment

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

@hanfei1991

  1. you mean that BIT_OR is never push down to TiKV, even in real clustered environment?
  2. This pr seems works ok with mock-tikv
  3. I think it's still necessary to support BIT_OR in TiKV anyway

what do you think

Copy link
Member

Choose a reason for hiding this comment

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

After tikv has supported this aggregate function, we can remove this check. This is only a protection mechanism.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hanfei1991 PTAL. I disabled FinalMode for aggregation BIT_OR. This check seems can be removed

Conflicts:
	ast/functions.go
	expression/aggregation/agg_to_pb.go
	expression/aggregation/aggregation.go
	expression/integration_test.go
	plan/physical_plans.go
@zz-jason
Copy link
Member

zz-jason commented Dec 7, 2017

/run-all-tests

@zz-jason
Copy link
Member

zz-jason commented Dec 7, 2017

/run-integration-common-test

ft := types.NewFieldType(mysql.TypeLonglong)
ft.Flen = 21
types.SetBinChsClnFlag(ft)
ft.Flag |= mysql.UnsignedFlag
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to add the flag of not null?

mysql> select bit_or(b) from t;
Field   1:  `bit_or(b)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       LONGLONG
Collation:  binary (63)
Length:     21
Max_length: 1
Decimals:   0
Flags:      NOT_NULL UNSIGNED BINARY NUM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zimulala yes. The same for BIT_AND and BIT_XOR.

// GetResult implements Aggregation interface.
func (bf *bitOrFunction) GetResult(ctx *AggEvaluateContext) (d types.Datum) {
d.SetUint64(ctx.Value.GetUint64())
return d
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not return "ctx.Value" directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By cursoriness.... Will fix

if ctx.Value.IsNull() {
ctx.Value.SetUint64(0)
}
v := row.GetUint64(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why here is 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zimulala you mean the 0 in line 83? what's wrong with it ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep. I don't know why the column index is 0.

Copy link
Contributor

@zimulala zimulala Dec 8, 2017

Choose a reason for hiding this comment

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

Besides, can we handle the operation of Update use this same way in different modes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zimulala yes, for bit_or, bit_and, bit_xor, FinalMode and Complete mode seem act the same , I'll refine here.

@spongedu
Copy link
Contributor Author

spongedu commented Dec 8, 2017

@zimulala merge FinalMode and CompleteMode in Update. 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


// CalculateDefaultValue implements Aggregation interface.
func (bf *bitOrFunction) CalculateDefaultValue(schema *expression.Schema, ctx context.Context) (d types.Datum, valid bool) {
arg := bf.Args[0]
Copy link
Member

Choose a reason for hiding this comment

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

Should we also check len(bf.Args[0]) as line 62?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shenli actually I think the check in line 62 should be removed as well. There's no need check argument length everytime Update is called. Parser would fail if argument number is wrong unless something is wrong in the framework. Or we can do this check in expression/aggregation/aggregation.go

@zimulala
Copy link
Contributor

zimulala commented Dec 8, 2017

LGTM

@zz-jason zz-jason added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Dec 19, 2017
@tiancaiamao
Copy link
Contributor

/run-all-tests

@tiancaiamao
Copy link
Contributor

/run-sqllogic-test

1 similar comment
@tiancaiamao
Copy link
Contributor

/run-sqllogic-test

@tiancaiamao tiancaiamao merged commit 6b6afb6 into pingcap:master Dec 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution This PR is from a community contributor. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants