diff --git a/columnar/src/columnar/merge/mod.rs b/columnar/src/columnar/merge/mod.rs index 9ee061be0a..01e60183a7 100644 --- a/columnar/src/columnar/merge/mod.rs +++ b/columnar/src/columnar/merge/mod.rs @@ -454,10 +454,17 @@ fn group_columns_for_merge_iter<'a>( group, ) }); - let iter = group_column_iter.filter(|res| { + let iter = group_column_iter.filter(move |res| { // Filter out empty columns. res.as_ref() - .map(|(_, _, group)| !group.columns.iter().all(|column| column.is_none())) + .map(|(_, _, group)| { + let column_is_required = force_type.is_some(); + if column_is_required { + return true; + } + let all_columns_none = group.columns.iter().all(|column| column.is_none()); + !all_columns_none + }) .unwrap_or(true) }); Box::new(iter) @@ -470,16 +477,13 @@ fn generate_require_column<'a>( required_columns_map: &HashMap, ) -> MergeIter<'a> { let mut grouped_columns = GroupedColumns::new(columnar_readers.len()); - let force_type: ColumnType = required_columns_map - .get(&*column_name) - .map(|el| (*el).into()) - .unwrap(); + let force_type: ColumnType = required_columns_map.get(&*column_name).cloned().unwrap(); grouped_columns.require_type(force_type).unwrap(); // Can't panic - return Box::new(std::iter::once(Ok(( + Box::new(std::iter::once(Ok(( column_name, force_type, grouped_columns, - )))) as MergeIter<'a>; + )))) as MergeIter<'a> } fn group_columns_iter<'a>( diff --git a/src/indexer/index_writer.rs b/src/indexer/index_writer.rs index c44ad39b69..4bff99389f 100644 --- a/src/indexer/index_writer.rs +++ b/src/indexer/index_writer.rs @@ -2426,6 +2426,13 @@ mod tests { test_operation_strategy(&ops[..], false, true).unwrap(); } + #[test] + fn test_merge_regression_1() { + use IndexingOp::*; + let ops = &[AddDoc { id: 15 }, Commit, AddDoc { id: 9 }, Commit, Merge]; + test_operation_strategy(&ops[..], false, true).unwrap(); + } + #[test] fn test_range_query_bug_1() { use IndexingOp::*;