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