Conversation
Summary of ChangesHello @guanshengliang, 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 integrates updates from version 3.3.8, primarily focusing on enhancing the system's time-related functionalities. It introduces more robust handling of calendar-based time intervals and refines time window calculations for improved accuracy and consistency. The changes also include structural improvements by centralizing time utility functions, alongside expanding test coverage for critical time-handling logic and improving existing disk allocation tests. 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. Changelog
Activity
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
|
There was a problem hiding this comment.
Code Review
This pull request appears to be a merge that incorporates several valuable bug fixes and refactorings, primarily focused on time handling functionalities. The changes are positive, enhancing both the correctness and maintainability of the codebase. Key improvements include a critical fix for handling negative month offsets in taosTimeAdd, a logical refactoring of taosTimeTruncate for better time window calculations, and the introduction of convertCalendarTimeFromUnitToPrecision to correctly manage comparisons between different time units. Additionally, moving time-related utilities to ttime.c improves code organization. I have a few minor suggestions for further refinement.
| int64_t y = mon / 12; | ||
| int64_t m = mon % 12; | ||
| if (m < 0) { | ||
| m += 12; | ||
| y -= 1; | ||
| } | ||
| tm.tm_year = (int)y; | ||
| tm.tm_mon = (int)m; |
There was a problem hiding this comment.
The logic to handle negative month offsets is correct. However, it can be simplified and made branchless, which can be slightly more efficient. Consider using modular arithmetic to handle negative results of the modulo operator.
int64_t m = (mon % 12 + 12) % 12;
int64_t y = (mon - m) / 12;
tm.tm_year = (int)y;
tm.tm_mon = (int)m;| interval.timeRange.skey = INT64_MIN; | ||
| interval.timeRange.ekey = INT64_MAX; | ||
| int64_t res = taosTimeTruncate(ts, &interval); | ||
| ASSERT_LE(res, 1633450000000); |
There was a problem hiding this comment.
The assertion ASSERT_LE(res, 1633450000000) is quite weak as it only checks that the truncated timestamp is not after the original one. To make this test more effective and ensure the correctness of taosTimeTruncate, it would be better to assert against a specific, expected timestamp value. For example: ASSERT_EQ(res, expected_timestamp);.
| int64_t interverNano = 0, slidingNano = 0; | ||
| code = convertCalendarTimeFromUnitToPrecision(pInter->datum.i, pInter->unit, precision, &interverNano); | ||
| TAOS_CHECK_GOTO(code, &lino, _exit); | ||
|
|
||
| // pSliding->datum.i is already in precision unit | ||
| slidingNano = pSliding->datum.i; | ||
|
|
||
| if (slidingNano > interverNano) { | ||
| return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTER_SLIDING_TOO_BIG); |
There was a problem hiding this comment.
There's a typo in the variable name interverNano. It should be intervalNano for clarity and consistency. This typo appears on lines 7489, 7490, and 7496.
int64_t intervalNano = 0, slidingNano = 0;
code = convertCalendarTimeFromUnitToPrecision(pInter->datum.i, pInter->unit, precision, &intervalNano);
TAOS_CHECK_GOTO(code, &lino, _exit);
// pSliding->datum.i is already in precision unit
slidingNano = pSliding->datum.i;
if (slidingNano > intervalNano) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTER_SLIDING_TOO_BIG);
}
Description
Issue(s)
Checklist
Please check the items in the checklist if applicable.