-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[BugFix] fix samples rows calculation error when sampling to collect table statistics #55201
[BugFix] fix samples rows calculation error when sampling to collect table statistics #55201
Conversation
|
||
private long getReadRowCount(long totalRowCount, double readRatio) { | ||
return (long) Math.max(totalRowCount * readRatio, 1L); | ||
} | ||
} |
There was a problem hiding this comment.
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:
The variable sampleRows
is declared twice, which can cause confusion and potential logical errors. The first declaration is not necessary if it is redefined later.
You can modify the code like this:
public void classifyPartitions(Table table, List<Long> partitions) {
long totalRows = high.getTotalRows() + mediumHigh.getTotalRows() + mediumLow.getTotalRows()
+ low.getTotalRows();
// Remove the initial declaration of sampleRows
// long sampleRows = high.getSampleRows() + mediumHigh.getSampleRows() + mediumLow.getSampleRows()
// + low.getSampleRows();
List<TabletStats> highSampleTablets = high.sample();
List<TabletStats> mediumHighSampleTablets = mediumHigh.sample();
List<TabletStats> mediumLowSampleTablets = mediumLow.sample();
List<TabletStats> lowSampleTablets = low.sample();
long sampleRows = Math.min(sampleRowsLimit, highSampleTablets.stream()
.mapToLong(e -> getReadRowCount(e.getRowCount(), highRatio))
.sum());
sampleRows += Math.min(sampleRowsLimit, mediumHighSampleTablets.stream()
.mapToLong(e -> getReadRowCount(e.getRowCount(), mediumHighRatio))
.sum());
sampleRows += Math.min(sampleRowsLimit, mediumLowSampleTablets.stream()
.mapToLong(e -> getReadRowCount(e.getRowCount(), mediumLowRatio))
.sum());
sampleRows += Math.min(sampleRowsLimit, lowSampleTablets.stream()
.mapToLong(e -> getReadRowCount(e.getRowCount(), lowRatio))
.sum());
sampleRows = Math.max(1, sampleRows);
long totalTablets = high.getTotalTablets() + mediumHigh.getTotalTablets() + mediumLow.getTotalTablets() +
low.getTotalTablets();
long sampleTablets = highSampleTablets.size() + mediumHighSampleTablets.size()
+ mediumLowSampleTablets.size() + lowSampleTablets.size();
}
This change removes the unnecessary initial definition of sampleRows
before it's properly defined further down in the code, thus reducing potential confusion or errors.
…table statistics Signed-off-by: stephen <[email protected]>
95570d4
to
82e2878
Compare
Quality Gate passedIssues Measures |
[Java-Extensions Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[FE Incremental Coverage Report]✅ pass : 14 / 14 (100.00%) file detail
|
[BE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
Why I'm doing:
What I'm doing:
we should use sampled tablets to calculate sample rows. currenty we use all tablets to calculate it.
Fixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: