本文整理汇总了Golang中github.com/couchbase/query/value.AnnotatedValue.SetField方法的典型用法代码示例。如果您正苦于以下问题:Golang AnnotatedValue.SetField方法的具体用法?Golang AnnotatedValue.SetField怎么用?Golang AnnotatedValue.SetField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbase/query/value.AnnotatedValue
的用法示例。
在下文中一共展示了AnnotatedValue.SetField方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: processItem
func (this *DummyFetch) processItem(item value.AnnotatedValue, context *Context) bool {
item.SetField(this.plan.Term().Alias(), item)
if !this.sendItem(item) {
return false
}
return true
}
示例2: processMatch
func (this *Merge) processMatch(item value.AnnotatedValue,
context *Context, update, delete, insert Operator) bool {
kv, e := this.plan.Key().Evaluate(item, context)
if e != nil {
context.Error(errors.NewEvaluationError(e, "MERGE key"))
return false
}
ka := kv.Actual()
k, ok := ka.(string)
if !ok {
context.Error(errors.NewInvalidValueError(
fmt.Sprintf("Invalid MERGE key %v of type %T.", ka, ka)))
return false
}
timer := time.Now()
fetchOk := true
bvs, errs := this.plan.Keyspace().Fetch([]string{k})
this.duration += time.Since(timer)
for _, err := range errs {
context.Error(err)
if err.IsFatal() {
fetchOk = false
}
}
if len(bvs) > 0 {
bv := bvs[0]
item.SetField(this.plan.KeyspaceRef().Alias(), bv.Value)
// Perform UPDATE and/or DELETE
if update != nil {
update.Input().ItemChannel() <- item
}
if delete != nil {
delete.Input().ItemChannel() <- item
}
} else {
// Not matched; INSERT
if insert != nil {
insert.Input().ItemChannel() <- item
}
}
return fetchOk
}
示例3: 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
}
示例4: nestEntries
func (this *IndexNest) nestEntries(item value.AnnotatedValue,
entries []*datastore.IndexEntry, context *Context) (ok bool) {
var nvs []interface{}
if len(entries) > 0 {
covers := this.plan.Covers()
if len(covers) == 0 {
nvs, ok = this.fetch(entries, context)
if !ok {
return ok
}
} else {
nvs = make([]interface{}, len(entries))
for i, entry := range entries {
nv := value.NewAnnotatedValue(nil)
meta := map[string]interface{}{"id": entry.PrimaryKey}
nv.SetAttachment("meta", meta)
for i, c := range covers {
nv.SetCover(c.Text(), entry.EntryKey[i])
}
nvs[i] = nv
}
}
}
if len(nvs) > 0 {
item.SetField(this.plan.Term().Alias(), nvs)
} else {
if !this.plan.Outer() {
return true
}
item.SetField(this.plan.Term().Alias(), value.EMPTY_ARRAY_VALUE)
}
return this.sendItem(item)
}
示例5: 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
}
示例6: processItem
func (this *Nest) processItem(item value.AnnotatedValue, context *Context) bool {
kv, e := this.plan.Term().Keys().Evaluate(item, context)
if e != nil {
context.Error(errors.NewEvaluationError(e, "NEST 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 nest
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
if !found && !this.plan.Outer() {
return true
}
nvs := make([]interface{}, 0, len(pairs))
for _, pair := range pairs {
nestItem := pair.Value
var nv value.AnnotatedValue
// Apply projection, if any
projection := this.plan.Term().Projection()
if projection != nil {
projectedItem, e := projection.Evaluate(nestItem, context)
if e != nil {
context.Error(errors.NewEvaluationError(e, "nest path"))
return false
}
if projectedItem.Type() == value.MISSING {
continue
}
nv = value.NewAnnotatedValue(projectedItem)
nv.SetAnnotations(nestItem)
} else {
nv = nestItem
}
nvs = append(nvs, nv)
}
// Attach and send
item.SetField(this.plan.Term().Alias(), nvs)
return this.sendItem(item) && fetchOk
}