* Core implementation of generating documents for densify. Currently this supports both * `range` and `partition` mode of densify. */
| 783 | * `range` and `partition` mode of densify. |
| 784 | */ |
| 785 | static pgbson * |
| 786 | DensifyPartitionCore(PG_FUNCTION_ARGS, DensifyType type) |
| 787 | { |
| 788 | WindowObject winObject = PG_WINDOW_OBJECT(); |
| 789 | |
| 790 | bool isNull = false; |
| 791 | pgbson *spec = DatumGetPgBson(WinGetFuncArgCurrent(winObject, 1, &isNull)); |
| 792 | |
| 793 | DensifyWindowState *densifyState = NULL; |
| 794 | int argPosition = 1; |
| 795 | SetCachedFunctionState( |
| 796 | densifyState, |
| 797 | DensifyWindowState, |
| 798 | argPosition, |
| 799 | InitializeDensifyWindowState, |
| 800 | spec, |
| 801 | type); |
| 802 | |
| 803 | if (densifyState == NULL) |
| 804 | { |
| 805 | densifyState = palloc0(sizeof(DensifyWindowState)); |
| 806 | InitializeDensifyWindowState(densifyState, spec, type); |
| 807 | } |
| 808 | |
| 809 | pgbson *document = NULL; |
| 810 | isNull = false; |
| 811 | Datum documentDatum = WinGetFuncArgCurrent(winObject, 0, &isNull); |
| 812 | if (isNull) |
| 813 | { |
| 814 | if (type == DENSIFY_TYPE_RANGE && |
| 815 | densifyState->previousType == DENSIFY_DOCUMENT_VALID) |
| 816 | { |
| 817 | /* |
| 818 | * Ignore this row because NULL row is added via a UNION |
| 819 | * query to help generate documents in case of: |
| 820 | * - Non existing collection. |
| 821 | * - Empty collection. |
| 822 | * - Filtered collection with 0 rows. |
| 823 | */ |
| 824 | return NULL; |
| 825 | } |
| 826 | } |
| 827 | else |
| 828 | { |
| 829 | document = DatumGetPgBson(documentDatum); |
| 830 | } |
| 831 | |
| 832 | densifyState->previousType = isNull ? DENSIFY_DOCUMENT_NULL : DENSIFY_DOCUMENT_VALID; |
| 833 | |
| 834 | PartitionAwareState *partitionState = GetValidPartitionAwareState(densifyState, |
| 835 | document); |
| 836 | |
| 837 | /* Check if this is the last row in the partition */ |
| 838 | bool isOut = false; |
| 839 | isNull = false; |
| 840 | WinGetFuncArgInPartition(winObject, 1, 1, WINDOW_SEEK_CURRENT, false, |
| 841 | &isNull, &isOut); |
| 842 | partitionState->isLastRow = isOut; |
no test coverage detected