本文整理汇总了Golang中github.com/pingcap/tidb/expression.Schema.FindColumn方法的典型用法代码示例。如果您正苦于以下问题:Golang Schema.FindColumn方法的具体用法?Golang Schema.FindColumn怎么用?Golang Schema.FindColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/expression.Schema
的用法示例。
在下文中一共展示了Schema.FindColumn方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: resolveFromSchema
func (a *havingAndOrderbyExprResolver) resolveFromSchema(v *ast.ColumnNameExpr, schema expression.Schema) (int, error) {
col, err := schema.FindColumn(v.Name)
if err != nil {
return -1, errors.Trace(err)
}
if col == nil {
return -1, nil
}
newColName := &ast.ColumnName{
Schema: col.DBName,
Table: col.TblName,
Name: col.ColName,
}
for i, field := range a.selectFields {
if c, ok := field.Expr.(*ast.ColumnNameExpr); ok && colMatch(newColName, c.Name) {
return i, nil
}
}
sf := &ast.SelectField{
Expr: &ast.ColumnNameExpr{Name: newColName},
Auxiliary: true,
}
sf.Expr.SetType(col.GetType())
a.selectFields = append(a.selectFields, sf)
return len(a.selectFields) - 1, nil
}
示例2: Enter
func (e *havingAndOrderbyResolver) Enter(inNode ast.Node) (ast.Node, bool) {
switch v := inNode.(type) {
case *ast.ValueExpr, *ast.ColumnName, *ast.ParenthesesExpr:
case *ast.ColumnNameExpr:
var first, second expression.Schema
var col *expression.Column
fromSchema := e.proj.GetChildByIndex(0).GetSchema()
fromSchemaFirst := e.orderBy && e.inExpr
if fromSchemaFirst {
first, second = fromSchema, e.proj.GetSchema()
col, e.err = first.FindColumn(v.Name)
} else {
first, second = e.proj.GetSchema(), fromSchema
col, e.err = first.FindSelectFieldColumn(v.Name, e.proj.Exprs)
}
if e.err != nil {
return inNode, true
}
if col == nil {
if fromSchemaFirst {
col, e.err = second.FindSelectFieldColumn(v.Name, e.proj.Exprs)
} else {
col, e.err = second.FindColumn(v.Name)
}
if e.err != nil {
return inNode, true
}
if col == nil {
e.err = errors.Errorf("Can't find Column %s", v.Name.Name)
return inNode, true
}
if !fromSchemaFirst {
e.addProjectionExpr(v, col)
} else {
e.mapper[v] = col
}
} else if fromSchemaFirst {
e.addProjectionExpr(v, col)
} else {
e.mapper[v] = col
}
case *ast.SubqueryExpr, *ast.CompareSubqueryExpr, *ast.ExistsSubqueryExpr:
return inNode, true
default:
e.inExpr = true
}
return inNode, false
}
示例3: resolveFromSchema
func (a *AggregateFuncExtractor) resolveFromSchema(v *ast.ColumnNameExpr, schema expression.Schema) (int, error) {
col, err := schema.FindColumn(v.Name)
if err != nil {
return -1, errors.Trace(err)
}
if col == nil {
return -1, nil
}
newColName := &ast.ColumnName{
Schema: col.DBName,
Table: col.TblName,
Name: col.ColName,
}
for i, field := range a.selectFields {
if c, ok := field.Expr.(*ast.ColumnNameExpr); ok && colMatch(newColName, c.Name) {
return i, nil
}
}
a.selectFields = append(a.selectFields, &ast.SelectField{
Expr: &ast.ColumnNameExpr{Name: newColName},
Auxiliary: true,
})
return len(a.selectFields) - 1, nil
}