• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang ast.ColumnNameExpr类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/pingcap/tidb/ast.ColumnNameExpr的典型用法代码示例。如果您正苦于以下问题:Golang ColumnNameExpr类的具体用法?Golang ColumnNameExpr怎么用?Golang ColumnNameExpr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: resolveColumnInResultFields

func (nr *nameResolver) resolveColumnInResultFields(cn *ast.ColumnNameExpr, rfs []*ast.ResultField) bool {
	if cn.Name.Table.L != "" {
		// Skip result fields, resolve the column in table source.
		return false
	}
	var matched *ast.ResultField
	for _, rf := range rfs {
		matchAsName := cn.Name.Name.L == rf.ColumnAsName.L
		matchColumnName := rf.ColumnAsName.L == "" && cn.Name.Name.L == rf.Column.Name.L
		if matchAsName || matchColumnName {
			if rf.Column.Name.L == "" {
				// This is not a real table column, resolve it directly.
				cn.Refer = rf
				return true
			}
			if matched == nil {
				matched = rf
			} else {
				sameColumn := matched.Table.Name.L == rf.Table.Name.L && matched.Column.Name.L == rf.Column.Name.L
				if !sameColumn {
					nr.Err = errors.Errorf("column %s is ambiguous.", cn.Name.Name.O)
					return true
				}
			}
		}
	}
	if matched != nil {
		// Bind column.
		cn.Refer = matched
		return true
	}
	return false
}
开发者ID:MDistribuntedSystem,项目名称:tidb,代码行数:33,代码来源:resolver.go


示例2: resolveColumnInResultFields

func (nr *nameResolver) resolveColumnInResultFields(ctx *resolverContext, cn *ast.ColumnNameExpr, rfs []*ast.ResultField) bool {
	var matched *ast.ResultField
	for _, rf := range rfs {
		if cn.Name.Table.L != "" {
			// Check table name
			if rf.TableAsName.L != "" {
				if cn.Name.Table.L != rf.TableAsName.L {
					continue
				}
			} else if cn.Name.Table.L != rf.Table.Name.L {
				continue
			}
		}
		matchAsName := cn.Name.Name.L == rf.ColumnAsName.L
		var matchColumnName bool
		if ctx.inHaving {
			matchColumnName = cn.Name.Name.L == rf.Column.Name.L
		} else {
			matchColumnName = rf.ColumnAsName.L == "" && cn.Name.Name.L == rf.Column.Name.L
		}
		if matchAsName || matchColumnName {
			if rf.Column.Name.L == "" {
				// This is not a real table column, resolve it directly.
				cn.Refer = rf
				rf.Referenced = true
				return true
			}
			if matched == nil {
				matched = rf
			} else {
				sameColumn := matched.TableName == rf.TableName && matched.Column.Name.L == rf.Column.Name.L
				if !sameColumn {
					nr.Err = errors.Errorf("column %s is ambiguous.", cn.Name.Name.O)
					return true
				}
			}
		}
	}
	if matched != nil {
		// If in GroupBy, we clone the ResultField
		if ctx.inGroupBy || ctx.inHaving || ctx.inOrderBy {
			nf := *matched
			expr := matched.Expr
			if cexpr, ok := expr.(*ast.ColumnNameExpr); ok {
				expr = cexpr.Refer.Expr
			}
			nf.Expr = expr
			matched = &nf
		}
		// Bind column.
		cn.Refer = matched
		matched.Referenced = true
		return true
	}
	return false
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:56,代码来源:resolver.go


示例3: resolveColumnInTableSources

func (nr *nameResolver) resolveColumnInTableSources(cn *ast.ColumnNameExpr, tableSources []*ast.TableSource) (done bool) {
	var matchedResultField *ast.ResultField
	tableNameL := cn.Name.Table.L
	columnNameL := cn.Name.Name.L
	if tableNameL != "" {
		var matchedTable ast.ResultSetNode
		for _, ts := range tableSources {
			if tableNameL == ts.AsName.L {
				// different table name.
				matchedTable = ts
				break
			} else if ts.AsName.L != "" {
				// Table as name shadows table real name.
				continue
			}
			if tn, ok := ts.Source.(*ast.TableName); ok {
				if cn.Name.Schema.L != "" && cn.Name.Schema.L != tn.Schema.L {
					continue
				}
				if tableNameL == tn.Name.L {
					matchedTable = ts
				}
			}
		}
		if matchedTable != nil {
			resultFields := matchedTable.GetResultFields()
			for _, rf := range resultFields {
				if rf.ColumnAsName.L == columnNameL || rf.Column.Name.L == columnNameL {
					// resolve column.
					matchedResultField = rf
					break
				}
			}
		}
	} else {
		for _, ts := range tableSources {
			rfs := ts.GetResultFields()
			for _, rf := range rfs {
				matchAsName := rf.ColumnAsName.L != "" && rf.ColumnAsName.L == columnNameL
				matchColumnName := rf.ColumnAsName.L == "" && rf.Column.Name.L == columnNameL
				if matchAsName || matchColumnName {
					if matchedResultField != nil {
						nr.Err = errors.Errorf("column %s is ambiguous.", cn.Name.Name.O)
						return true
					}
					matchedResultField = rf
				}
			}
		}
	}
	if matchedResultField != nil {
		// Bind column.
		cn.Refer = matchedResultField
		matchedResultField.Referenced = true
		return true
	}
	return false
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:58,代码来源:resolver.go


示例4: resolveColumnInResultFields

func (nr *nameResolver) resolveColumnInResultFields(ctx *resolverContext, cn *ast.ColumnNameExpr, rfs []*ast.ResultField) bool {
	var matched *ast.ResultField
	for _, rf := range rfs {
		if cn.Name.Table.L != "" {
			// Check table name
			if rf.TableAsName.L != "" {
				if cn.Name.Table.L != rf.TableAsName.L {
					continue
				}
			} else if cn.Name.Table.L != rf.Table.Name.L {
				continue
			}
		}
		matchAsName := cn.Name.Name.L == rf.ColumnAsName.L
		var matchColumnName bool
		if ctx.inHaving {
			matchColumnName = cn.Name.Name.L == rf.Column.Name.L
		} else {
			matchColumnName = rf.ColumnAsName.L == "" && cn.Name.Name.L == rf.Column.Name.L
		}
		if matchAsName || matchColumnName {
			if rf.Column.Name.L == "" {
				// This is not a real table column, resolve it directly.
				cn.Refer = rf
				return true
			}
			if matched == nil {
				matched = rf
			} else {
				sameColumn := matched.TableName == rf.TableName && matched.Column.Name.L == rf.Column.Name.L
				if !sameColumn {
					nr.Err = errors.Errorf("column %s is ambiguous.", cn.Name.Name.O)
					return true
				}
			}
		}
	}
	if matched != nil {
		// Bind column.
		cn.Refer = matched
		return true
	}
	return false
}
开发者ID:xudongQiu,项目名称:tidb,代码行数:44,代码来源:resolver.go


示例5: columnName

func (e *Evaluator) columnName(v *ast.ColumnNameExpr) bool {
	v.SetDatum(*v.Refer.Expr.GetDatum())
	return true
}
开发者ID:yangxuanjia,项目名称:tidb,代码行数:4,代码来源:evaluator.go


示例6: resolveColumnNameInContext

// resolveColumnNameInContext looks up and sets ResultField for a column with the ctx.
func (nr *nameResolver) resolveColumnNameInContext(ctx *resolverContext, cn *ast.ColumnNameExpr) bool {
	if ctx.inTableRefs {
		// In TableRefsClause, column reference only in join on condition which is handled before.
		return false
	}
	if ctx.inFieldList {
		// only resolve column using tables.
		return nr.resolveColumnInTableSources(cn, ctx.tables)
	}
	if ctx.inGroupBy {
		// From tables first, then field list.
		// If ctx.InByItemExpression is true, the item is not an identifier.
		// Otherwise it is an identifier.
		if ctx.inByItemExpression {
			// From table first, then field list.
			if nr.resolveColumnInTableSources(cn, ctx.tables) {
				return true
			}
			found := nr.resolveColumnInResultFields(ctx, cn, ctx.fieldList)
			if nr.Err == nil && found {
				// Check if resolved refer is an aggregate function expr.
				if _, ok := cn.Refer.Expr.(*ast.AggregateFuncExpr); ok {
					nr.Err = ErrIllegalReference.Gen("Reference '%s' not supported (reference to group function)", cn.Name.Name.O)
				}
			}
			return found
		}
		// Resolve from table first, then from select list.
		found := nr.resolveColumnInTableSources(cn, ctx.tables)
		if nr.Err != nil {
			return found
		}
		// We should copy the refer here.
		// Because if the ByItem is an identifier, we should check if it
		// is ambiguous even it is already resolved from table source.
		// If the ByItem is not an identifier, we do not need the second check.
		r := cn.Refer
		if nr.resolveColumnInResultFields(ctx, cn, ctx.fieldList) {
			if nr.Err != nil {
				return true
			}
			if r != nil {
				// It is not ambiguous and already resolved from table source.
				// We should restore its Refer.
				cn.Refer = r
			}
			if _, ok := cn.Refer.Expr.(*ast.AggregateFuncExpr); ok {
				nr.Err = ErrIllegalReference.Gen("Reference '%s' not supported (reference to group function)", cn.Name.Name.O)
			}
			return true
		}
		return found
	}
	if ctx.inHaving {
		// First group by, then field list.
		if nr.resolveColumnInResultFields(ctx, cn, ctx.groupBy) {
			return true
		}
		if ctx.inHavingAgg {
			// If cn is in an aggregate function in having clause, check tablesource first.
			if nr.resolveColumnInTableSources(cn, ctx.tables) {
				return true
			}
		}
		return nr.resolveColumnInResultFields(ctx, cn, ctx.fieldList)
	}
	if ctx.inOrderBy {
		if nr.resolveColumnInResultFields(ctx, cn, ctx.groupBy) {
			return true
		}
		if ctx.inByItemExpression {
			// From table first, then field list.
			if nr.resolveColumnInTableSources(cn, ctx.tables) {
				return true
			}
			return nr.resolveColumnInResultFields(ctx, cn, ctx.fieldList)
		}
		// Field list first, then from table.
		if nr.resolveColumnInResultFields(ctx, cn, ctx.fieldList) {
			return true
		}
		return nr.resolveColumnInTableSources(cn, ctx.tables)
	}
	// In where clause.
	return nr.resolveColumnInTableSources(cn, ctx.tables)
}
开发者ID:youprofit,项目名称:tidb,代码行数:87,代码来源:resolver.go


示例7: resolveColumnNameInContext

// resolveColumnNameInContext looks up and sets ResultField for a column with the ctx.
func (nr *nameResolver) resolveColumnNameInContext(ctx *resolverContext, cn *ast.ColumnNameExpr) bool {
	if ctx.inTableRefs {
		// In TableRefsClause, column reference only in join on condition which is handled before.
		return false
	}
	if ctx.inFieldList {
		// only resolve column using tables.
		return nr.resolveColumnInTableSources(cn, ctx.tables)
	}
	if ctx.inGroupBy {
		// From tables first, then field list.
		// If ctx.InByItemExpression is true, the item is not an identifier.
		// Otherwise it is an identifier.
		if ctx.inByItemExpression {
			// From table first, then field list.
			if nr.resolveColumnInTableSources(cn, ctx.tables) {
				return true
			}
			return nr.resolveColumnInResultFields(cn, ctx.fieldList)
		}
		// Resolve from table first, then from select list.
		found := nr.resolveColumnInTableSources(cn, ctx.tables)
		if nr.Err != nil {
			return found
		}
		// We should copy the refer here.
		// Because if the ByItem is an identifier, we should check if it
		// is ambiguous even it is already resolved from table source.
		// If the ByItem is not an identifier, we do not need the second check.
		r := cn.Refer
		if nr.resolveColumnInResultFields(cn, ctx.fieldList) {
			if nr.Err != nil {
				return true
			}
			if r != nil {
				// It is not ambiguous and already resolved from table source.
				// We should restore its Refer.
				cn.Refer = r
			}
			return true
		}
		return found
	}
	if ctx.inHaving {
		// First group by, then field list.
		if nr.resolveColumnInResultFields(cn, ctx.groupBy) {
			return true
		}
		return nr.resolveColumnInResultFields(cn, ctx.fieldList)
	}
	if ctx.inOrderBy {
		if nr.resolveColumnInResultFields(cn, ctx.groupBy) {
			return true
		}
		if ctx.inByItemExpression {
			// From table first, then field list.
			if nr.resolveColumnInTableSources(cn, ctx.tables) {
				return true
			}
			return nr.resolveColumnInResultFields(cn, ctx.fieldList)
		}
		// Field list first, then from table.
		if nr.resolveColumnInResultFields(cn, ctx.fieldList) {
			return true
		}
		return nr.resolveColumnInTableSources(cn, ctx.tables)
	}
	// In where clause.
	return nr.resolveColumnInTableSources(cn, ctx.tables)
}
开发者ID:dabudaqiu,项目名称:tidb,代码行数:71,代码来源:resolver.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang ast.DropIndexStmt类代码示例发布时间:2022-05-28
下一篇:
Golang ast.CaseExpr类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap