Skip to content

impl(bigquery): add support for Interval type - #6137

Open
alvarowolfx wants to merge 5 commits into
googleapis:mainfrom
alvarowolfx:impl-bq-interval-type
Open

impl(bigquery): add support for Interval type#6137
alvarowolfx wants to merge 5 commits into
googleapis:mainfrom
alvarowolfx:impl-bq-interval-type

Conversation

@alvarowolfx

Copy link
Copy Markdown
Contributor

Towards #5844

@product-auto-label product-auto-label Bot added the api: bigquery Issues related to the BigQuery API. label Jul 22, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request introduces support for BigQuery INTERVAL values by adding a new Interval struct, implementing FromSql for it, and updating the time format constants to support unpadded values. It also refactors time parsing into a helper function and adds comprehensive unit and integration tests. The review feedback suggests deriving Copy and Eq on the Interval struct to improve API usability, and optimizing the parsing logic by using iterators instead of collecting into a Vec to avoid unnecessary heap allocations.

}

/// Represents a BigQuery TIME INTERVAL value.
#[derive(Clone, Debug, Default, PartialEq)]

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.

medium

Since Interval only contains i32 fields, it is highly recommended to derive Copy and Eq to improve API usability and allow it to be easily copied and compared.

Suggested change
#[derive(Clone, Debug, Default, PartialEq)]
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
References
  1. Implement Debug for all public types. Implement Default where appropriate. (API Design) (link)

Comment thread src/bigquery/src/query/from_sql.rs Outdated
@alvarowolfx
alvarowolfx marked this pull request as ready for review July 22, 2026 15:30
@alvarowolfx
alvarowolfx requested a review from a team as a code owner July 22, 2026 15:30
@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.53%. Comparing base (1f360d1) to head (671fefe).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6137      +/-   ##
==========================================
- Coverage   96.54%   96.53%   -0.01%     
==========================================
  Files         264      264              
  Lines       66072    66138      +66     
==========================================
+ Hits        63789    63848      +59     
- Misses       2283     2290       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +371 to +373
return Err(ConvertError::Convert(
format!("invalid interval format: expected 3 parts, got {count}")
.into(),

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.

I think displaying {s} would be more helpful than {count}

}
}

/// Represents a BigQuery TIME INTERVAL value.

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.

consider linking to https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/data-types#interval_type

and (not in this PR) maybe do a pass on the other non-trivial types?


/// Represents a BigQuery TIME INTERVAL value.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Interval {

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.

thought for later: might be nice to have conversion helpers for wkt::Duration.

another thought for later: are we going to impl mathy traits like Add: https://doc.rust-lang.org/std/ops/trait.Add.html

I will answer my own questions and say: let's not do this any time soon. It is a trivial task to do later if we are asked to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the BigQuery API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants