@@ -910,6 +910,7 @@ pub(crate) fn get_final_indices_from_bit_map(
910910 ( left_indices, right_indices)
911911}
912912
913+ #[ expect( clippy:: too_many_arguments) ]
913914pub ( crate ) fn apply_join_filter_to_indices (
914915 build_input_buffer : & RecordBatch ,
915916 probe_batch : & RecordBatch ,
@@ -918,6 +919,7 @@ pub(crate) fn apply_join_filter_to_indices(
918919 filter : & JoinFilter ,
919920 build_side : JoinSide ,
920921 max_intermediate_size : Option < usize > ,
922+ join_type : JoinType ,
921923) -> Result < ( UInt64Array , UInt32Array ) > {
922924 if build_indices. is_empty ( ) && probe_indices. is_empty ( ) {
923925 return Ok ( ( build_indices, probe_indices) ) ;
@@ -938,6 +940,7 @@ pub(crate) fn apply_join_filter_to_indices(
938940 & probe_indices. slice ( i, len) ,
939941 filter. column_indices ( ) ,
940942 build_side,
943+ join_type,
941944 ) ?;
942945 let filter_result = filter
943946 . expression ( )
@@ -959,6 +962,7 @@ pub(crate) fn apply_join_filter_to_indices(
959962 & probe_indices,
960963 filter. column_indices ( ) ,
961964 build_side,
965+ join_type,
962966 ) ?;
963967
964968 filter
@@ -979,6 +983,7 @@ pub(crate) fn apply_join_filter_to_indices(
979983
980984/// Returns a new [RecordBatch] by combining the `left` and `right` according to `indices`.
981985/// The resulting batch has [Schema] `schema`.
986+ #[ expect( clippy:: too_many_arguments) ]
982987pub ( crate ) fn build_batch_from_indices (
983988 schema : & Schema ,
984989 build_input_buffer : & RecordBatch ,
@@ -987,11 +992,19 @@ pub(crate) fn build_batch_from_indices(
987992 probe_indices : & UInt32Array ,
988993 column_indices : & [ ColumnIndex ] ,
989994 build_side : JoinSide ,
995+ join_type : JoinType ,
990996) -> Result < RecordBatch > {
991997 if schema. fields ( ) . is_empty ( ) {
998+ // For RightAnti and RightSemi joins, after `adjust_indices_by_join_type`
999+ // the build_indices were untouched so only probe_indices hold the actual
1000+ // row count.
1001+ let row_count = match join_type {
1002+ JoinType :: RightAnti | JoinType :: RightSemi => probe_indices. len ( ) ,
1003+ _ => build_indices. len ( ) ,
1004+ } ;
9921005 let options = RecordBatchOptions :: new ( )
9931006 . with_match_field_names ( true )
994- . with_row_count ( Some ( build_indices . len ( ) ) ) ;
1007+ . with_row_count ( Some ( row_count ) ) ;
9951008
9961009 return Ok ( RecordBatch :: try_new_with_options (
9971010 Arc :: new ( schema. clone ( ) ) ,
0 commit comments