本文整理汇总了Golang中github.com/couchbaselabs/dparval.Value.SetAttachment方法的典型用法代码示例。如果您正苦于以下问题:Golang Value.SetAttachment方法的具体用法?Golang Value.SetAttachment怎么用?Golang Value.SetAttachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbaselabs/dparval.Value
的用法示例。
在下文中一共展示了Value.SetAttachment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setAggregateValue
func setAggregateValue(item *dparval.Value, key string, val *dparval.Value) {
aggregates := item.GetAttachment("aggregates")
aggregatesMap, ok := aggregates.(map[string]interface{})
if !ok {
// create a new aggregates map
aggregatesMap = map[string]interface{}{}
item.SetAttachment("aggregates", aggregatesMap)
}
aggregatesMap[key] = val
}
示例2: processItem
func (this *Project) processItem(item *dparval.Value) bool {
resultMap := map[string]interface{}{}
for _, resultItem := range this.Result {
val, err := this.Base.projectedValueOfResultExpression(item, resultItem)
if err != nil {
switch err := err.(type) {
case *dparval.Undefined:
// undefined contributes nothing to the result map
continue
default:
return this.Base.SendError(query.NewError(err, "unexpected error projecting expression"))
}
}
if resultItem.Star {
if val != nil {
valval := val.Value()
switch valval := valval.(type) {
case map[string]interface{}:
// then if the result was an object
// add its contents ot the result map
for k, v := range valval {
resultMap[k] = v
}
}
}
} else {
resultMap[resultItem.As] = val
}
}
if !this.projectEmpty && len(resultMap) == 0 {
return true
}
// build a Value from the projection
projection := dparval.NewValue(resultMap)
// store the projection as an attachment on the main item
item.SetAttachment("projection", projection)
clog.To(DEBUG_PROJECT_CHANNEL, "projecting: %v", item)
// write to the output
return this.Base.SendItem(item)
}
示例3: Evaluate
func (this *BaseOperator) Evaluate(e ast.Expression, item *dparval.Value) (*dparval.Value, error) {
// first ensure the query is avaliable
item.SetAttachment("query", this.query)
return e.Evaluate(item)
}