本文整理匯總了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
}