本文整理汇总了Golang中github.com/pingcap/tidb/ast.UnionStmt类的典型用法代码示例。如果您正苦于以下问题:Golang UnionStmt类的具体用法?Golang UnionStmt怎么用?Golang UnionStmt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UnionStmt类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: buildUnion
func (b *planBuilder) buildUnion(union *ast.UnionStmt) Plan {
sels := make([]Plan, len(union.SelectList.Selects))
for i, sel := range union.SelectList.Selects {
sels[i] = b.buildSelect(sel)
}
var p Plan
p = &Union{
Selects: sels,
}
unionFields := union.GetResultFields()
for _, sel := range sels {
for i, f := range sel.Fields() {
if i == len(unionFields) {
b.err = errors.New("The used SELECT statements have a different number of columns")
return nil
}
uField := unionFields[i]
/*
* The lengths of the columns in the UNION result take into account the values retrieved by all of the SELECT statements
* SELECT REPEAT('a',1) UNION SELECT REPEAT('b',10);
* +---------------+
* | REPEAT('a',1) |
* +---------------+
* | a |
* | bbbbbbbbbb |
* +---------------+
*/
if f.Column.Flen > uField.Column.Flen {
uField.Column.Flen = f.Column.Flen
}
// For select nul union select "abc", we should not convert "abc" to nil.
// And the result field type should be VARCHAR.
if uField.Column.Tp == 0 || uField.Column.Tp == mysql.TypeNull {
uField.Column.Tp = f.Column.Tp
}
}
addChild(p, sel)
}
for _, v := range unionFields {
v.Expr.SetType(&v.Column.FieldType)
}
p.SetFields(unionFields)
if union.Distinct {
p = b.buildDistinct(p)
}
if union.OrderBy != nil {
p = b.buildSort(p, union.OrderBy.Items)
}
if union.Limit != nil {
p = b.buildLimit(p, union.Limit)
}
return p
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:54,代码来源:planbuilder.go
示例2: convertUnion
func convertUnion(converter *expressionConverter, u *ast.UnionStmt) (*stmts.UnionStmt, error) {
oldUnion := &stmts.UnionStmt{
Text: u.Text(),
}
oldUnion.Selects = make([]*stmts.SelectStmt, len(u.Selects))
oldUnion.Distincts = make([]bool, len(u.Selects)-1)
if u.Distinct {
for i := range oldUnion.Distincts {
oldUnion.Distincts[i] = true
}
}
for i, val := range u.Selects {
oldSelect, err := convertSelect(converter, val)
if err != nil {
return nil, errors.Trace(err)
}
oldUnion.Selects[i] = oldSelect
}
if u.OrderBy != nil {
oldOrderBy, err := convertOrderBy(converter, u.OrderBy)
if err != nil {
return nil, errors.Trace(err)
}
oldUnion.OrderBy = oldOrderBy
}
if u.Limit != nil {
if u.Limit.Offset > 0 {
oldUnion.Offset = &rsets.OffsetRset{Count: u.Limit.Offset}
}
if u.Limit.Count > 0 {
oldUnion.Limit = &rsets.LimitRset{Count: u.Limit.Count}
}
}
// Union order by can not converted to old because it is pushed to select statements.
return oldUnion, nil
}
开发者ID:yzl11,项目名称:vessel,代码行数:36,代码来源:convert_stmt.go
注:本文中的github.com/pingcap/tidb/ast.UnionStmt类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论