func (this *InitialProject) processTerms(item value.AnnotatedValue, context *Context) bool { n := len(this.plan.Terms()) var f map[string]interface{} if item.Type() == value.OBJECT { f = item.Copy().Fields() } if f == nil { f = make(map[string]interface{}, n) } pv := value.NewAnnotatedValue(f) pv.SetAttachments(item.Attachments()) p := value.NewValue(make(map[string]interface{}, n+32)) pv.SetAttachment("projection", p) for _, term := range this.plan.Terms() { if term.Result().Alias() != "" { v, err := term.Result().Expression().Evaluate(item, context) if err != nil { context.Error(errors.NewError(err, "Error evaluating projection.")) return false } p.SetField(term.Result().Alias(), v) // Explicit aliases override data if term.Result().As() != "" { pv.SetField(term.Result().As(), v) } } else { // Star starval := item.GetValue() if term.Result().Expression() != nil { var err error starval, err = term.Result().Expression().Evaluate(item, context) if err != nil { context.Error(errors.NewError(err, "Error evaluating projection.")) return false } } // Latest star overwrites previous star switch sa := starval.Actual().(type) { case map[string]interface{}: for k, v := range sa { p.SetField(k, v) } } } } return this.sendItem(pv) }
func (this *Let) processItem(item value.AnnotatedValue, context *Context) bool { n := len(this.plan.Bindings()) cv := value.NewScopeValue(make(map[string]interface{}, n), item) lv := value.NewAnnotatedValue(cv) lv.SetAttachments(item.Attachments()) for _, b := range this.plan.Bindings() { v, e := b.Expression().Evaluate(item, context) if e != nil { context.Error(errors.NewError(e, "Error evaluating LET.")) return false } lv.SetField(b.Variable(), v) } return this.sendItem(lv) }
func setPath(t *algebra.SetTerm, clone, item value.AnnotatedValue, context *Context) (value.AnnotatedValue, error) { if t.UpdateFor() != nil { return setFor(t, clone, item, context) } v, err := t.Value().Evaluate(item, context) if err != nil { return nil, err } if v.Type() == value.MISSING { } if t.Path() != nil { t.Path().Set(clone, v, context) return clone, nil } else { av := value.NewAnnotatedValue(v) av.SetAttachments(clone.Attachments()) return av, nil } }
func (this *Alias) processItem(item value.AnnotatedValue, context *Context) bool { av := value.NewAnnotatedValue(make(map[string]interface{})) av.SetAttachments(item.Attachments()) av.SetField(this.plan.Alias(), item) return this.sendItem(av) }