當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ast.AggregateFuncExpr類代碼示例

本文整理匯總了Golang中github.com/pingcap/tidb/ast.AggregateFuncExpr的典型用法代碼示例。如果您正苦於以下問題:Golang AggregateFuncExpr類的具體用法?Golang AggregateFuncExpr怎麽用?Golang AggregateFuncExpr使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了AggregateFuncExpr類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: aggregateFunc

func (v *typeInferrer) aggregateFunc(x *ast.AggregateFuncExpr) {
	name := strings.ToLower(x.F)
	switch name {
	case "count":
		ft := types.NewFieldType(mysql.TypeLonglong)
		ft.Flen = 21
		x.SetType(ft)
	}
}
開發者ID:AkihiroSuda,項目名稱:tidb,代碼行數:9,代碼來源:typeinferer.go

示例2: evalAggAvg

func (e *Evaluator) evalAggAvg(v *ast.AggregateFuncExpr) {
	ctx := v.GetContext()
	switch x := ctx.Value.(type) {
	case float64:
		ctx.Value = x / float64(ctx.Count)
	case mysql.Decimal:
		ctx.Value = x.Div(mysql.NewDecimalFromUint(uint64(ctx.Count), 0))
	}
	v.SetValue(ctx.Value)
}
開發者ID:xudongQiu,項目名稱:tidb,代碼行數:10,代碼來源:evaluator.go

示例3: aggregateFunc

func (e *Evaluator) aggregateFunc(v *ast.AggregateFuncExpr) bool {
	idx := e.aggregateMap[v]
	aggr := e.aggregators[idx]
	if e.aggregateDone {
		v.SetValue(aggr.Output())
		return true
	}
	// TODO: currently only single argument aggregate functions are supported.
	e.err = aggr.Input(v.Args[0].GetValue())
	return e.err == nil
}
開發者ID:yzl11,項目名稱:vessel,代碼行數:11,代碼來源:evaluator.go

示例4: aggregateFunc

func (v *typeInferrer) aggregateFunc(x *ast.AggregateFuncExpr) {
	name := strings.ToLower(x.F)
	switch name {
	case ast.AggFuncCount:
		ft := types.NewFieldType(mysql.TypeLonglong)
		ft.Flen = 21
		ft.Charset = charset.CharsetBin
		ft.Collate = charset.CollationBin
		x.SetType(ft)
	case ast.AggFuncMax, ast.AggFuncMin:
		x.SetType(x.Args[0].GetType())
	case ast.AggFuncSum, ast.AggFuncAvg:
		ft := types.NewFieldType(mysql.TypeNewDecimal)
		ft.Charset = charset.CharsetBin
		ft.Collate = charset.CollationBin
		x.SetType(ft)
	case ast.AggFuncGroupConcat:
		ft := types.NewFieldType(mysql.TypeVarString)
		ft.Charset = v.defaultCharset
		cln, err := charset.GetDefaultCollation(v.defaultCharset)
		if err != nil {
			v.err = err
		}
		ft.Collate = cln
		x.SetType(ft)
	}
}
開發者ID:mumubusu,項目名稱:tidb,代碼行數:27,代碼來源:typeinferer.go

示例5: aggregateFunc

func (v *typeInferrer) aggregateFunc(x *ast.AggregateFuncExpr) {
	name := strings.ToLower(x.F)
	switch name {
	case "count":
		ft := types.NewFieldType(mysql.TypeLonglong)
		ft.Flen = 21
		ft.Charset = charset.CharsetBin
		ft.Collate = charset.CollationBin
		x.SetType(ft)
	case "sum":
		ft := types.NewFieldType(mysql.TypeNewDecimal)
		ft.Charset = charset.CharsetBin
		ft.Collate = charset.CollationBin
		x.SetType(ft)
	}
}
開發者ID:losas,項目名稱:tidb,代碼行數:16,代碼來源:typeinferer.go

示例6: evalAggAvg

func (e *Evaluator) evalAggAvg(v *ast.AggregateFuncExpr) {
	ctx := v.GetContext()
	switch ctx.Value.Kind() {
	case types.KindFloat64:
		t := ctx.Value.GetFloat64() / float64(ctx.Count)
		v.SetValue(t)
	case types.KindMysqlDecimal:
		x := ctx.Value.GetMysqlDecimal()
		t := x.Div(mysql.NewDecimalFromUint(uint64(ctx.Count), 0))
		v.SetMysqlDecimal(t)
	}
	ctx.Value = *v.GetDatum()
}
開發者ID:XuHuaiyu,項目名稱:tidb,代碼行數:13,代碼來源:evaluator.go

示例7: evalAggGroupConcat

func (e *Evaluator) evalAggGroupConcat(v *ast.AggregateFuncExpr) {
	ctx := v.GetContext()
	if ctx.Buffer != nil {
		v.SetString(ctx.Buffer.String())
	} else {
		v.SetNull()
	}
}
開發者ID:yangxuanjia,項目名稱:tidb,代碼行數:8,代碼來源:evaluator.go

示例8: evalAggAvg

func (e *Evaluator) evalAggAvg(v *ast.AggregateFuncExpr) {
	ctx := v.GetContext()
	switch ctx.Value.Kind() {
	case types.KindFloat64:
		t := ctx.Value.GetFloat64() / float64(ctx.Count)
		v.SetValue(t)
	case types.KindMysqlDecimal:
		x := ctx.Value.GetMysqlDecimal()
		var y, to mysql.MyDecimal
		y.FromUint(uint64(ctx.Count))
		mysql.DecimalDiv(x, &y, &to, mysql.DivFracIncr)
		to.Round(&to, ctx.Value.Frac()+mysql.DivFracIncr)
		v.SetMysqlDecimal(&to)
	}
	ctx.Value = *v.GetDatum()
}
開發者ID:yangxuanjia,項目名稱:tidb,代碼行數:16,代碼來源:evaluator.go

示例9: evalAggSetValue

func (e *Evaluator) evalAggSetValue(v *ast.AggregateFuncExpr) {
	ctx := v.GetContext()
	v.SetDatum(ctx.Value)
}
開發者ID:yangxuanjia,項目名稱:tidb,代碼行數:4,代碼來源:evaluator.go

示例10: evalAggCount

func (e *Evaluator) evalAggCount(v *ast.AggregateFuncExpr) {
	ctx := v.GetContext()
	v.SetInt64(ctx.Count)
}
開發者ID:yangxuanjia,項目名稱:tidb,代碼行數:4,代碼來源:evaluator.go

示例11: evalAggFirstRow

func (e *Evaluator) evalAggFirstRow(v *ast.AggregateFuncExpr) {
	ctx := v.GetContext()
	v.SetValue(ctx.Value)
}
開發者ID:mrtoms,項目名稱:tidb,代碼行數:4,代碼來源:evaluator.go


注:本文中的github.com/pingcap/tidb/ast.AggregateFuncExpr類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。