本文整理汇总了Golang中github.com/pingcap/tidb/ast.HasAggFlag函数的典型用法代码示例。如果您正苦于以下问题:Golang HasAggFlag函数的具体用法?Golang HasAggFlag怎么用?Golang HasAggFlag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HasAggFlag函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: detectSelectAgg
// Detect aggregate function or groupby clause.
func (b *planBuilder) detectSelectAgg(sel *ast.SelectStmt) bool {
if sel.GroupBy != nil {
return true
}
for _, f := range sel.GetResultFields() {
if ast.HasAggFlag(f.Expr) {
return true
}
}
return false
}
开发者ID:zxylvlp,项目名称:tidb,代码行数:12,代码来源:planbuilder.go
示例2: Enter
// Enter implements ast.Visitor interface.
func (nr *nameResolver) Enter(inNode ast.Node) (outNode ast.Node, skipChildren bool) {
switch v := inNode.(type) {
case *ast.AdminStmt:
nr.pushContext()
case *ast.AggregateFuncExpr:
ctx := nr.currentContext()
if ctx.inHaving {
ctx.inHavingAgg = true
}
case *ast.ByItem:
if _, ok := v.Expr.(*ast.ColumnNameExpr); !ok {
// If ByItem is not a single column name expression,
// the resolving rule is different from order by clause.
nr.currentContext().inByItemExpression = true
}
if nr.currentContext().inGroupBy {
// make sure item is not aggregate function
if ast.HasAggFlag(v.Expr) {
nr.Err = ErrInvalidGroupFuncUse
return inNode, true
}
}
case *ast.DeleteStmt:
nr.pushContext()
case *ast.DeleteTableList:
nr.currentContext().inDeleteTableList = true
case *ast.FieldList:
nr.currentContext().inFieldList = true
case *ast.GroupByClause:
nr.currentContext().inGroupBy = true
case *ast.HavingClause:
nr.currentContext().inHaving = true
case *ast.InsertStmt:
nr.pushContext()
case *ast.Join:
nr.pushJoin(v)
case *ast.OnCondition:
nr.currentContext().inOnCondition = true
case *ast.OrderByClause:
nr.currentContext().inOrderBy = true
case *ast.SelectStmt:
nr.pushContext()
case *ast.TableRefsClause:
nr.currentContext().inTableRefs = true
case *ast.UnionStmt:
nr.pushContext()
case *ast.UpdateStmt:
nr.pushContext()
}
return inNode, false
}
开发者ID:steffengy,项目名称:tidb,代码行数:52,代码来源:resolver.go
示例3: detectSelectAgg
// Detect aggregate function or groupby clause.
func (b *planBuilder) detectSelectAgg(sel *ast.SelectStmt) bool {
if sel.GroupBy != nil {
return true
}
for _, f := range sel.GetResultFields() {
if ast.HasAggFlag(f.Expr) {
return true
}
}
if sel.Having != nil {
if ast.HasAggFlag(sel.Having.Expr) {
return true
}
}
if sel.OrderBy != nil {
for _, item := range sel.OrderBy.Items {
if ast.HasAggFlag(item.Expr) {
return true
}
}
}
return false
}
开发者ID:tutuhuagong,项目名称:tidb,代码行数:24,代码来源:planbuilder.go
示例4: handlePosition
func (nr *nameResolver) handlePosition(pos *ast.PositionExpr) {
ctx := nr.currentContext()
if pos.N < 1 || pos.N > len(ctx.fieldList) {
nr.Err = errors.Errorf("Unknown column '%d'", pos.N)
return
}
pos.Refer = ctx.fieldList[pos.N-1]
if nr.currentContext().inGroupBy {
// make sure item is not aggregate function
if ast.HasAggFlag(pos.Refer.Expr) {
nr.Err = errors.New("group by cannot contain aggregate function")
}
}
}
开发者ID:mumubusu,项目名称:tidb,代码行数:14,代码来源:resolver.go
示例5: TestHasAggFlag
func (ts *testFlagSuite) TestHasAggFlag(c *C) {
expr := &ast.BetweenExpr{}
cases := []struct {
flag uint64
hasAgg bool
}{
{ast.FlagHasAggregateFunc, true},
{ast.FlagHasAggregateFunc | ast.FlagHasVariable, true},
{ast.FlagHasVariable, false},
}
for _, ca := range cases {
expr.SetFlag(ca.flag)
c.Assert(ast.HasAggFlag(expr), Equals, ca.hasAgg)
}
}
开发者ID:dabudaqiu,项目名称:tidb,代码行数:15,代码来源:flag_test.go
示例6: handlePosition
func (nr *nameResolver) handlePosition(pos *ast.PositionExpr) {
ctx := nr.currentContext()
if pos.N < 1 || pos.N > len(ctx.fieldList) {
nr.Err = errors.Errorf("Unknown column '%d'", pos.N)
return
}
matched := ctx.fieldList[pos.N-1]
nf := *matched
expr := matched.Expr
if cexpr, ok := expr.(*ast.ColumnNameExpr); ok {
expr = cexpr.Refer.Expr
}
nf.Expr = expr
pos.Refer = &nf
if nr.currentContext().inGroupBy {
// make sure item is not aggregate function
if ast.HasAggFlag(pos.Refer.Expr) {
nr.Err = errors.New("group by cannot contain aggregate function")
}
}
}
开发者ID:youprofit,项目名称:tidb,代码行数:21,代码来源:resolver.go
示例7: Enter
// Enter implements ast.Visitor interface.
func (nr *nameResolver) Enter(inNode ast.Node) (outNode ast.Node, skipChildren bool) {
switch v := inNode.(type) {
case *ast.AdminStmt:
nr.pushContext()
case *ast.AggregateFuncExpr:
ctx := nr.currentContext()
if ctx.inHaving {
ctx.inHavingAgg = true
}
case *ast.AlterTableStmt:
nr.pushContext()
case *ast.AnalyzeTableStmt:
nr.pushContext()
case *ast.ByItem:
if _, ok := v.Expr.(*ast.ColumnNameExpr); !ok {
// If ByItem is not a single column name expression,
// the resolving rule is different from order by clause.
nr.currentContext().inByItemExpression = true
}
if nr.currentContext().inGroupBy {
// make sure item is not aggregate function
if ast.HasAggFlag(v.Expr) {
nr.Err = ErrInvalidGroupFuncUse
return inNode, true
}
}
case *ast.CreateIndexStmt:
nr.pushContext()
case *ast.CreateTableStmt:
nr.pushContext()
nr.currentContext().inCreateOrDropTable = true
case *ast.DeleteStmt:
nr.pushContext()
case *ast.DeleteTableList:
nr.currentContext().inDeleteTableList = true
case *ast.DoStmt:
nr.pushContext()
case *ast.DropTableStmt:
nr.pushContext()
nr.currentContext().inCreateOrDropTable = true
case *ast.DropIndexStmt:
nr.pushContext()
case *ast.FieldList:
nr.currentContext().inFieldList = true
case *ast.GroupByClause:
nr.currentContext().inGroupBy = true
case *ast.HavingClause:
nr.currentContext().inHaving = true
case *ast.InsertStmt:
nr.pushContext()
case *ast.Join:
nr.pushJoin(v)
case *ast.OnCondition:
nr.currentContext().inOnCondition = true
case *ast.OrderByClause:
nr.currentContext().inOrderBy = true
case *ast.SelectStmt:
nr.pushContext()
case *ast.SetStmt:
for _, assign := range v.Variables {
if cn, ok := assign.Value.(*ast.ColumnNameExpr); ok && cn.Name.Table.L == "" {
// Convert column name expression to string value expression.
assign.Value = ast.NewValueExpr(cn.Name.Name.O)
}
}
nr.pushContext()
case *ast.ShowStmt:
nr.pushContext()
nr.currentContext().inShow = true
nr.fillShowFields(v)
case *ast.TableRefsClause:
nr.currentContext().inTableRefs = true
case *ast.TruncateTableStmt:
nr.pushContext()
case *ast.UnionStmt:
nr.pushContext()
case *ast.UpdateStmt:
nr.pushContext()
}
return inNode, false
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:82,代码来源:resolver.go
注:本文中的github.com/pingcap/tidb/ast.HasAggFlag函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论