feat:stmt2 query free result by adapter - #34200
Conversation
Summary of ChangesHello @Pengrongkun, 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 introduces a new feature that allows Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe 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
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 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
|
704a2b4 to
3a37783
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a useAdapter option for stmt2 queries. When enabled, the ownership of the result set (TAOS_RES) is transferred to the caller, who then becomes responsible for freeing it using taos_free_result. This is useful in adapter scenarios where the result set's lifecycle needs to be managed independently of the statement object. The implementation in clientStmt2.c is correct, and new tests have been added to cover this feature. My review found one minor issue in the new test case where an assertion was missing.
| ASSERT_EQ(strncmp((char*)row[1], "abc", 3), 0); | ||
| ASSERT_EQ(strncmp((char*)row[2], "abc", 3), 0); | ||
| row = taos_fetch_row(pRes); | ||
| ASSERT_NE(row, nullptr); |
There was a problem hiding this comment.
The test fetches the second row from the result set but does not validate its content. This makes the test for the asynchronous query case incomplete. To ensure correctness, assertions should be added for the second row's data, similar to what is done in the synchronous query part of this test.
ASSERT_NE(row, nullptr);
ASSERT_EQ(strncmp((char*)row[0], "tb2", 3), 0);
ASSERT_EQ(strncmp((char*)row[1], "xyz", 3), 0);
ASSERT_EQ(strncmp((char*)row[2], "abc", 3), 0);There was a problem hiding this comment.
Pull request overview
This PR adds support for querying and freeing result sets through an adapter in the stmt2 implementation. The feature allows the stmt2 prepared statement API to properly manage query results when using the adapter mode.
Key changes:
- Modified existing query tests to iterate multiple times and fetch result sets
- Added new test case
query_use_adapterto verify adapter-based query result handling - Implemented adapter-aware result handling in
stmtUseResult2function
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| source/client/test/stmt2Test.cpp | Extended existing synchronous and asynchronous query tests to execute 3 iterations with result fetching; added comprehensive test case for adapter mode with both sync and async query scenarios |
| source/client/src/clientStmt2.c | Added adapter detection logic in stmtUseResult2 to transfer ownership of pRequest when useAdapter is enabled, preventing double-free issues |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -2692,6 +2695,17 @@ TAOS_RES* stmtUseResult2(TAOS_STMT2* stmt) { | |||
| return NULL; | |||
| } | |||
There was a problem hiding this comment.
Inconsistent pattern for accessing configuration. The code directly uses the global tsCfg variable, while other parts of the codebase (e.g., clientEnv.c, clientMain.c) use taosGetCfg() to retrieve the configuration. Consider using the taosGetCfg() function for consistency and to ensure proper initialization checks are performed.
|
|
||
| SConfigItem* pItem = cfgGetItem(tsCfg, "useAdapter"); | ||
| if (pItem == NULL) { | ||
| STMT2_ELOG_E("Invalid option useAdapter"); |
There was a problem hiding this comment.
The error message "Invalid option useAdapter" is misleading. This error occurs when cfgGetItem returns NULL, which could mean the configuration system hasn't been initialized or the item doesn't exist, not that the option value itself is invalid. Consider using a more descriptive message like "Failed to get useAdapter configuration" or "Configuration item useAdapter not found".
| STMT2_ELOG_E("Invalid option useAdapter"); | |
| if (tsCfg == NULL) { | |
| STMT2_ELOG_E("Failed to get useAdapter configuration: configuration system not initialized"); | |
| } else { | |
| STMT2_ELOG_E("Failed to get useAdapter configuration: configuration item not found"); | |
| } |
| ASSERT_NE(row, nullptr); | ||
| ASSERT_EQ(strncmp((char*)row[0], "tb2", 3), 0); | ||
| ASSERT_EQ(strncmp((char*)row[1], "xyz", 3), 0); | ||
| ASSERT_EQ(strncmp((char*)row[2], "abc", 3), 0); |
There was a problem hiding this comment.
Memory leak: The result obtained from taos_stmt2_result should be freed using taos_free_result after use. In the loop, the result from each iteration is not freed, which will cause a resource leak when executing multiple iterations.
| ASSERT_EQ(strncmp((char*)row[2], "abc", 3), 0); | |
| ASSERT_EQ(strncmp((char*)row[2], "abc", 3), 0); | |
| taos_free_result(pRes); |
|
|
||
| taos_stmt2_exec(stmt, NULL); | ||
| checkError(stmt, code, __FILE__, __LINE__); | ||
| taos_stmt2_exec(stmt, NULL); |
There was a problem hiding this comment.
The error checking for taos_stmt2_exec is incorrect. The code checks the return value of the previous taos_stmt2_bind_param call stored in 'code', not the actual return value from taos_stmt2_exec. This should be: code = taos_stmt2_exec(stmt, NULL); checkError(stmt, code, FILE, LINE);
| taos_stmt2_exec(stmt, NULL); | |
| code = taos_stmt2_exec(stmt, NULL); |
| code = taos_stmt2_bind_param(stmt, &bindv, -1); | ||
| checkError(stmt, code, __FILE__, __LINE__); | ||
|
|
||
| taos_stmt2_exec(stmt, NULL); |
There was a problem hiding this comment.
The error checking for taos_stmt2_exec is incorrect. The code checks the return value of the previous taos_stmt2_bind_param call stored in 'code', not the actual return value from taos_stmt2_exec. This should be: code = taos_stmt2_exec(stmt, NULL); checkError(stmt, code, FILE, LINE);
| taos_stmt2_exec(stmt, NULL); | |
| code = taos_stmt2_exec(stmt, NULL); |
| code = taos_stmt2_bind_param(stmt, &bindv, -1); | ||
| checkError(stmt, code); | ||
|
|
||
| taos_stmt2_exec(stmt, NULL); |
There was a problem hiding this comment.
The error checking for taos_stmt2_exec is incorrect. The code checks the return value of the previous taos_stmt2_bind_param call stored in 'code', not the actual return value from taos_stmt2_exec. This should be: code = taos_stmt2_exec(stmt, NULL); checkError(stmt, code, ...);
| taos_stmt2_exec(stmt, NULL); | |
| code = taos_stmt2_exec(stmt, NULL); |
| code = taos_stmt2_bind_param(stmt, &bindv, -1); | ||
| checkError(stmt, code); | ||
|
|
||
| taos_stmt2_exec(stmt, NULL); |
There was a problem hiding this comment.
The error checking for taos_stmt2_exec is incorrect. The code checks the return value of the previous taos_stmt2_bind_param call stored in 'code', not the actual return value from taos_stmt2_exec. This should be: code = taos_stmt2_exec(stmt, NULL); checkError(stmt, code, ...);
| taos_stmt2_exec(stmt, NULL); | |
| code = taos_stmt2_exec(stmt, NULL); |
| row = taos_fetch_row(pRes); | ||
| ASSERT_NE(row, nullptr); |
There was a problem hiding this comment.
Incomplete test assertions: The test fetches a second row but only checks that it's not null without verifying the content of the second row. This test should also include assertions for row[0], row[1], and row[2] to ensure data correctness, similar to the first test case in the synchronous section.
3a37783 to
e570aa5
Compare
Description
Issue(s)
Checklist
Please check the items in the checklist if applicable.