Skip to content

refactor: remove Memtable::iter#7809

Open
v0y4g3r wants to merge 1 commit intoGreptimeTeam:mainfrom
v0y4g3r:fix/time-series-offset-overflow-2
Open

refactor: remove Memtable::iter#7809
v0y4g3r wants to merge 1 commit intoGreptimeTeam:mainfrom
v0y4g3r:fix/time-series-offset-overflow-2

Conversation

@v0y4g3r
Copy link
Contributor

@v0y4g3r v0y4g3r commented Mar 13, 2026

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?

Remove Memtable::iter method and implementations.

PR Checklist

Please convert it to a draft if some of the following conditions are not met.

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.
  • API changes are backward compatible.
  • Schema or data changes are backward compatible.

Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
Copilot AI review requested due to automatic review settings March 13, 2026 08:35
@github-actions github-actions bot added size/M docs-not-required This change does not impact docs. labels Mar 13, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the memtable iteration mechanism by deprecating and removing the direct Memtable::iter method. The change promotes a more structured approach where an iterator builder is first obtained via Memtable::ranges, which can then be configured and built into a BoxedBatchIterator. This enhances the modularity and extensibility of memtable scanning operations, allowing for better control over projection, predicates, and sequence filtering.

Highlights

  • API Refactoring: The Memtable::iter method has been removed from the Memtable trait and all its concrete implementations, promoting a more explicit iterator construction pattern.
  • Iterator Construction: All previous usages of Memtable::iter have been replaced with a two-step process: first obtaining an IterBuilder via Memtable::ranges, and then calling build() on it to get the final iterator.
  • Deprecated Code Removal: Removed deprecated iterator builder structures and helper methods, specifically BatchIterBuilderDeprecated and create_iter from simple_bulk_memtable.
  • Bug Fix/Improvement: The MemtableRanges::build method was updated to correctly construct an iterator from its contained range, resolving a previous UnsupportedOperationSnafu error.
Changelog
  • src/mito2/benches/memtable_bench.rs
    • Updated benchmark calls from memtable.iter() to memtable.ranges(...).build().
    • Added IterBuilder to imports.
  • src/mito2/benches/simple_bulk_memtable.rs
    • Updated benchmark calls from mem.iter() to mem.ranges(...).build().
    • Added IterBuilder to imports.
  • src/mito2/src/memtable.rs
    • Removed the iter method from the Memtable trait.
    • Updated MemtableRanges::build to correctly build an iterator from its single range.
  • src/mito2/src/memtable/bulk.rs
    • Removed the iter method implementation for BulkMemtable.
  • src/mito2/src/memtable/partition_tree.rs
    • Removed the iter method implementation for PartitionTreeMemtable.
    • Updated test cases to use ranges(...).build() instead of iter().
    • Removed unused datafusion_common::Column and datafusion_expr::{BinaryExpr, Expr, Literal, Operator} imports.
  • src/mito2/src/memtable/simple_bulk_memtable.rs
    • Removed the iter method implementation for SimpleBulkMemtable.
    • Updated test cases to use ranges(...).build() instead of iter().
  • src/mito2/src/memtable/simple_bulk_memtable/test_only.rs
    • Removed the create_iter method from SimpleBulkMemtable.
    • Removed the BatchIterBuilderDeprecated struct and its IterBuilder implementation.
    • Removed several unused imports related to the deprecated builder.
  • src/mito2/src/memtable/time_partition.rs
    • Updated test cases to use ranges(...).build() instead of iter().
    • Added IterBuilder and RangesOptions to imports.
  • src/mito2/src/memtable/time_series.rs
    • Removed the iter method implementation for TimeSeriesMemtable.
    • Updated test cases to use ranges(...).build() instead of iter().
  • src/mito2/src/test_util/memtable_util.rs
    • Removed the iter method implementation for EmptyMemtable.
Activity
  • No human activity (comments, reviews, etc.) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a good refactoring that removes the test-only Memtable::iter method and replaces its usages with the more general Memtable::ranges() method. However, there is a potential issue in the implementation of IterBuilder for MemtableRanges that could lead to panics in tests for SimpleBulkMemtable. My review includes a suggestion to make this implementation more robust.

Comment on lines +234 to +235
assert_eq!(self.ranges.len(), 1);
self.ranges.values().next().unwrap().build_iter()
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Using assert_eq! here can cause a panic if memtable.ranges() returns more than one range. This is a valid scenario for SimpleBulkMemtable as its ranges() implementation can produce multiple ranges, unlike its previous iter() implementation which performed a compaction. The compacting logic seems to have been lost in this refactoring.

To prevent panics in tests and improve robustness, it's safer to return an error when there isn't exactly one range.

        if self.ranges.len() != 1 {
            return UnsupportedOperationSnafu {
                err_msg: format!(
                    "Building an iterator from MemtableRanges expects 1 range, but got {}",
                    self.ranges.len()
                ),
            }
            .fail();
        }
        self.ranges.values().next().unwrap().build_iter()

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the test-only Memtable::iter API and updates memtable implementations, unit tests, and benchmarks to scan data via the ranges()/IterBuilder path instead.

Changes:

  • Removed Memtable::iter from the Memtable trait and deleted per-memtable implementations.
  • Updated unit tests/benches to read via ranges(...).build(...) or per-range iterators.
  • Simplified test-only helper code that existed mainly to support the deprecated iterator path.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/mito2/src/test_util/memtable_util.rs Drops EmptyMemtable::iter and relies on ranges() for test scaffolding.
src/mito2/src/memtable/time_series.rs Removes iter impl; updates tests to build iterators from ranges().
src/mito2/src/memtable/time_partition.rs Updates tests to use ranges() + IterBuilder instead of iter().
src/mito2/src/memtable/simple_bulk_memtable/test_only.rs Removes deprecated iterator builder helper code, keeps only metadata accessor.
src/mito2/src/memtable/simple_bulk_memtable.rs Removes iter impl; updates tests to use ranges()/RangesOptions.
src/mito2/src/memtable/partition_tree.rs Removes iter from Memtable impl; updates some tests; removes predicate test.
src/mito2/src/memtable/bulk.rs Removes unimplemented iter() stub.
src/mito2/src/memtable.rs Removes Memtable::iter from trait; changes MemtableRangesIterBuilder::build.
src/mito2/benches/simple_bulk_memtable.rs Bench updated to scan via ranges().build(...).
src/mito2/benches/memtable_bench.rs Bench updated to scan/filter via ranges() for TimeSeriesMemtable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 233 to 236
fn build(&self, _metrics: Option<MemScanMetrics>) -> Result<BoxedBatchIterator> {
UnsupportedOperationSnafu {
err_msg: "MemtableRanges does not support build iterator",
}
.fail()
assert_eq!(self.ranges.len(), 1);
self.ranges.values().next().unwrap().build_iter()
}
Comment on lines 386 to 391
use api::v1::{Mutation, OpType, Rows, SemanticType};
use common_query::prelude::{greptime_timestamp, greptime_value};
use common_time::Timestamp;
use datafusion_common::Column;
use datafusion_expr::{BinaryExpr, Expr, Literal, Operator};
use datatypes::data_type::ConcreteDataType;
use datatypes::prelude::Vector;
use datatypes::scalars::ScalarVector;
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. size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants