@@ -29,7 +29,6 @@ import (
2929type groupConcatExec struct {
3030 multiAggInfo
3131 ret aggResultWithBytesType
32- distinctHash
3332
3433 separator []byte
3534}
@@ -40,22 +39,20 @@ func (exec *groupConcatExec) GetOptResult() SplitResult {
4039
4140func (exec * groupConcatExec ) marshal () ([]byte , error ) {
4241 d := exec .multiAggInfo .getEncoded ()
43- r , em , err := exec .ret .marshalToBytes ()
42+ r , em , dist , err := exec .ret .marshalToBytes ()
4443 if err != nil {
4544 return nil , err
4645 }
4746 encoded := EncodedAgg {
4847 Info : d ,
4948 Result : r ,
5049 Empties : em ,
51- Groups : [][]byte {exec .separator },
50+ // Oh, this is so f**ked.
51+ Groups : [][]byte {exec .separator },
5252 }
53- if exec .IsDistinct () {
54- data , err := exec .distinctHash .marshal ()
55- if err != nil {
56- return nil , err
57- }
58- encoded .Groups = append (encoded .Groups , data )
53+
54+ if dist != nil {
55+ encoded .Groups = append (encoded .Groups , dist ... )
5956 }
6057 return encoded .Marshal ()
6158}
@@ -64,27 +61,34 @@ func (exec *groupConcatExec) unmarshal(_ *mpool.MPool, result, empties, groups [
6461 if err := exec .SetExtraInformation (groups [0 ], 0 ); err != nil {
6562 return err
6663 }
67- if exec .IsDistinct () {
68- if len (groups ) > 1 {
69- if err := exec .distinctHash .unmarshal (groups [1 ]); err != nil {
70- return err
71- }
72- }
73- }
74- return exec .ret .unmarshalFromBytes (result , empties )
64+ return exec .ret .unmarshalFromBytes (result , empties , groups [1 :])
7565}
7666
7767func (exec * groupConcatExec ) SaveIntermediateResult (bucketIdx []int64 , bucket int64 , buf * bytes.Buffer ) error {
78- return marshalRetAndGroupsAndDistinctHashToBuffers [dummyBinaryMarshaler ](
68+ err := marshalRetAndGroupsToBuffer [dummyBinaryMarshaler ](
7969 bucketIdx , bucket , buf ,
80- & exec .ret .optSplitResult , nil ,
81- exec .IsDistinct (), & exec .distinctHash )
70+ & exec .ret .optSplitResult , nil )
71+ if err != nil {
72+ return err
73+ }
74+
75+ if err = types .WriteSizeBytes (exec .separator , buf ); err != nil {
76+ return err
77+ }
78+ return nil
8279}
8380
8481func (exec * groupConcatExec ) SaveIntermediateResultOfChunk (chunk int , buf * bytes.Buffer ) error {
85- return marshalChunkToBuffer [dummyBinaryMarshaler ](chunk , buf ,
86- & exec .ret .optSplitResult , nil ,
87- exec .IsDistinct (), & exec .distinctHash )
82+ err := marshalChunkToBuffer [dummyBinaryMarshaler ](chunk , buf ,
83+ & exec .ret .optSplitResult , nil )
84+ if err != nil {
85+ return err
86+ }
87+
88+ if err = types .WriteSizeBytes (exec .separator , buf ); err != nil {
89+ return err
90+ }
91+ return nil
8892}
8993
9094func GroupConcatReturnType (args []types.Type ) types.Type {
@@ -99,12 +103,9 @@ func GroupConcatReturnType(args []types.Type) types.Type {
99103func newGroupConcatExec (mg AggMemoryManager , info multiAggInfo , separator string ) AggFuncExec {
100104 exec := & groupConcatExec {
101105 multiAggInfo : info ,
102- ret : initAggResultWithBytesTypeResult (mg , info .retType , info .emptyNull , "" ),
106+ ret : initAggResultWithBytesTypeResult (mg , info .retType , info .emptyNull , "" , info . distinct ),
103107 separator : []byte (separator ),
104108 }
105- if info .distinct {
106- exec .distinctHash = newDistinctHash ()
107- }
108109 return exec
109110}
110111
@@ -116,11 +117,6 @@ func isValidGroupConcatUnit(value []byte) error {
116117}
117118
118119func (exec * groupConcatExec ) GroupGrow (more int ) error {
119- if exec .IsDistinct () {
120- if err := exec .distinctHash .grows (more ); err != nil {
121- return err
122- }
123- }
124120 return exec .ret .grows (more )
125121}
126122
@@ -137,14 +133,13 @@ func (exec *groupConcatExec) Fill(groupIndex int, row int, vectors []*vector.Vec
137133 }
138134 }
139135
140- if exec .IsDistinct () {
141- if need , err := exec .distinctHash .fill (groupIndex , vectors , row ); err != nil || ! need {
142- return err
143- }
144- }
145-
146136 x , y := exec .ret .updateNextAccessIdx (groupIndex )
147137 exec .ret .setGroupNotEmpty (x , y )
138+
139+ if need , err := exec .ret .distinctFill (x , y , vectors , row ); err != nil || ! need {
140+ return err
141+ }
142+
148143 r := exec .ret .get ()
149144 if len (r ) > 0 {
150145 r = append (r , exec .separator ... )
@@ -189,7 +184,8 @@ func (exec *groupConcatExec) SetExtraInformation(partialResult any, _ int) error
189184func (exec * groupConcatExec ) merge (other * groupConcatExec , idx1 , idx2 int ) error {
190185 x1 , y1 := exec .ret .updateNextAccessIdx (idx1 )
191186 x2 , y2 := other .ret .updateNextAccessIdx (idx2 )
192- if err := exec .distinctHash .merge (& other .distinctHash ); err != nil {
187+
188+ if err := exec .ret .distinctMerge (x1 , & other .ret .optSplitResult , x2 ); err != nil {
193189 return err
194190 }
195191 empty1 , empty2 := exec .ret .isGroupEmpty (x1 , y1 ), other .ret .isGroupEmpty (x2 , y2 )
@@ -230,12 +226,11 @@ func (exec *groupConcatExec) Flush() ([]*vector.Vector, error) {
230226}
231227
232228func (exec * groupConcatExec ) Free () {
233- exec .distinctHash .free ()
234229 exec .ret .free ()
235230}
236231
237232func (exec * groupConcatExec ) Size () int64 {
238- return exec .ret .Size () + exec . distinctHash . Size () + int64 (cap (exec .separator ))
233+ return exec .ret .Size () + int64 (cap (exec .separator ))
239234}
240235
241236var GroupConcatUnsupportedTypes = []types.T {
0 commit comments