當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ast.TableSource類代碼示例

本文整理匯總了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;未經允許,請勿轉載。