Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Filter row group using runtime filter before prepare next row group in FileReader #54868

Merged
merged 6 commits into from
Jan 13, 2025

Conversation

trueeyu
Copy link
Contributor

@trueeyu trueeyu commented Jan 9, 2025

Why I'm doing:

If one FileReader scan multi row groups, if runtime filter is updated, the FilterReader will use the out of date runtime filter to filter next row group, so the filtering effect is not good.

What I'm doing:

Try to filter row group using the newest runtime filter before prepare next row group.

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.4
    • 3.3
    • 3.2
    • 3.1
    • 3.0

Signed-off-by: trueeyu <lxhhust350@qq.com>
@trueeyu trueeyu requested review from a team as code owners January 9, 2025 06:36
@mergify mergify bot assigned trueeyu Jan 9, 2025
RETURN_IF_ERROR(cur_row_group->prepare());
}
break;
} while (true);

return Status::OK();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most risky bug in this code is:
An infinite loop may occur when _row_group_size is 0 or _cur_row_group_idx exceeds _row_group_size.

You can modify the code like this:

Status FileReader::get_next(ChunkPtr* chunk) {
    while (_cur_row_group_idx < _row_group_size) { // Add condition check here
        const auto& cur_row_group = _row_group_readers[_cur_row_group_idx];
        
        auto ret = _update_rf_and_filter_group(cur_row_group);
        if (ret.ok() && ret.value()) {
            _group_reader_param.stats->parquet_filtered_row_groups += 1;
            _row_group_readers[_cur_row_group_idx] = nullptr; // Ensure the current reader is nullified after filtering
            _cur_row_group_idx++;
            continue;
        } else if (ret.status().is_end_of_file()) {
            _group_reader_param.stats->parquet_filtered_row_groups += 
                (_row_group_size - _cur_row_group_idx);
            _row_group_readers.assign(_row_group_readers.size(), nullptr);
            _cur_row_group_idx = _row_group_size;
            break;
        } else {
            // do nothing, ignore the error code
        }

        RETURN_IF_ERROR(cur_row_group->prepare());
        break;
    }
    return Status::OK();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not one good suggestion

Signed-off-by: trueeyu <lxhhust350@qq.com>
Signed-off-by: trueeyu <lxhhust350@qq.com>
Signed-off-by: trueeyu <lxhhust350@qq.com>
Signed-off-by: trueeyu <lxhhust350@qq.com>
@@ -321,6 +321,8 @@ struct HdfsScannerContext {

int64_t connector_max_split_size = 0;

OlapRuntimeScanRangePruner* rf_scan_range_pruner = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we definitely have to remove "Olap"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, i will remove it next pr.

dirtysalt
dirtysalt previously approved these changes Jan 9, 2025
meegoo
meegoo previously approved these changes Jan 10, 2025
Signed-off-by: trueeyu <lxhhust350@qq.com>
@trueeyu trueeyu dismissed stale reviews from meegoo and dirtysalt via b3b943e January 10, 2025 02:20
Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[BE Incremental Coverage Report]

pass : 29 / 34 (85.29%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 be/src/formats/parquet/file_reader.cpp 19 24 79.17% [641, 642, 643, 644, 645]
🔵 be/src/exec/hdfs_scanner.cpp 4 4 100.00% []
🔵 be/src/storage/olap_runtime_range_pruner.hpp 1 1 100.00% []
🔵 be/src/storage/rowset/segment_iterator.cpp 1 1 100.00% []
🔵 be/src/storage/predicate_parser.cpp 3 3 100.00% []
🔵 be/src/storage/olap_runtime_range_pruner.h 1 1 100.00% []

@wyb wyb merged commit 6653cbd into StarRocks:main Jan 13, 2025
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants