当前位置: 首页>>代码示例>>Golang>>正文


Golang Aggregation.GetSchema方法代码示例

本文整理汇总了Golang中github.com/pingcap/tidb/plan.Aggregation.GetSchema方法的典型用法代码示例。如果您正苦于以下问题:Golang Aggregation.GetSchema方法的具体用法?Golang Aggregation.GetSchema怎么用?Golang Aggregation.GetSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/pingcap/tidb/plan.Aggregation的用法示例。


在下文中一共展示了Aggregation.GetSchema方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: buildAggregation

func (b *executorBuilder) buildAggregation(v *plan.Aggregation) Executor {
	return &AggregationExec{
		Src:          b.build(v.GetChildByIndex(0)).(NewExecutor),
		schema:       v.GetSchema(),
		ctx:          b.ctx,
		AggFuncs:     v.AggFuncs,
		GroupByItems: v.GroupByItems,
	}
}
开发者ID:tangfeixiong,项目名称:tidb,代码行数:9,代码来源:new_builder.go

示例2: buildAggregation

func (b *executorBuilder) buildAggregation(v *plan.Aggregation) Executor {
	src := b.build(v.GetChildByIndex(0))
	e := &AggregationExec{
		Src:          src,
		schema:       v.GetSchema(),
		ctx:          b.ctx,
		AggFuncs:     v.AggFuncs,
		GroupByItems: v.GroupByItems,
	}
	// Check if the underlying is xapi executor, we should try to push aggregate function down.
	xSrc, ok := src.(NewXExecutor)
	if !ok {
		return e
	}
	txn, err := b.ctx.GetTxn(false)
	if err != nil {
		b.err = err
		return nil
	}
	client := txn.GetClient()
	if len(v.GroupByItems) > 0 && !client.SupportRequestType(kv.ReqTypeSelect, kv.ReqSubTypeGroupBy) {
		return e
	}
	// Convert aggregate function exprs to pb.
	pbAggFuncs := make([]*tipb.Expr, 0, len(v.AggFuncs))
	for _, af := range v.AggFuncs {
		if af.IsDistinct() {
			// We do not support distinct push down.
			return e
		}
		pbAggFunc := b.newAggFuncToPBExpr(client, af, xSrc.GetTable())
		if pbAggFunc == nil {
			return e
		}
		pbAggFuncs = append(pbAggFuncs, pbAggFunc)
	}
	pbByItems := make([]*tipb.ByItem, 0, len(v.GroupByItems))
	// Convert groupby to pb
	for _, item := range v.GroupByItems {
		pbByItem := b.newGroupByItemToPB(client, item, xSrc.GetTable())
		if pbByItem == nil {
			return e
		}
		pbByItems = append(pbByItems, pbByItem)
	}
	// compose aggregate info
	// We should infer fields type.
	// Each agg item will be splitted into two datums: count and value
	// The first field should be group key.
	fields := make([]*types.FieldType, 0, 1+2*len(v.AggFuncs))
	gk := types.NewFieldType(mysql.TypeBlob)
	gk.Charset = charset.CharsetBin
	gk.Collate = charset.CollationBin
	fields = append(fields, gk)
	// There will be one or two fields in the result row for each AggregateFuncExpr.
	// Count needs count partial result field.
	// Sum, FirstRow, Max, Min, GroupConcat need value partial result field.
	// Avg needs both count and value partial result field.
	for i, agg := range v.AggFuncs {
		name := strings.ToLower(agg.GetName())
		if needCount(name) {
			// count partial result field
			ft := types.NewFieldType(mysql.TypeLonglong)
			ft.Flen = 21
			ft.Charset = charset.CharsetBin
			ft.Collate = charset.CollationBin
			fields = append(fields, ft)
		}
		if needValue(name) {
			// value partial result field
			col := v.GetSchema()[i]
			fields = append(fields, col.GetType())
		}
	}
	xSrc.AddAggregate(pbAggFuncs, pbByItems, fields)
	hasGroupBy := len(v.GroupByItems) > 0
	xe := &NewXAggregateExec{
		Src:        src,
		ctx:        b.ctx,
		AggFuncs:   v.AggFuncs,
		hasGroupBy: hasGroupBy,
		schema:     v.GetSchema(),
	}
	log.Debugf("Use XAggregateExec with %d aggs", len(v.AggFuncs))
	return xe
}
开发者ID:c4pt0r,项目名称:tidb,代码行数:86,代码来源:new_builder.go


注:本文中的github.com/pingcap/tidb/plan.Aggregation.GetSchema方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。