本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/sql/parser.TableName.TableName方法的典型用法代码示例。如果您正苦于以下问题:Golang TableName.TableName方法的具体用法?Golang TableName.TableName怎么用?Golang TableName.TableName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/pkg/sql/parser.TableName
的用法示例。
在下文中一共展示了TableName.TableName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getDataSource
// getDataSource builds a planDataSource from a single data source clause
// (TableExpr) in a SelectClause.
func (p *planner) getDataSource(
src parser.TableExpr, hints *parser.IndexHints, scanVisibility scanVisibility,
) (planDataSource, error) {
switch t := src.(type) {
case *parser.NormalizableTableName:
// Usual case: a table.
tn, err := p.QualifyWithDatabase(t)
if err != nil {
return planDataSource{}, err
}
// Is this perhaps a name for a virtual table?
ds, foundVirtual, err := p.getVirtualDataSource(tn)
if err != nil {
return planDataSource{}, err
}
if foundVirtual {
return ds, nil
}
return p.getTableScanOrViewPlan(tn, hints, scanVisibility)
case *parser.Subquery:
return p.getSubqueryPlan(t.Select, nil)
case *parser.JoinTableExpr:
// Joins: two sources.
left, err := p.getDataSource(t.Left, nil, scanVisibility)
if err != nil {
return left, err
}
right, err := p.getDataSource(t.Right, nil, scanVisibility)
if err != nil {
return right, err
}
return p.makeJoin(t.Join, left, right, t.Cond)
case *parser.ParenTableExpr:
return p.getDataSource(t.Expr, hints, scanVisibility)
case *parser.AliasedTableExpr:
// Alias clause: source AS alias(cols...)
src, err := p.getDataSource(t.Expr, t.Hints, scanVisibility)
if err != nil {
return src, err
}
var tableAlias parser.TableName
if t.As.Alias != "" {
// If an alias was specified, use that.
tableAlias.TableName = parser.Name(t.As.Alias.Normalize())
src.info.sourceAliases = sourceAliases{
tableAlias: fillColumnRange(0, len(src.info.sourceColumns)-1),
}
}
colAlias := t.As.Cols
if len(colAlias) > 0 {
// Make a copy of the slice since we are about to modify the contents.
src.info.sourceColumns = append(ResultColumns(nil), src.info.sourceColumns...)
// The column aliases can only refer to explicit columns.
for colIdx, aliasIdx := 0, 0; aliasIdx < len(colAlias); colIdx++ {
if colIdx >= len(src.info.sourceColumns) {
var srcName string
if tableAlias.DatabaseName != "" {
srcName = tableAlias.String()
} else {
srcName = tableAlias.TableName.String()
}
return planDataSource{}, errors.Errorf(
"source %q has %d columns available but %d columns specified",
srcName, aliasIdx, len(colAlias))
}
if src.info.sourceColumns[colIdx].hidden {
continue
}
src.info.sourceColumns[colIdx].Name = string(colAlias[aliasIdx])
aliasIdx++
}
}
return src, nil
default:
return planDataSource{}, errors.Errorf("unsupported FROM type %T", src)
}
}