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 }
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) }
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) }