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


Golang ast.SelectField類代碼示例

本文整理匯總了Golang中github.com/pingcap/tidb/ast.SelectField的典型用法代碼示例。如果您正苦於以下問題:Golang SelectField類的具體用法?Golang SelectField怎麽用?Golang SelectField使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了SelectField類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: createResultFields

// createResultFields creates result field list for a single select field.
func (nr *nameResolver) createResultFields(field *ast.SelectField) (rfs []*ast.ResultField) {
	ctx := nr.currentContext()
	if field.WildCard != nil {
		if len(ctx.tables) == 0 {
			nr.Err = errors.New("No table used.")
			return
		}
		if field.WildCard.Table.L == "" {
			for _, v := range ctx.tables {
				rfs = append(rfs, v.GetResultFields()...)
			}
		} else {
			name := nr.tableUniqueName(field.WildCard.Schema, field.WildCard.Table)
			tableIdx, ok := ctx.tableMap[name]
			if !ok {
				nr.Err = errors.Errorf("unknown table %s.", field.WildCard.Table.O)
			}
			rfs = ctx.tables[tableIdx].GetResultFields()
		}
		return
	}
	// The column is visited before so it must has been resolved already.
	rf := &ast.ResultField{ColumnAsName: field.AsName}
	innerExpr := getInnerFromParentheses(field.Expr)
	switch v := innerExpr.(type) {
	case *ast.ColumnNameExpr:
		rf.Column = v.Refer.Column
		rf.Table = v.Refer.Table
		rf.DBName = v.Refer.DBName
		rf.TableName = v.Refer.TableName
		rf.Expr = v.Refer.Expr
	default:
		rf.Column = &model.ColumnInfo{} // Empty column info.
		rf.Table = &model.TableInfo{}   // Empty table info.
		rf.Expr = v
	}
	if field.AsName.L == "" {
		switch x := innerExpr.(type) {
		case *ast.ColumnNameExpr:
			rf.ColumnAsName = model.NewCIStr(x.Name.Name.O)
		case *ast.ValueExpr:
			if innerExpr.Text() != "" {
				rf.ColumnAsName = model.NewCIStr(innerExpr.Text())
			} else {
				rf.ColumnAsName = model.NewCIStr(field.Text())
			}
		default:
			rf.ColumnAsName = model.NewCIStr(field.Text())
		}
	}
	rfs = append(rfs, rf)
	return
}
開發者ID:xudongQiu,項目名稱:tidb,代碼行數:54,代碼來源:resolver.go

示例2: createResultFields

// createResultFields creates result field list for a single select field.
func (nr *nameResolver) createResultFields(field *ast.SelectField) (rfs []*ast.ResultField) {
	ctx := nr.currentContext()
	if field.WildCard != nil {
		if len(ctx.tables) == 0 {
			nr.Err = errors.New("No table used.")
			return
		}
		tableRfs := []*ast.ResultField{}
		if field.WildCard.Table.L == "" {
			for _, v := range ctx.tables {
				tableRfs = append(tableRfs, v.GetResultFields()...)
			}
		} else {
			name := nr.tableUniqueName(field.WildCard.Schema, field.WildCard.Table)
			tableIdx, ok1 := ctx.tableMap[name]
			derivedTableIdx, ok2 := ctx.derivedTableMap[name]
			if !ok1 && !ok2 {
				nr.Err = errors.Errorf("unknown table %s.", field.WildCard.Table.O)
			}
			if ok1 {
				tableRfs = ctx.tables[tableIdx].GetResultFields()
			}
			if ok2 {
				tableRfs = append(tableRfs, ctx.tables[derivedTableIdx].GetResultFields()...)
			}

		}
		for _, trf := range tableRfs {
			// Convert it to ColumnNameExpr
			cn := &ast.ColumnName{
				Schema: trf.DBName,
				Table:  trf.Table.Name,
				Name:   trf.ColumnAsName,
			}
			cnExpr := &ast.ColumnNameExpr{
				Name:  cn,
				Refer: trf,
			}
			ast.SetFlag(cnExpr)
			cnExpr.SetType(trf.Expr.GetType())
			rf := *trf
			rf.Expr = cnExpr
			rfs = append(rfs, &rf)
		}
		return
	}
	// The column is visited before so it must has been resolved already.
	rf := &ast.ResultField{ColumnAsName: field.AsName}
	innerExpr := getInnerFromParentheses(field.Expr)
	switch v := innerExpr.(type) {
	case *ast.ColumnNameExpr:
		rf.Column = v.Refer.Column
		rf.Table = v.Refer.Table
		rf.DBName = v.Refer.DBName
		rf.TableName = v.Refer.TableName
		rf.Expr = v
	default:
		rf.Column = &model.ColumnInfo{} // Empty column info.
		rf.Table = &model.TableInfo{}   // Empty table info.
		rf.Expr = v
	}
	if field.AsName.L == "" {
		switch x := innerExpr.(type) {
		case *ast.ColumnNameExpr:
			rf.ColumnAsName = model.NewCIStr(x.Name.Name.O)
		case *ast.ValueExpr:
			if innerExpr.Text() != "" {
				rf.ColumnAsName = model.NewCIStr(innerExpr.Text())
			} else {
				rf.ColumnAsName = model.NewCIStr(field.Text())
			}
		default:
			rf.ColumnAsName = model.NewCIStr(field.Text())
		}
	}
	rfs = append(rfs, rf)
	return
}
開發者ID:youprofit,項目名稱:tidb,代碼行數:79,代碼來源:resolver.go


注:本文中的github.com/pingcap/tidb/ast.SelectField類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。