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

feat: Implement reader that returns the last row of each series #4354

Merged
merged 4 commits into from
Jul 12, 2024

Conversation

evenyag
Copy link
Contributor

@evenyag evenyag commented Jul 12, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

What's changed and what's your intention?

This PR implements LastRowReader that only returns the last row of each series (Batches with the same primary key). This can reduce the number of rows to process in the query engine.

When the scan requests has a TimeSeriesRowSelector hint, the storage engine will use SeqScan to scan data and enables the LastRowReader.

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.

Summary by CodeRabbit

  • New Features

    • Introduced functionality to read the last row of each time series, including handling for sorted batches and filtering out deleted rows.
  • Bug Fixes

    • Updated scanning logic to account for conditions where the table is append-only and no series row selector is present.
  • Tests

    • Added comprehensive test functions for verifying last row selection behavior and handling different scenarios.

Copy link
Contributor

coderabbitai bot commented Jul 12, 2024

Walkthrough

This update introduces a module for testing row selection within a time series dataset, a LastRowReader struct for reading the last row of each time series, and modifies scanning conditions for append-only tables. These changes enhance the functionality for time series data handling, providing more control and accuracy in data retrieval processes.

Changes

Files Change Summary
src/mito2/src/engine.rs Added row_selector_test module for testing row selection.
src/mito2/src/engine/row_selector_test.rs Implemented test functions to verify the behavior of selecting the last row in different scenarios.
src/mito2/src/read.rs Added new last_row module with pub(crate) visibility.
src/mito2/src/read/last_row.rs Introduced LastRowReader struct, methods new and next_last_row, and associated tests.
src/mito2/src/read/scan_region.rs Updated scan condition to include check for series_row_selector in append-only tables.
src/mito2/src/read/seq_scan.rs Imported TimeSeriesRowSelector, added LastRowReader, and modified logic for reader selection.

Sequence Diagrams

sequenceDiagram
    participant Test as row_selector_test.rs
    participant Mito as engine.rs
    participant LastRow as last_row.rs
    participant Scan as scan_region.rs
    participant SeqScan as seq_scan.rs

    Test->>Mito: Add row_selector_test module for testing
    Test->>Mito: Implement test functions for last row selection

    Mito->>LastRow: Introduce LastRowReader struct
    Note over LastRow: Provides new method and next_last_row method

    Scan->>SeqScan: Update scan condition to check series_row_selector
    SeqScan->>LastRow: Add LastRowReader and modify reader selection logic
Loading

Poem

In the code where data flows,
A new reader now bestows,
The final row, a tale it tells,
Through tests and scans, it excels.
Append-only checks so keen,
In the world of code unseen.
Cheers to progress, oh so neat! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Jul 12, 2024
@evenyag evenyag marked this pull request as ready for review July 12, 2024 06:20
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ab22bba and 79a0e37.

Files selected for processing (6)
  • src/mito2/src/engine.rs (1 hunks)
  • src/mito2/src/engine/row_selector_test.rs (1 hunks)
  • src/mito2/src/read.rs (1 hunks)
  • src/mito2/src/read/last_row.rs (1 hunks)
  • src/mito2/src/read/scan_region.rs (1 hunks)
  • src/mito2/src/read/seq_scan.rs (3 hunks)
Files skipped from review due to trivial changes (1)
  • src/mito2/src/engine.rs
Additional comments not posted (11)
src/mito2/src/engine/row_selector_test.rs (3)

96-99: LGTM!

The function test_last_row_append_mode_disabled correctly tests the LastRowReader with append mode disabled by calling test_last_row with append_mode set to false.


101-104: LGTM!

The function test_last_row_append_mode_enabled correctly tests the LastRowReader with append mode enabled by calling test_last_row with append_mode set to true.


27-94: Verify the function usage and ensure comprehensive test coverage.

The function test_last_row sets up the environment, creates the engine, and tests the last row reader by inserting rows and flushing regions. Ensure that this function is used correctly in all relevant test cases and consider adding edge cases such as empty datasets or datasets with only one series.

Verification successful

Verify comprehensive test coverage for test_last_row function

The function test_last_row is invoked in two specific test cases: test_last_row_append_mode_disabled and test_last_row_append_mode_enabled. Ensure these test cases cover a wide range of scenarios, including edge cases such as empty datasets or datasets with only one series.

  • src/mito2/src/engine/row_selector_test.rs: test_last_row_append_mode_disabled
  • src/mito2/src/engine/row_selector_test.rs: test_last_row_append_mode_enabled
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `test_last_row` function and ensure comprehensive test coverage.

# Test: Search for the function usage. Expect: Only occurances of the function usage in relevant test cases.
rg --type rust -A 5 $'test_last_row'

Length of output: 1753

src/mito2/src/read/last_row.rs (5)

36-43: LGTM!

The method LastRowReader::new correctly initializes the LastRowReader with the provided reader and sets last_batch to None.


45-72: LGTM!

The method LastRowReader::next_last_row correctly iterates over batches and returns the last row of the next key, handling different keys and empty batches appropriately.


75-80: LGTM!

The implementation of BatchReader for LastRowReader correctly delegates the next_batch method to next_last_row.


89-115: LGTM!

The test test_last_row_one_batch correctly checks the functionality of LastRowReader with a single batch, ensuring it returns the last row.


117-152: LGTM!

The test test_last_row_multi_batch correctly checks the functionality of LastRowReader with multiple batches, ensuring it returns the last row for each key.

src/mito2/src/read/seq_scan.rs (1)

Line range hint 214-234:
LGTM!

The segment correctly integrates the LastRowReader and updates the reader selection logic to handle deduplication and series row selector settings.

src/mito2/src/read/scan_region.rs (1)

212-213: LGTM!

The segment correctly updates the scanner method to handle the absence of a series row selector when the table is in append-only mode, ensuring that unordered scans are used appropriately.

src/mito2/src/read.rs (1)

19-19: Addition of last_row module approved.

The last_row module is appropriately marked with pub(crate) visibility for internal use.

Copy link

codecov bot commented Jul 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.91%. Comparing base (ab22bba) to head (79a0e37).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4354      +/-   ##
==========================================
- Coverage   85.18%   84.91%   -0.27%     
==========================================
  Files        1061     1063       +2     
  Lines      189447   189615     +168     
==========================================
- Hits       161372   161007     -365     
- Misses      28075    28608     +533     

Copy link
Member

@waynexia waynexia left a comment

Choose a reason for hiding this comment

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

easy to understand

Copy link
Collaborator

@fengjiachun fengjiachun left a comment

Choose a reason for hiding this comment

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

LGTM

@fengjiachun fengjiachun added this pull request to the merge queue Jul 12, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 12, 2024
@waynexia waynexia added this pull request to the merge queue Jul 12, 2024
Merged via the queue into GreptimeTeam:main with commit 5a17322 Jul 12, 2024
108 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required This change does not impact docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants