promql/engine.go
func (ev *evaluator) matrixSelector(node *MatrixSelector) Matrix {
	checkForSeriesSetExpansion(ev.ctx, node)

	var (
		offset = durationMilliseconds(node.Offset)
		maxt   = ev.startTimestamp - offset
		mint   = maxt - durationMilliseconds(node.Range)
		matrix = make(Matrix, 0, len(node.series))
	)

	it := storage.NewBuffer(durationMilliseconds(node.Range))
	for i, s := range node.series {
		if err := contextDone(ev.ctx, "expression evaluation"); err != nil {
			ev.error(err)
		}
		it.Reset(s.Iterator())
		ss := Series{
			Metric: node.series[i].Labels(),
		}

		ss.Points = ev.matrixIterSlice(it, mint, maxt, getPointSlice(16))

		if len(ss.Points) > 0 {
			matrix = append(matrix, ss)
		} else {
			putPointSlice(ss.Points)
		}
	}
	return matrix
}
func (ev *evaluator) matrixSelector(node *MatrixSelector) Matrix {
	checkForSeriesSetExpansion(ev.ctx, node)

	var (
		offset = durationMilliseconds(node.Offset)
		maxt   = ev.startTimestamp - offset
		mint   = maxt - durationMilliseconds(node.Range)
		matrix = make(Matrix, 0, len(node.series))
	)

	it := storage.NewBuffer(durationMilliseconds(node.Range))
	for i, s := range node.series {
		if err := contextDone(ev.ctx, "expression evaluation"); err != nil {
			ev.error(err)
		}
		it.Reset(s.Iterator())
		ss := Series{
			Metric: node.series[i].Labels(),
		}

		ss.Points = ev.matrixIterSlice(it, mint, maxt, getPointSlice(16))

		if len(ss.Points) > 0 {
			matrix = append(matrix, ss)
		} else {
			putPointSlice(ss.Points)
		}
	}
	return matrix
}
func ( ev * evaluator ) matrixSelector ( node * MatrixSelector ) Matrix { checkForSeriesSetExpansion ( ev . ctx , node ) var ( offset = durationMilliseconds ( node . Offset ) maxt = ev . startTimestamp - offset mint = maxt - durationMilliseconds ( node . Range ) matrix = make ( Matrix , 0 , len ( node . series ) ) ) it := storage . NewBuffer ( durationMilliseconds ( node . Range ) ) for i , s := range node . series { if err := contextDone ( ev . ctx , " " ) ; err != nil { ev . error ( err ) } it . Reset ( s . Iterator ( ) ) ss := Series { Metric : node . series [ i ] . Labels ( ) , } ss . Points = ev . matrixIterSlice ( it , mint , maxt , getPointSlice ( 16 ) ) if len ( ss . Points ) > 0 { matrix = append ( matrix , ss ) } else { putPointSlice ( ss . Points ) } } return matrix }
// matrixSelector evaluates a *MatrixSelector expression.
matrixSelector evaluates a * MatrixSelector expression .