本文整理汇总了Golang中github.com/youtube/vitess/go/vt/schema.Table.FindColumn方法的典型用法代码示例。如果您正苦于以下问题:Golang Table.FindColumn方法的具体用法?Golang Table.FindColumn怎么用?Golang Table.FindColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/vt/schema.Table
的用法示例。
在下文中一共展示了Table.FindColumn方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: analyzeSelectExprs
func analyzeSelectExprs(exprs sqlparser.SelectExprs, table *schema.Table) (selects []int, err error) {
selects = make([]int, 0, len(exprs))
for _, expr := range exprs {
switch expr := expr.(type) {
case *sqlparser.StarExpr:
// Append all columns.
for colIndex := range table.Columns {
selects = append(selects, colIndex)
}
case *sqlparser.NonStarExpr:
name := sqlparser.GetColName(expr.Expr)
if name == "" {
// Not a simple column name.
return nil, nil
}
colIndex := table.FindColumn(name)
if colIndex == -1 {
return nil, fmt.Errorf("column %s not found in table %s", name, table.Name)
}
selects = append(selects, colIndex)
default:
panic("unreachable")
}
}
return selects, nil
}
示例2: findSplitColumnsInSchema
func findSplitColumnsInSchema(
splitColumnNames []sqlparser.ColIdent, tableSchema *schema.Table,
) ([]*schema.TableColumn, error) {
result := make([]*schema.TableColumn, 0, len(splitColumnNames))
for _, splitColumnName := range splitColumnNames {
i := tableSchema.FindColumn(splitColumnName.Original())
if i == -1 {
return nil, fmt.Errorf("can't find split column: %v", splitColumnName)
}
result = append(result, &tableSchema.Columns[i])
}
return result, nil
}
示例3: execAnalyzeSelectExpressions
func (node *Node) execAnalyzeSelectExpressions(table *schema.Table) (selects []int) {
selects = make([]int, 0, node.Len())
for i := 0; i < node.Len(); i++ {
if name := node.At(i).execAnalyzeSelectExpression(); name != "" {
if name == "*" {
for colIndex := range table.Columns {
selects = append(selects, colIndex)
}
} else if colIndex := table.FindColumn(name); colIndex != -1 {
selects = append(selects, colIndex)
} else {
panic(NewParserError("Column %s not found in table %s", name, table.Name))
}
} else {
// Complex expression
return nil
}
}
return selects
}
示例4: execAnalyzeSelectExprs
func execAnalyzeSelectExprs(exprs SelectExprs, table *schema.Table) (selects []int) {
selects = make([]int, 0, len(exprs))
for _, expr := range exprs {
if name := execAnalyzeSelectExpr(expr); name != "" {
if name == "*" {
for colIndex := range table.Columns {
selects = append(selects, colIndex)
}
} else if colIndex := table.FindColumn(name); colIndex != -1 {
selects = append(selects, colIndex)
} else {
panic(NewParserError("column %s not found in table %s", name, table.Name))
}
} else {
// Complex expression
return nil
}
}
return selects
}