getValueByOffset returns a datum calculated as the value of the current row in the column over which rows are ordered plus/minus logic offset, and an error if encountered. It should be used only in RANGE mode.
( ctx context.Context, evalCtx *EvalContext, offset Datum, negative bool, )
| 82 | // in the column over which rows are ordered plus/minus logic offset, and an |
| 83 | // error if encountered. It should be used only in RANGE mode. |
| 84 | func (wfr *WindowFrameRun) getValueByOffset( |
| 85 | ctx context.Context, evalCtx *EvalContext, offset Datum, negative bool, |
| 86 | ) (Datum, error) { |
| 87 | if wfr.OrdDirection == encoding.Descending { |
| 88 | // If rows are in descending order, we want to perform the "opposite" |
| 89 | // addition/subtraction to default ascending order. |
| 90 | negative = !negative |
| 91 | } |
| 92 | var binOp *BinOp |
| 93 | if negative { |
| 94 | binOp = wfr.MinusOp |
| 95 | } else { |
| 96 | binOp = wfr.PlusOp |
| 97 | } |
| 98 | value, err := wfr.valueAt(ctx, wfr.RowIdx) |
| 99 | if err != nil { |
| 100 | return nil, err |
| 101 | } |
| 102 | if value == DNull { |
| 103 | return DNull, nil |
| 104 | } |
| 105 | return binOp.Fn(evalCtx, value, offset) |
| 106 | } |
| 107 | |
| 108 | // FrameStartIdx returns the index of starting row in the frame (which is the first to be included). |
| 109 | func (wfr *WindowFrameRun) FrameStartIdx(ctx context.Context, evalCtx *EvalContext) (int, error) { |
no test coverage detected