本文整理汇总了Golang中github.com/couchbase/query/value.AnnotatedValue.Copy方法的典型用法代码示例。如果您正苦于以下问题:Golang AnnotatedValue.Copy方法的具体用法?Golang AnnotatedValue.Copy怎么用?Golang AnnotatedValue.Copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbase/query/value.AnnotatedValue
的用法示例。
在下文中一共展示了AnnotatedValue.Copy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: processItem
func (this *Unnest) processItem(item value.AnnotatedValue, context *Context) bool {
ev, err := this.plan.Term().Expression().Evaluate(item, context)
if err != nil {
context.Error(errors.NewEvaluationError(err, "UNNEST path"))
return false
}
actuals := ev.Actual()
switch actuals.(type) {
case []interface{}:
case nil:
actuals = []interface{}(nil)
default:
actuals = []interface{}{actuals}
}
acts := actuals.([]interface{})
if len(acts) == 0 {
// Outer unnest
return !this.plan.Term().Outer() || this.sendItem(item)
}
// Attach and send
for i, act := range acts {
var av value.AnnotatedValue
if i < len(acts)-1 {
av = value.NewAnnotatedValue(item.Copy())
} else {
av = item
}
actv := value.NewAnnotatedValue(act)
actv.SetAttachment("unnest_position", i)
av.SetField(this.plan.Alias(), actv)
if !this.sendItem(av) {
return false
}
}
return true
}
示例2: joinEntry
func (this *IndexJoin) joinEntry(item value.AnnotatedValue,
entry *datastore.IndexEntry, context *Context) (found, ok bool) {
var jv value.AnnotatedValue
covers := this.plan.Covers()
if len(covers) == 0 {
jv, ok = this.fetch(entry, context)
if jv == nil || !ok {
return jv != nil, ok
}
} else {
jv = value.NewAnnotatedValue(nil)
meta := map[string]interface{}{"id": entry.PrimaryKey}
jv.SetAttachment("meta", meta)
for i, c := range covers {
jv.SetCover(c.Text(), entry.EntryKey[i])
}
}
joined := item.Copy().(value.AnnotatedValue)
joined.SetField(this.plan.Term().Alias(), jv)
return true, this.sendItem(joined)
}
示例3: processItem
func (this *Join) processItem(item value.AnnotatedValue, context *Context) bool {
kv, e := this.plan.Term().Keys().Evaluate(item, context)
if e != nil {
context.Error(errors.NewEvaluationError(e, "JOIN keys"))
return false
}
actuals := kv.Actual()
switch actuals.(type) {
case []interface{}:
case nil:
actuals = []interface{}(nil)
default:
actuals = []interface{}{actuals}
}
acts := actuals.([]interface{})
if len(acts) == 0 {
// Outer join
return !this.plan.Outer() || this.sendItem(item)
}
// Build list of keys
keys := make([]string, 0, len(acts))
for _, key := range acts {
k := value.NewValue(key).Actual()
switch k := k.(type) {
case string:
keys = append(keys, k)
}
}
timer := time.Now()
// Fetch
pairs, errs := this.plan.Keyspace().Fetch(keys)
this.duration += time.Since(timer)
fetchOk := true
for _, err := range errs {
context.Error(err)
if err.IsFatal() {
fetchOk = false
}
}
found := len(pairs) > 0
// Attach and send
for i, pair := range pairs {
joinItem := pair.Value
var jv value.AnnotatedValue
// Apply projection, if any
projection := this.plan.Term().Projection()
if projection != nil {
projectedItem, e := projection.Evaluate(joinItem, context)
if e != nil {
context.Error(errors.NewEvaluationError(e, "join path"))
return false
}
jv = value.NewAnnotatedValue(projectedItem)
jv.SetAnnotations(joinItem)
} else {
jv = joinItem
}
var av value.AnnotatedValue
if i < len(pairs)-1 {
av = value.NewAnnotatedValue(item.Copy())
} else {
av = item
}
av.SetField(this.plan.Term().Alias(), jv)
if !this.sendItem(av) {
return false
}
}
return (found || !this.plan.Outer() || this.sendItem(item)) && fetchOk
}