Skip to content

feat: auto alter table during trace ingestion from int to float#7871

Merged
shuiyisong merged 4 commits intoGreptimeTeam:mainfrom
shuiyisong:fix/trace_alter_table
Apr 2, 2026
Merged

feat: auto alter table during trace ingestion from int to float#7871
shuiyisong merged 4 commits intoGreptimeTeam:mainfrom
shuiyisong:fix/trace_alter_table

Conversation

@shuiyisong
Copy link
Copy Markdown
Contributor

@shuiyisong shuiyisong commented Mar 26, 2026

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

#7860

What's changed and what's your intention?

Note: merge #7870 first

This is the second PR for solving issue 7860:

  • When the existing table's datatype is Int64 and the incoming datatype is Float64, issue an alter table request to change the datatype from Int64 to Float64

Note: concurrent update should work but have not yet been tested

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.

@shuiyisong shuiyisong requested a review from a team as a code owner March 26, 2026 12:35
@github-actions github-actions bot added size/L docs-not-required This change does not impact docs. labels Mar 26, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 significantly improves the robustness of OTLP trace ingestion by introducing dynamic type handling. It enables the system to automatically adapt table schemas to accommodate varying data types from incoming traces, specifically by widening integer columns to floating-point when necessary and performing other compatible type coercions. This prevents ingestion failures and ensures data integrity, making the trace ingestion process more resilient to schema mismatches.

Highlights

  • Automatic Type Widening (Int64 to Float64): Implemented automatic schema evolution during OTLP trace ingestion. If an existing table column is Int64 and incoming data for that column is Float64, the system will automatically issue an ALTER TABLE request to change the column's type to Float64 to prevent data loss.
  • In-Batch Type Coercion: Added support for various type coercions within a single batch of OTLP trace data. This includes Int64 to Float64, String to Int64, String to Float64, and String to Boolean conversions, ensuring compatibility with existing column types.
  • Robust Error Handling for Coercion: Introduced error handling for unparsable string values during type coercion, which will now result in a BAD_REQUEST status, preventing corrupted data from being ingested.
  • Enhanced TableData Utilities: Extended the TableData structure with new methods (column_datatype and upgrade_column_to_f64) to facilitate type checking and retroactive column type upgrades, particularly for Int64 to Float64 conversions.
  • Comprehensive Integration Tests: Added new integration tests to thoroughly validate the type coercion and automatic table alteration functionalities for OTLP trace ingestion, covering both in-batch and cross-batch scenarios.
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.

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.

@shuiyisong shuiyisong marked this pull request as draft March 26, 2026 12:36
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 introduces comprehensive type coercion and widening capabilities for OTLP trace data ingestion. It enables in-batch type conversions for compatible types (e.g., Int64 to Float64, String to numeric/boolean) and supports cross-batch column widening from Int64 to Float64 by issuing ALTER TABLE statements. New utility functions and integration tests are included to support these features. A review comment highlights a potential data loss or inconsistency issue in the coerce_trace_numeric_columns function due to incorrect handling of missing values and short rows, suggesting a fix to ensure all rows are processed and padded correctly.

Signed-off-by: shuiyisong <xixing.sys@gmail.com>
@shuiyisong shuiyisong force-pushed the fix/trace_alter_table branch from 46afe01 to 35d8623 Compare April 2, 2026 03:57
@github-actions github-actions bot added size/M and removed size/L labels Apr 2, 2026
@shuiyisong shuiyisong marked this pull request as ready for review April 2, 2026 03:58
@discord9
Copy link
Copy Markdown
Contributor

discord9 commented Apr 2, 2026

/gemini review

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 implements automatic column widening for OTLP traces, specifically allowing existing Int64 columns to be widened to Float64 when incoming data contains floating-point values. It introduces a reconciliation decision mechanism to determine whether to use existing types, request-local types, or perform an alter operation. The ingestion logic was updated to collect and execute these schema changes before processing row data. Feedback was provided regarding the error handling in the new alter_trace_table_columns_to_float64 method, suggesting that the original error's status code and context should be preserved rather than being wrapped in a generic InternalSnafu.

@fengys1996
Copy link
Copy Markdown
Contributor

@codex review

Signed-off-by: shuiyisong <xixing.sys@gmail.com>
@shuiyisong shuiyisong requested review from fengys1996 and sunng87 April 2, 2026 06:56
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8121d784aa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Signed-off-by: shuiyisong <xixing.sys@gmail.com>
Signed-off-by: shuiyisong <xixing.sys@gmail.com>
@shuiyisong shuiyisong enabled auto-merge April 2, 2026 09:28
@shuiyisong shuiyisong added this pull request to the merge queue Apr 2, 2026
Merged via the queue into GreptimeTeam:main with commit 8d49590 Apr 2, 2026
46 checks passed
@shuiyisong shuiyisong deleted the fix/trace_alter_table branch April 2, 2026 10:36
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.

4 participants