| 893 | }; |
| 894 | |
| 895 | std::optional<MergeJoinAlgorithm::Status> MergeJoinAlgorithm::handleAnyJoinState() |
| 896 | { |
| 897 | if (any_join_state.empty()) |
| 898 | return {}; |
| 899 | |
| 900 | Chunk result; |
| 901 | |
| 902 | for (size_t source_num = 0; source_num < 2; ++source_num) |
| 903 | { |
| 904 | auto & current = cursors[source_num]; |
| 905 | if (any_join_state.keys[source_num].equals(current)) |
| 906 | { |
| 907 | size_t start_pos = current.getRow(); |
| 908 | size_t length = nextDistinct(current); |
| 909 | |
| 910 | if (length && isLeft(kind) && source_num == 0) |
| 911 | { |
| 912 | if (any_join_state.value) |
| 913 | result = copyChunkResized(current.getCurrent(), any_join_state.value, start_pos, length); |
| 914 | else |
| 915 | result = createBlockWithDefaults(source_num, start_pos, length); |
| 916 | } |
| 917 | |
| 918 | if (length && isRight(kind) && source_num == 1) |
| 919 | { |
| 920 | if (any_join_state.value) |
| 921 | result = copyChunkResized(any_join_state.value, current.getCurrent(), start_pos, length); |
| 922 | else |
| 923 | result = createBlockWithDefaults(source_num, start_pos, length); |
| 924 | } |
| 925 | |
| 926 | if (current.isValid()) |
| 927 | any_join_state.keys[source_num].reset(); |
| 928 | } |
| 929 | else |
| 930 | { |
| 931 | any_join_state.keys[source_num].reset(); |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | if (result) |
| 936 | return Status(std::move(result)); |
| 937 | return {}; |
| 938 | } |
| 939 | |
| 940 | MergeJoinAlgorithm::Status MergeJoinAlgorithm::anyJoin() |
| 941 | { |