本文整理汇总了Golang中github.com/pingcap/tidb/ast.TableSource类的典型用法代码示例。如果您正苦于以下问题:Golang TableSource类的具体用法?Golang TableSource怎么用?Golang TableSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TableSource类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: handleTableSource
// handleTableSources checks name duplication
// and puts the table source in current resolverContext.
func (nr *nameResolver) handleTableSource(ts *ast.TableSource) {
for _, v := range ts.GetResultFields() {
v.TableAsName = ts.AsName
}
var name string
if ts.AsName.L != "" {
name = ts.AsName.L
} else {
tableName := ts.Source.(*ast.TableName)
name = nr.tableUniqueName(tableName.Schema, tableName.Name)
}
ctx := nr.currentContext()
if _, ok := ctx.tableMap[name]; ok {
nr.Err = errors.Errorf("duplicated table/alias name %s", name)
return
}
ctx.tableMap[name] = len(ctx.tables)
ctx.tables = append(ctx.tables, ts)
return
}
开发者ID:MDistribuntedSystem,项目名称:tidb,代码行数:22,代码来源:resolver.go
示例2: handleTableSource
// handleTableSources checks name duplication
// and puts the table source in current resolverContext.
// Note:
// "select * from t as a join (select 1) as a;" is not duplicate.
// "select * from t as a join t as a;" is duplicate.
// "select * from (select 1) as a join (select 1) as a;" is duplicate.
func (nr *nameResolver) handleTableSource(ts *ast.TableSource) {
for _, v := range ts.GetResultFields() {
v.TableAsName = ts.AsName
}
ctx := nr.currentContext()
switch ts.Source.(type) {
case *ast.TableName:
var name string
if ts.AsName.L != "" {
name = ts.AsName.L
} else {
tableName := ts.Source.(*ast.TableName)
name = nr.tableUniqueName(tableName.Schema, tableName.Name)
}
if _, ok := ctx.tableMap[name]; ok {
nr.Err = errors.Errorf("duplicated table/alias name %s", name)
return
}
ctx.tableMap[name] = len(ctx.tables)
case *ast.SelectStmt:
name := ts.AsName.L
if _, ok := ctx.derivedTableMap[name]; ok {
nr.Err = errors.Errorf("duplicated table/alias name %s", name)
return
}
ctx.derivedTableMap[name] = len(ctx.tables)
}
dupNames := make(map[string]struct{}, len(ts.GetResultFields()))
for _, f := range ts.GetResultFields() {
// duplicate column name in one table is not allowed.
// "select * from (select 1, 1) as a;" is duplicate.
name := f.ColumnAsName.L
if name == "" {
name = f.Column.Name.L
}
if _, ok := dupNames[name]; ok {
nr.Err = errors.Errorf("Duplicate column name '%s'", name)
return
}
dupNames[name] = struct{}{}
}
ctx.tables = append(ctx.tables, ts)
return
}
开发者ID:youprofit,项目名称:tidb,代码行数:50,代码来源:resolver.go
注:本文中的github.com/pingcap/tidb/ast.TableSource类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论