Skip to content

Conversation

@dapan1121
Copy link
Contributor

Description

Please briefly describe the code changes in this pull request.

Checklist

Please check the items in the checklist if applicable.

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @dapan1121, 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 addresses several issues and introduces enhancements primarily focused on stream calculation queries and their interaction with window functions and timestamp handling. It refines how the system processes queries without a 'FROM' clause in stream contexts, correctly identifies new timestamp functions, and includes specific fixes to resolve performance test errors, alongside general improvements to error handling within the planner.

Highlights

  • Stream Calculation Query Enhancements: Improved handling of stream calculation queries, especially those without a 'FROM' clause, by introducing dedicated logic for external window nodes and adjusting timeline resolution.
  • Timestamp Function Recognition: Expanded the parser and planner to correctly identify various timestamp-related functions (e.g., TPREV_TS, TCURRENT_TS) as primary key-like or primary timestamp columns.
  • Performance Test Fixes: Enabled the 'TRIGGER_USE_HISTORY_META' flag and adjusted history recalculation logic to include the 'fillHistoryFirst' condition, addressing issues in performance tests.
  • Refactored Error Handling: Standardized error handling in the physical plan creation process using 'PLAN_ERR_JRET' macros for improved robustness and consistency.
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 introduces fixes for performance tests, primarily by enhancing stream processing capabilities, especially for queries without a FROM clause and handling new timestamp-related placeholder functions. The changes include refactoring for better error handling and readability. My review focuses on improving maintainability by reducing code duplication, enhancing readability of complex conditions, and addressing potential issues from commented-out code.

Comment on lines +202 to +210
/* agg could meet the requirement when the primary key is const like function, so this check may be failed
if (requirement > DATA_ORDER_LEVEL_NONE && (NULL != pAgg->pGroupKeys || !pAgg->onlyHasKeepOrderFunc)) {
planError(
"The output of aggregate cannot meet the requirements(%s) of the upper operator. "
"Illegal statement, should be intercepted in parser",
dataOrderStr(requirement));
return TSDB_CODE_PLAN_INTERNAL_ERROR;
}
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The check for requirement > DATA_ORDER_LEVEL_NONE has been commented out. While the comment provides some context, simply removing the check might introduce regressions. A more robust approach would be to refine the condition to correctly handle the case of constant primary keys, rather than disabling the check entirely. For example, you could add a check to see if the primary key is a constant-like function. Could you please consider a more precise condition?

pTask->historyCalcStarted = true;

if (pTask->fillHistory) {
if (pTask->fillHistory || pTask->fillHistoryFirst) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The condition pTask->fillHistory || pTask->fillHistoryFirst is duplicated in stRealtimeGroupInit (line 6988). To improve maintainability and avoid future inconsistencies, consider creating a helper function or a macro to encapsulate this logic. For example:

static inline bool stTriggerTaskShouldFillHistory(SStreamTriggerTask *pTask) {
    return pTask->fillHistory || pTask->fillHistoryFirst;
}

Then you can use if (stTriggerTaskShouldFillHistory(pTask)) in both places.

}
#endif
if (pTask->fillHistory) {
if (pTask->fillHistory || pTask->fillHistoryFirst) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This condition pTask->fillHistory || pTask->fillHistoryFirst is a duplication of the logic in stRealtimeContextCheck (line 3861). Extracting this into a shared helper function would improve code clarity and reduce the chance of bugs if this logic needs to be updated in the future.

Comment on lines 1396 to +1402
} else if (FUNCTION_TYPE_WSTART == pFunc->funcType || FUNCTION_TYPE_WEND == pFunc->funcType ||
FUNCTION_TYPE_IROWTS == pFunc->funcType || FUNCTION_TYPE_IROWTS_ORIGIN == pFunc->funcType ||
FUNCTION_TYPE_FORECAST_ROWTS == pFunc->funcType || FUNCTION_TYPE_IMPUTATION_ROWTS == pFunc->funcType) {
FUNCTION_TYPE_FORECAST_ROWTS == pFunc->funcType || FUNCTION_TYPE_IMPUTATION_ROWTS == pFunc->funcType ||
FUNCTION_TYPE_TPREV_TS == pFunc->funcType || FUNCTION_TYPE_TCURRENT_TS == pFunc->funcType ||
FUNCTION_TYPE_TNEXT_TS == pFunc->funcType || FUNCTION_TYPE_TWSTART == pFunc->funcType ||
FUNCTION_TYPE_TWEND == pFunc->funcType || FUNCTION_TYPE_TPREV_LOCALTIME == pFunc->funcType ||
FUNCTION_TYPE_TNEXT_LOCALTIME == pFunc->funcType || FUNCTION_TYPE_TLOCALTIME == pFunc->funcType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This else if condition is very long and contains many || operators, which makes it hard to read and maintain. Consider refactoring this into a switch statement on pFunc->funcType for better readability and easier future modifications.

Comment on lines +2018 to +2034
static int32_t createWindowLogicNodeByExternalWithoutFrom(SLogicPlanContext* pCxt, SExternalWindowNode* pExternal,
SSelectStmt* pSelect, SLogicNode** pLogicNode) {
SWindowLogicNode* pWindow = NULL;
int32_t code = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW, (SNode**)&pWindow);
if (NULL == pWindow) {
return code;
}

pWindow->winType = WINDOW_TYPE_EXTERNAL;
pWindow->node.groupAction = GROUP_ACTION_NONE;
pWindow->node.requireDataOrder = DATA_ORDER_LEVEL_GLOBAL;
pWindow->node.resultDataOrder = DATA_ORDER_LEVEL_GLOBAL;
pWindow->isPartTb = 0;
pWindow->pTspk = NULL;

return createExternalWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The new function createWindowLogicNodeByExternalWithoutFrom shares a lot of similar logic with createWindowLogicNodeByExternal. To reduce code duplication and improve maintainability, consider refactoring the common parts into a helper function.

static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowPhysiNode* pWindow,
SWindowLogicNode* pWindowLogicNode) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t lino = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The variable lino is initialized but never used. It should be removed to avoid confusion and improve code clarity.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ Simon9997
❌ dapan1121
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

4 participants