Skip to content

fix: infer time index from column meta on derived table#8013

Open
waynexia wants to merge 5 commits intomainfrom
fix-range-query-1
Open

fix: infer time index from column meta on derived table#8013
waynexia wants to merge 5 commits intomainfrom
fix-range-query-1

Conversation

@waynexia
Copy link
Copy Markdown
Member

Signed-off-by: Ruihang Xia waynestxia@gmail.comI hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

try to infer correct time index from the column meta when operations like UNION produce a synthetic table. likely a regression from #7558

What's changed and what's your intention?

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: Ruihang Xia <waynestxia@gmail.com>
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
@waynexia waynexia requested review from a team, discord9 and evenyag as code owners April 22, 2026 05:41
@github-actions github-actions Bot added size/M docs-not-required This change does not impact docs. labels Apr 22, 2026
Copy link
Copy Markdown
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 enhances range query support to handle derived inputs, such as those resulting from a UNION ALL, by allowing the time index to be inferred from field metadata when the underlying table cannot be directly resolved. It also introduces a flag to prevent invalid default BY column inference in these scenarios and adds comprehensive test cases. Review feedback highlights a critical compilation error caused by the removal of the WildcardOptions import while it is still in use, as well as significant indentation inconsistencies in the newly added logic.

Comment thread src/query/src/range_select/plan_rewrite.rs
Comment thread src/query/src/range_select/plan_rewrite.rs Outdated
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Comment on lines +522 to +527
Err(error) => {
if matches!(&error, catalog::error::Error::TableNotExist { .. })
&& metadata_time_index_expr.is_some()
{
continue;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you add some comments to document why do we need this check?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Better to add a debug log.

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
@waynexia waynexia enabled auto-merge April 23, 2026 18:00
Copy link
Copy Markdown
Member

@killme2008 killme2008 left a comment

Choose a reason for hiding this comment

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

LGTM

Let’s release a new minor version once this PR is merged. @waynexia @fengjiachun

@@ -485,21 +489,49 @@ impl RangePlanRewriter {
/// return `(time_index, [row_columns])` to the rewriter.
/// If the user does not explicitly use the `by` keyword to indicate time series,
/// `[row_columns]` will be use as default time series
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to change the comment too?

Comment on lines +522 to +527
Err(error) => {
if matches!(&error, catalog::error::Error::TableNotExist { .. })
&& metadata_time_index_expr.is_some()
{
continue;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Better to add a debug log.

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.

3 participants