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

executor, util: wrap cast upon the args for AggFunction #7180

Merged
merged 5 commits into from
Jul 31, 2018

Conversation

XuHuaiyu
Copy link
Contributor

What have you changed? (mandatory)

To support all the types for new aggregation framework, we need to wrap cast upon the args of SUM/AVG/BIT_FUNCS/GROUP_CONCAT.

What is the type of the changes? (mandatory)

  • Improvement (non-breaking change which is an improvement to an existing feature)

How has this PR been tested? (mandatory)

The exist tests.

Does this PR affect documentation (docs/docs-cn) update? (mandatory)

no

Does this PR affect tidb-ansible update? (mandatory)

no

Does this PR need to be added to the release notes? (mandatory)

no

Refer to a related PR or issue link (optional)

#6952

Benchmark result if necessary (optional)

Add a few positive/negative examples (optional)

@XuHuaiyu XuHuaiyu added type/enhancement The issue or PR belongs to an enhancement. sig/execution SIG execution labels Jul 30, 2018
@XuHuaiyu XuHuaiyu added this to the 2.1 milestone Jul 30, 2018
@XuHuaiyu
Copy link
Contributor Author

PTAL @zz-jason

@XuHuaiyu
Copy link
Contributor Author

/run-all-tests

@@ -825,11 +825,43 @@ func (b *executorBuilder) buildHashJoin(v *plan.PhysicalHashJoin) Executor {
return e
}

// wrapCastForAggArgs wraps the args of an aggregate function with a cast function.
func (b *executorBuilder) wrapCastForAggArgs(funcs []*aggregation.AggFuncDesc) {
Copy link
Member

Choose a reason for hiding this comment

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

We'd better make implement a function like InferArgumentType for AggFuncDesc, and call that function inside this routine:

for _, aggFuncDesc := range funcs {
    aggFuncDesc.InferArgumentType()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think current function name may be clearer,
since this is not a real type infer.
Type infer for agg function has been done in AggFuncDesc.typeInfer.
This function is more like a supplementary behavior for type infer.

// we should set it to the real fraction length of the decimal value,
// if not, the d.Frac will be set to MAX_UINT16 which will cause unexpected BadNumber error
// when encoding.
if tp.Decimal == -1 {
Copy link
Member

Choose a reason for hiding this comment

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

Use types.UnspecifiedLength?

// If tp.Decimal is unspecified(-1),
// we should set it to the real fraction length of the decimal value,
// if not, the d.Frac will be set to MAX_UINT16 which will cause unexpected BadNumber error
// when encoding.
Copy link
Member

Choose a reason for hiding this comment

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

@zz-jason
Copy link
Member

I think the integration tests are filed because the newer implemented aggregate function avg doesn't have this logic: https://github.com/pingcap/tidb/blob/master/expression/aggregation/avg.go#L85

@XuHuaiyu
Copy link
Contributor Author

/run-common-test tidb-test=pr/595
/run-integration-common-test tidb-test=pr/595

1 similar comment
@XuHuaiyu
Copy link
Contributor Author

/run-common-test tidb-test=pr/595
/run-integration-common-test tidb-test=pr/595

// buildProjBelowAgg builds a ProjectionExec below AggregationExec.
// If all the args of `aggFuncs`, and all the item of `groupByItems`
// are columns or constants, we do not need to build the `proj`.
func (b *executorBuilder) buildProjBelowAgg(aggFuncs []*aggregation.AggFuncDesc, groupByItems []expression.Expression, src Executor) Executor {
hasScalarFunc := false
// If the mode if Partial2Mode or CompleteMode, we do not need to wrap cast upon the args,
// since the types of the args are already the expected.
if len(aggFuncs) > 0 && (aggFuncs[0].Mode == aggregation.Partial1Mode || aggFuncs[0].Mode == aggregation.CompleteMode) {
Copy link
Member

Choose a reason for hiding this comment

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

I think len(aggFuncs) > 0 is enough, aggFuncs[0].Mode == aggregation.Partial1Mode || aggFuncs[0].Mode == aggregation.CompleteMode is guaranteed to be true in this procedure.

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

@XuHuaiyu
Copy link
Contributor Author

PTAL @winoros

Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

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

lgtm

@XuHuaiyu
Copy link
Contributor Author

/run-common-test tidb-test=pr/595
/run-integration-common-test tidb-test=pr/595

@XuHuaiyu XuHuaiyu merged commit 0ca4cc6 into pingcap:master Jul 31, 2018
@XuHuaiyu XuHuaiyu deleted the agg_type branch April 22, 2019 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants