Skip to content

feat: interval day to second support#183

Draft
gord02 wants to merge 4 commits into
mainfrom
gordon.hamilton/interval-day-to-second-support
Draft

feat: interval day to second support#183
gord02 wants to merge 4 commits into
mainfrom
gordon.hamilton/interval-day-to-second-support

Conversation

@gord02

@gord02 gord02 commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Description

Adds Substrait's IntervalDayToSecond type and literal to the text format, on both the parse and textify sides.

  • Type: interval_day (bare, unset precision → treated as 6/microseconds) and interval_day (explicit precision 0–12), matching Type.IntervalDay in the spec.
  • Literal: '':interval_day, e.g. '5d 3s':interval_day, '123456789ns':interval_day. A literal is 1–3 whitespace-separated terms (d, s, and one of ms/us/ns/ps), each term optionally signed and appearing at most once; the subsecond unit determines the stored precision. Literal type ascription is always bare :interval_day — precision is derived from the string, not a type parameter — to avoid two ways of expressing precision disagreeing with each other.
  • Enforces the spec's ±3,650,000-day bound (both individually and combined with seconds), i32 bounds on seconds, and per-precision bounds on subseconds.
  • Updates GRAMMAR.md with the interval_day_literal grammar and precision semantics.

Type of Change

  • New feature

Testing

  • Added tests for new functionality
  • All existing tests pass

Related Issues

Closes #177

Copilot AI 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.

Pull request overview

Adds IntervalDayToSecond support to the substrait-explain text format, covering both parsing (text → protobuf literal/type) and textification (protobuf → canonical text), and updates the documented grammar accordingly.

Changes:

  • Adds interval_day typed literal parsing/textification using a compact duration-string encoding (e.g. '4d 5s':interval_day, '123456789ns':interval_day) with bounds validation.
  • Adds interval_day type support, including bare interval_day (unset precision) and parameterized interval_day<precision> (0–12).
  • Extends grammar + tests for roundtrip coverage of the new type and literal behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/literal_roundtrip.rs Adds a plan-level roundtrip test covering an interval_day literal.
src/types_tests.rs Adds type/literal roundtrip assertions for interval_day and representative literals.
src/textify/types.rs Emits bare interval_day when precision is unset; emits interval_day<precision> when set.
src/textify/expressions.rs Implements IntervalDayToSecond literal textification as a duration string + adds validation tests.
src/parser/types.rs Parses bare interval_day and parameterized interval_day<precision> with bounded precision validation.
src/parser/expressions.rs Parses :interval_day typed string literals into IntervalDayToSecond with bounds/format checks.
src/parser/expression_grammar.pest Adds interval_day to type grammar and introduces interval_day_type.
GRAMMAR.md Documents interval_day typed-literal and type syntax/semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/parser/expressions.rs
duration_str: &str,
span: pest::Span,
) -> Result<(&'a str, &'a str), MessageParseError> {
let digits_start = if term.starts_with('-') { 1 } else { 0 };

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This isn't work addressing. I don't think adding + in front of number is a case we should account for.

Comment thread GRAMMAR.md
Comment on lines +254 to +256
interval_day_literal := duration_term (" " duration_term)*
duration_term := "-"? digit+ ("d" / "s" / "ms" / "us" / "ns" / "ps")
```
Comment thread src/textify/expressions.rs Outdated
Comment on lines +893 to +897
// An all-zero value at precision 0 collapses to the same "0s" as the
// all-zero default (precision 6): precision 0 has no subsecond term
// at all, so there's nothing to distinguish it from the default once
// days and seconds are also 0. Re-parsing "0s" always yields
// precision 6, so this specific value does not round-trip.
@gord02 gord02 force-pushed the gordon.hamilton/interval-day-to-second-support branch from 462b480 to b39deaf Compare July 14, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Design convention for multi-field literal types (starting with IntervalDayToSecond)

2 participants