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

[Feature] table sample #52600

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

murphyatwork
Copy link
Contributor

@murphyatwork murphyatwork commented Nov 5, 2024

Why I'm doing:

What I'm doing:

Introduce a syntax for table sample:

SELECT count(k1), sum(k1)
FROM t1  SAMPLE('seed'='1', 'method'='by_page', 'percent'='1');

Properties:

  • seed: optional, specify the random seed, which can guarantee the deterministic result
  • method: optional, by_block or by_page
  • percent: (0, 100), sample probability

Fixes #52787

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.3
    • 3.2
    • 3.1
    • 3.0
    • 2.5

@wanpengfei-git wanpengfei-git requested a review from a team November 5, 2024 02:03
@murphyatwork murphyatwork force-pushed the murphy_feat_table_sample branch 5 times, most recently from 64435a6 to 46bfe29 Compare November 8, 2024 07:07
@murphyatwork murphyatwork marked this pull request as ready for review November 11, 2024 06:28
@murphyatwork murphyatwork requested review from a team as code owners November 11, 2024 06:28
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Signed-off-by: Murphy <[email protected]>
Copy link

sonarcloud bot commented Nov 11, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarCloud

Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

fail : 61 / 85 (71.76%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/common/util/ParseUtil.java 1 6 16.67% [103, 104, 110, 111, 112]
🔵 com/starrocks/sql/optimizer/operator/physical/PhysicalOlapScanOperator.java 3 6 50.00% [211, 212, 254]
🔵 com/starrocks/sql/optimizer/operator/logical/LogicalOlapScanOperator.java 5 7 71.43% [185, 186]
🔵 com/starrocks/sql/ast/TableSampleClause.java 40 52 76.92% [63, 99, 100, 101, 102, 103, 104, 108, 109, 110, 111, 112]
🔵 com/starrocks/planner/OlapScanNode.java 7 9 77.78% [946, 1177]
🔵 com/starrocks/sql/optimizer/transformer/RelationTransformer.java 1 1 100.00% []
🔵 com/starrocks/sql/plan/PlanFragmentBuilder.java 1 1 100.00% []
🔵 com/starrocks/sql/ast/TableRelation.java 3 3 100.00% []

Copy link

[BE Incremental Coverage Report]

pass : 272 / 322 (84.47%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 be/src/storage/rowset/column_iterator.h 0 2 00.00% [161, 265]
🔵 be/src/storage/rowset/ordinal_page_index.cpp 0 4 00.00% [186, 187, 188, 189]
🔵 be/src/storage/rowset/scalar_column_iterator.h 0 1 00.00% [68]
🔵 be/src/storage/rowset/data_sample.cpp 166 206 80.58% [47, 48, 49, 50, 82, 94, 117, 118, 127, 128, 129, 130, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160]
🔵 be/src/storage/rowset/segment_iterator.cpp 58 61 95.08% [2125, 2126, 2141]
🔵 be/src/storage/rowset/rowset.cpp 1 1 100.00% []
🔵 be/src/storage/tablet_reader.cpp 1 1 100.00% []
🔵 be/src/exec/pipeline/scan/olap_chunk_source.cpp 10 10 100.00% []
🔵 be/src/storage/zone_map_detail.h 1 1 100.00% []
🔵 be/src/storage/rowset/data_sample.h 18 18 100.00% []
🔵 be/src/storage/rowset/column_reader.cpp 17 17 100.00% []

@@ -259,9 +261,11 @@ class ColumnIterator {

virtual Status null_count(size_t* count) { return Status::OK(); };

// RAW interface, should be used carefully
virtual ColumnReader* get_column_reader() { return nullptr; };
Copy link
Contributor

Choose a reason for hiding this comment

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

suggest to

virtual ColumnReader* get_column_reader()=0;

or use std::optional<ColumnReader*> as a return type to tell sb that the return type must be checked

std::bernoulli_distribution dist(_probability_percent / 100.0);

size_t sampled_blocks = 0;
size_t total_blocks = _total_rows / _rows_per_block;
Copy link
Contributor

Choose a reason for hiding this comment

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

how _rows_per_block is deduced? it seems _rows_per_block is deduced from rows per block

for (size_t i = 0; i < _total_rows; i += _rows_per_block) {
if (dist(mt)) {
sampled_blocks++;
sampled_ranges.add(RowIdRange(i, std::min(i + _rows_per_block, _total_rows)));
Copy link
Contributor

Choose a reason for hiding this comment

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

  • can RowIdRange span two blocks ? a interesting question is what's the math expect of number of RowIdRanges spanning two block when stride(_rows_per_block) varies. is there an optimized stride?


double SortableZoneMap::width(const Datum& lhs, const Datum& rhs) {
if (lhs.is_null() || rhs.is_null()) {
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

why is 0, it seems that is a open range, it seens that infinity or maximum value is reasonable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce table sample
3 participants