@@ -960,7 +960,7 @@ type profileMatchIterator struct {
960960 lbls map [int64 ]labelsInfo
961961}
962962
963- func newProfileMatchIterator (file * parquet.File , lbls map [int64 ]labelsInfo ) * profileMatchIterator {
963+ func newProfileMatchIterator (file * parquet.File , lbls map [int64 ]labelsInfo ) query. Iterator {
964964 it := & profileMatchIterator {file : file , lbls : lbls }
965965 timeNanosIndex , _ := query .GetColumnIndexByPath (file , "TimeNanos" )
966966 it .rowGroups = file .RowGroups ()
@@ -993,6 +993,11 @@ type parquetUint32Reader interface {
993993 ReadUint32s (values []uint32 ) (int , error )
994994}
995995
996+ func (it * profileMatchIterator ) Seek (to query.RowNumberWithDefinitionLevel ) bool {
997+ panic ("not seeking for anyone" )
998+ return false
999+ }
1000+
9961001func (it * profileMatchIterator ) readNextRowGroup () error {
9971002 rg := it .rowGroups [it .currentRowGroup ]
9981003 //it.currentRowGroup++
@@ -1093,8 +1098,7 @@ func (it *profileMatchIterator) Close() error {
10931098 return nil
10941099}
10951100
1096- func (it * profileMatchIterator ) At () Profile {
1097-
1101+ func (it * profileMatchIterator ) At () * query.IteratorResult {
10981102 panic ("xx" )
10991103 return nil
11001104}
@@ -1145,97 +1149,61 @@ func (b *singleBlockQuerier) SelectMatchingProfiles(ctx context.Context, params
11451149 }
11461150 }
11471151
1148- /*
1149- var (
1150- buf [][]parquet.Value
1151- joinIters []query.Iterator
1152- )
1153- pgIdx := 0
1154-
1155- pages := cc.Pages()
1156-
1157- for {
1158- pg, err := pages.ReadPage()
1159- if err == io.EOF {
1160- break
1161- }
1162- if err != nil {
1163- return nil, err
1164- }
1165-
1166- valueReader := pg.Values()
1167- vR, ok := valueReader.(parquet.Int64Reader)
1168- if !ok {
1169- return nil, fmt.Errorf("unexpected type for value reader %T", valueReader)
1170- }
1171-
1172- values := make([]int64, pg.NumValues())
1173- _, err = vR.ReadInt64s(values)
1174- if err != nil && err != io.EOF {
1175- return nil, err
1176- }
1177-
1178- fmt.Printf("numValues=%+#v\n ", pg.NumValues())
1179-
1180- pgIdx++
1181-
1182- }
1183-
1184- }
1185- */
1186-
1187- return newProfileMatchIterator (b .profiles .file , lblsPerRef ), nil
1152+ var (
1153+ buf [][]parquet.Value
1154+ joinIters []query.Iterator
1155+ )
11881156
1189- /*
1157+ seriesIndexIter := newProfileMatchIterator ( b . profiles . file , lblsPerRef )
11901158
1191- if b.meta.Version >= 2 {
1192- joinIters = []query.Iterator{
1193- b.profiles.columnIter(ctx, "SeriesIndex", newMapPredicate(lblsPerRef), "SeriesIndex"),
1194- b.profiles.columnIter(ctx, "TimeNanos", query.NewIntBetweenPredicate(model.Time(params.Start).UnixNano(), model.Time(params.End).UnixNano()), "TimeNanos"),
1195- b.profiles.columnIter(ctx, "StacktracePartition", nil, "StacktracePartition"),
1196- }
1197- buf = make([][]parquet.Value, 3)
1198- } else {
1199- joinIters = []query.Iterator{
1200- b.profiles.columnIter(ctx, "SeriesIndex", newMapPredicate(lblsPerRef), "SeriesIndex"),
1201- b.profiles.columnIter(ctx, "TimeNanos", query.NewIntBetweenPredicate(model.Time(params.Start).UnixNano(), model.Time(params.End).UnixNano()), "TimeNanos"),
1202- }
1203- buf = make([][]parquet.Value, 2)
1159+ if b .meta .Version >= 2 {
1160+ joinIters = []query.Iterator {
1161+ seriesIndexIter ,
1162+ b .profiles .columnIter (ctx , "SeriesIndex" , newMapPredicate (lblsPerRef ), "SeriesIndex" ),
1163+ b .profiles .columnIter (ctx , "TimeNanos" , query .NewIntBetweenPredicate (model .Time (params .Start ).UnixNano (), model .Time (params .End ).UnixNano ()), "TimeNanos" ),
1164+ b .profiles .columnIter (ctx , "StacktracePartition" , nil , "StacktracePartition" ),
12041165 }
1205-
1206- pIt := query.NewJoinIterator(0, joinIters, nil)
1207- iters := make([]iter.Iterator[Profile], 0, len(lblsPerRef))
1208- defer pIt.Close()
1209-
1210- currSeriesIndex := int64(-1)
1211- var currentSeriesSlice []Profile
1212- for pIt.Next() {
1213- res := pIt.At()
1214- buf = res.Columns(buf, "SeriesIndex", "TimeNanos", "StacktracePartition")
1215- seriesIndex := buf[0][0].Int64()
1216- if seriesIndex != currSeriesIndex {
1217- currSeriesIndex = seriesIndex
1218- if len(currentSeriesSlice) > 0 {
1219- fmt.Println(len(currentSeriesSlice))
1220- iters = append(iters, iter.NewSliceIterator(currentSeriesSlice))
1221- }
1222- currentSeriesSlice = make([]Profile, 0, 100)
1223- }
1224-
1225- currentSeriesSlice = append(currentSeriesSlice, BlockProfile{
1226- labels: lblsPerRef[seriesIndex].lbs,
1227- fp: lblsPerRef[seriesIndex].fp,
1228- ts: model.TimeFromUnixNano(buf[1][0].Int64()),
1229- stacktracePartition: retrieveStacktracePartition(buf, 2),
1230- RowNum: res.RowNumber[0],
1231- })
1166+ buf = make ([][]parquet.Value , 3 )
1167+ } else {
1168+ joinIters = []query.Iterator {
1169+ seriesIndexIter ,
1170+ b .profiles .columnIter (ctx , "TimeNanos" , query .NewIntBetweenPredicate (model .Time (params .Start ).UnixNano (), model .Time (params .End ).UnixNano ()), "TimeNanos" ),
12321171 }
1233- if len(currentSeriesSlice) > 0 {
1234- iters = append(iters, iter.NewSliceIterator(currentSeriesSlice))
1172+ buf = make ([][]parquet.Value , 2 )
1173+ }
1174+
1175+ pIt := query .NewJoinIterator (0 , joinIters , nil )
1176+ iters := make ([]iter.Iterator [Profile ], 0 , len (lblsPerRef ))
1177+ defer pIt .Close ()
1178+
1179+ currSeriesIndex := int64 (- 1 )
1180+ var currentSeriesSlice []Profile
1181+ for pIt .Next () {
1182+ res := pIt .At ()
1183+ buf = res .Columns (buf , "SeriesIndex" , "TimeNanos" , "StacktracePartition" )
1184+ seriesIndex := buf [0 ][0 ].Int64 ()
1185+ if seriesIndex != currSeriesIndex {
1186+ currSeriesIndex = seriesIndex
1187+ if len (currentSeriesSlice ) > 0 {
1188+ fmt .Println (len (currentSeriesSlice ))
1189+ iters = append (iters , iter .NewSliceIterator (currentSeriesSlice ))
1190+ }
1191+ currentSeriesSlice = make ([]Profile , 0 , 100 )
12351192 }
12361193
1237- return iter.NewMergeIterator(maxBlockProfile, false, iters...), nil
1238- */
1194+ currentSeriesSlice = append (currentSeriesSlice , BlockProfile {
1195+ labels : lblsPerRef [seriesIndex ].lbs ,
1196+ fp : lblsPerRef [seriesIndex ].fp ,
1197+ ts : model .TimeFromUnixNano (buf [1 ][0 ].Int64 ()),
1198+ stacktracePartition : retrieveStacktracePartition (buf , 2 ),
1199+ RowNum : res .RowNumber [0 ],
1200+ })
1201+ }
1202+ if len (currentSeriesSlice ) > 0 {
1203+ iters = append (iters , iter .NewSliceIterator (currentSeriesSlice ))
1204+ }
1205+
1206+ return iter .NewMergeIterator (maxBlockProfile , false , iters ... ), nil
12391207}
12401208
12411209func (b * singleBlockQuerier ) Sort (in []Profile ) []Profile {
0 commit comments