Skip to content

Comments

refactor: Migrate sqlite from adapter::kv to Access instead#6328

Merged
Xuanwo merged 2 commits intoapache:mainfrom
NoxTav:refactor-sqlite
Oct 22, 2025
Merged

refactor: Migrate sqlite from adapter::kv to Access instead#6328
Xuanwo merged 2 commits intoapache:mainfrom
NoxTav:refactor-sqlite

Conversation

@NoxTav
Copy link
Contributor

@NoxTav NoxTav commented Jun 23, 2025

Which issue does this PR close?

Part #5739

Rationale for this change

See #5739

What changes are included in this PR?

Migrate sqlite from adapter::kv to Access instead

Are there any user-facing changes?

No.

@NoxTav NoxTav requested a review from Xuanwo as a code owner June 23, 2025 08:13
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. releases-note/refactor The PR does a refactor on code or has a title that begins with "refactor" labels Jun 23, 2025
@Xuanwo
Copy link
Member

Xuanwo commented Jun 25, 2025

Hi, please fix the CI issues.

@Xuanwo Xuanwo closed this Jun 25, 2025
@Xuanwo Xuanwo reopened this Jun 25, 2025
@NoxTav NoxTav force-pushed the refactor-sqlite branch 10 times, most recently from 292c736 to 6986d0c Compare July 1, 2025 14:32
@NoxTav
Copy link
Contributor Author

NoxTav commented Jul 1, 2025

@Xuanwo I fixed the CI.

@asukaminato0721 asukaminato0721 requested a review from Copilot July 5, 2025 13:29
Copy link

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 refactors the SQLite service to use the new Access trait instead of the old adapter::kv approach.

  • Introduce SqliteAccessor implementing full CRUD and list operations via the Access trait.
  • Add dedicated modules for writer (SqliteWriter), lister (SqliteLister), and deleter (SqliteDeleter).
  • Remove the old kv::Adapter code and wire up the builder to produce the new accessor, plus add initial tests.

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
core/src/services/sqlite/writer.rs Adds SqliteWriter for buffered writes, close and abort logic
core/src/services/sqlite/lister.rs Adds SqliteLister for recursive and non-recursive listings
core/src/services/sqlite/delete.rs Adds SqliteDeleter for one-shot deletes
core/src/services/sqlite/mod.rs Exposes the new modules under the services-sqlite feature flag
core/src/services/sqlite/core.rs Implements SqliteCore with get, get_range, set, and delete APIs
core/src/services/sqlite/backend.rs Replaces kv::Adapter with SqliteAccessor, wires up builder, adds tests
core/Cargo.toml Adds tempfile dependency for test setup
Comments suppressed due to low confidence (3)

core/src/services/sqlite/backend.rs:156

  • The root configured via the builder is ignored here—SqliteAccessor::new always defaults to "/. You should apply the normalized rootvalue, e.g.,.with_normalized_root(root)`, so builder settings take effect.
        Ok(SqliteAccessor::new(SqliteCore {

core/src/services/sqlite/backend.rs:301

  • The test suite covers accessor creation and builder settings but doesn't include tests for core operations (stat, read, write, delete, list). Consider adding tests for these to ensure end-to-end functionality.
mod test {

core/src/services/sqlite/core.rs:27

  • [nitpick] Consider adding documentation comments for SqliteCore to explain its purpose and how its methods (get, get_range, set, delete) are expected to be used.
pub struct SqliteCore {

Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Others look fine to me.

}

#[test]
fn test_sqlite_builder_interface() {
Copy link
Member

Choose a reason for hiding this comment

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

Those tests are meaningless.

} else {
// Non-recursive listing under a specific path
(format!(
"SELECT `{}` FROM `{}` WHERE (`{}` LIKE $1 OR `{}` = $2) AND (`{}` NOT LIKE $3 OR (`{}` LIKE $4 AND `{}` NOT LIKE $5))",
Copy link
Member

Choose a reason for hiding this comment

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

Should we just use something like

SELECT key
FROM   objects
WHERE  key GLOB 'a/*'
  AND  key NOT GLOB 'a/*/*';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GLOB is good for simple cases, but it is not precise enough for more complex cases like LibSubDir. So we need LIKE with a complex query.

@NoxTav NoxTav force-pushed the refactor-sqlite branch 6 times, most recently from 91809a5 to ef873bc Compare September 15, 2025 14:07
@NoxTav NoxTav requested a review from Xuanwo September 15, 2025 14:33
@NoxTav
Copy link
Contributor Author

NoxTav commented Oct 15, 2025

@Xuanwo Up

@Xuanwo
Copy link
Member

Xuanwo commented Oct 15, 2025

Thanks for working on this, but I’m not fond of how SqliteLister is implemented. Can we migrate the other parts first and leave listing unsupported for now?

@NoxTav NoxTav force-pushed the refactor-sqlite branch 2 times, most recently from a9ec78c to 7f07a63 Compare October 22, 2025 08:48
@NoxTav
Copy link
Contributor Author

NoxTav commented Oct 22, 2025

@Xuanwo I removed the SqliteLister and thus it is unsupported right now. Could you make another pass on this PR?

Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Thank you @NoxTav, this change set mostly LGTM.

core/Cargo.toml Outdated
sha2 = "0.10"
size = "0.5"
tokio = { version = "1.48", features = ["fs", "macros", "rt-multi-thread"] }
tempfile = "3.20.0"
Copy link
Member

Choose a reason for hiding this comment

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

We don't want to add new deps like tempfile in opendal, can we avoid that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Xuanwo Fixed.

Ok(stream)
async fn build_client() -> OnceCell<SqlitePool> {
let file = tempfile::NamedTempFile::new().unwrap();
let config = SqliteConnectOptions::from_str(file.path().to_str().unwrap()).unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

sqlite should be able to run in memory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Thank you for working on this!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 22, 2025
@Xuanwo Xuanwo merged commit b64d20b into apache:main Oct 22, 2025
327 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer releases-note/refactor The PR does a refactor on code or has a title that begins with "refactor" size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants