func NewDistinct(collect bool) *Distinct { rv := &Distinct{ base: newBase(), set: value.NewSet(_DISTINCT_CAP), collect: collect, } rv.output = rv return rv }
/* Add input item to the cumulative set. Get the set. If no errors enountered add the item to the set and return it. If set has not been initialized yet, create a new set with capacity _OBJECT_CAP and add the item. Return the set value. */ func setAdd(item, cumulative value.Value) (value.Value, error) { set, e := getSet(cumulative) if e == nil { set.Add(item) return cumulative, nil } set = value.NewSet(_OBJECT_CAP) set.Add(item) av := value.NewAnnotatedValue(nil) av.SetAttachment("set", set) return av, nil }
/* This method returns the input array with distinct elements. If the input value is of type missing return a missing value, and for all non array values return null. Create a new set and add all distinct values to the set. Return it. */ func (this *ArrayDistinct) Apply(context Context, arg value.Value) (value.Value, error) { if arg.Type() == value.MISSING { return value.MISSING_VALUE, nil } else if arg.Type() != value.ARRAY { return value.NULL_VALUE, nil } aa := arg.Actual().([]interface{}) set := value.NewSet(len(aa)) for _, a := range aa { set.Add(value.NewValue(a)) } return value.NewValue(set.Actuals()), nil }
func (this *Distinct) Copy() Operator { return &Distinct{ base: this.base.copy(), set: value.NewSet(_DISTINCT_CAP), } }