* WinGetFuncArgInPartition * Evaluate a window function's argument expression on a specified * row of the partition. The row is identified in lseek(2) style, * i.e. relative to the current, first, or last row. * * argno: argument number to evaluate (counted from 0) * relpos: signed rowcount offset from the seek position * seektype: WINDOW_SEEK_CURRENT, WINDOW_SEEK_HEAD, or WINDOW_SEEK_T
| 3584 | * (plus setting *isout true, if isout isn't NULL). |
| 3585 | */ |
| 3586 | Datum |
| 3587 | WinGetFuncArgInPartition(WindowObject winobj, int argno, |
| 3588 | int relpos, int seektype, bool set_mark, |
| 3589 | bool *isnull, bool *isout) |
| 3590 | { |
| 3591 | WindowAggState *winstate; |
| 3592 | ExprContext *econtext; |
| 3593 | TupleTableSlot *slot; |
| 3594 | bool gottuple; |
| 3595 | int64 abs_pos; |
| 3596 | |
| 3597 | Assert(WindowObjectIsValid(winobj)); |
| 3598 | winstate = winobj->winstate; |
| 3599 | econtext = winstate->ss.ps.ps_ExprContext; |
| 3600 | slot = winstate->temp_slot_1; |
| 3601 | |
| 3602 | switch (seektype) |
| 3603 | { |
| 3604 | case WINDOW_SEEK_CURRENT: |
| 3605 | abs_pos = winstate->currentpos + relpos; |
| 3606 | break; |
| 3607 | case WINDOW_SEEK_HEAD: |
| 3608 | abs_pos = relpos; |
| 3609 | break; |
| 3610 | case WINDOW_SEEK_TAIL: |
| 3611 | spool_tuples(winstate, -1); |
| 3612 | abs_pos = winstate->spooled_rows - 1 + relpos; |
| 3613 | break; |
| 3614 | default: |
| 3615 | elog(ERROR, "unrecognized window seek type: %d", seektype); |
| 3616 | abs_pos = 0; /* keep compiler quiet */ |
| 3617 | break; |
| 3618 | } |
| 3619 | |
| 3620 | gottuple = window_gettupleslot(winobj, abs_pos, slot); |
| 3621 | |
| 3622 | if (!gottuple) |
| 3623 | { |
| 3624 | if (isout) |
| 3625 | *isout = true; |
| 3626 | *isnull = true; |
| 3627 | return (Datum) 0; |
| 3628 | } |
| 3629 | else |
| 3630 | { |
| 3631 | if (isout) |
| 3632 | *isout = false; |
| 3633 | if (set_mark) |
| 3634 | WinSetMarkPosition(winobj, abs_pos); |
| 3635 | econtext->ecxt_outertuple = slot; |
| 3636 | return ExecEvalExpr((ExprState *) list_nth(winobj->argstates, argno), |
| 3637 | econtext, isnull); |
| 3638 | } |
| 3639 | } |
| 3640 | |
| 3641 | /* |
| 3642 | * WinGetFuncArgInFrame |
no test coverage detected