@@ -918,6 +918,7 @@ pub(crate) fn get_final_indices_from_bit_map(
918918 ( left_indices, right_indices)
919919}
920920
921+ #[ expect( clippy:: too_many_arguments) ]
921922pub ( crate ) fn apply_join_filter_to_indices (
922923 build_input_buffer : & RecordBatch ,
923924 probe_batch : & RecordBatch ,
@@ -926,6 +927,7 @@ pub(crate) fn apply_join_filter_to_indices(
926927 filter : & JoinFilter ,
927928 build_side : JoinSide ,
928929 max_intermediate_size : Option < usize > ,
930+ join_type : JoinType ,
929931) -> Result < ( UInt64Array , UInt32Array ) > {
930932 if build_indices. is_empty ( ) && probe_indices. is_empty ( ) {
931933 return Ok ( ( build_indices, probe_indices) ) ;
@@ -946,6 +948,7 @@ pub(crate) fn apply_join_filter_to_indices(
946948 & probe_indices. slice ( i, len) ,
947949 filter. column_indices ( ) ,
948950 build_side,
951+ join_type,
949952 ) ?;
950953 let filter_result = filter
951954 . expression ( )
@@ -967,6 +970,7 @@ pub(crate) fn apply_join_filter_to_indices(
967970 & probe_indices,
968971 filter. column_indices ( ) ,
969972 build_side,
973+ join_type,
970974 ) ?;
971975
972976 filter
@@ -987,6 +991,7 @@ pub(crate) fn apply_join_filter_to_indices(
987991
988992/// Returns a new [RecordBatch] by combining the `left` and `right` according to `indices`.
989993/// The resulting batch has [Schema] `schema`.
994+ #[ expect( clippy:: too_many_arguments) ]
990995pub ( crate ) fn build_batch_from_indices (
991996 schema : & Schema ,
992997 build_input_buffer : & RecordBatch ,
@@ -995,11 +1000,19 @@ pub(crate) fn build_batch_from_indices(
9951000 probe_indices : & UInt32Array ,
9961001 column_indices : & [ ColumnIndex ] ,
9971002 build_side : JoinSide ,
1003+ join_type : JoinType ,
9981004) -> Result < RecordBatch > {
9991005 if schema. fields ( ) . is_empty ( ) {
1006+ // For RightAnti and RightSemi joins, after `adjust_indices_by_join_type`
1007+ // the build_indices were untouched so only probe_indices hold the actual
1008+ // row count.
1009+ let row_count = match join_type {
1010+ JoinType :: RightAnti | JoinType :: RightSemi => probe_indices. len ( ) ,
1011+ _ => build_indices. len ( ) ,
1012+ } ;
10001013 let options = RecordBatchOptions :: new ( )
10011014 . with_match_field_names ( true )
1002- . with_row_count ( Some ( build_indices . len ( ) ) ) ;
1015+ . with_row_count ( Some ( row_count ) ) ;
10031016
10041017 return Ok ( RecordBatch :: try_new_with_options (
10051018 Arc :: new ( schema. clone ( ) ) ,
0 commit comments