GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [SQL] Date and interval arithmetic follow the SQL standard by mihaibudiu · Pull Request #7692 · feldera/feldera

Conversation

@mihaibudiu

@mihaibudiu mihaibudiu commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Linked Issue

Fixes #7690

Checklist

  • Unit tests added/updated
  • Integration tests added/updated
  • Documentation updated
  • Changelog updated

Breaking Changes?

Mark if you think the answer is yes for any of these components:

  • Feldera SQL (Syntax, Semantics)
  • feldera-sqllib (incl. dependencies fxp, etc.) (What is a breaking change?)

Describe Incompatible Changes

Our implementation of arithmetic on dates and intervals was not conforming to the SQL standard. Now it is.
This is mostly about how rounding is done for the computation results.
None of the programs in our QA suite is affected by this change.
We recommend in the documentation for people not to depend on the semantics of these operations and to always use functions for date manipulation. The semantics of none of the functions has changed, only built-in operators.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
mythical-fred-oss[bot]
mythical-fred-oss Bot reviewed Oct 29, 2026
View reviewed changes
Comment thread crates/sqllib/src/casts.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

mythical-fred-oss[bot]
mythical-fred-oss Bot reviewed Oct 29, 2026
View reviewed changes
Comment thread ...er/src/main/java/org/dbsp/sqlCompiler/compiler/frontend/calciteCompiler/ConvertletTable.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mythical-fred-oss

mythical-fred-oss Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Review: SQL-standard interval truncation (#7690)

Ran Result
cargo test -p feldera-sqllib interval (debug) ❌ casts::tests::interval_casts_truncate panics: attempt to negate with overflow (see inline comment)
./build.sh + mvn test -Dtest=CastTests,TimeArithmeticTests,PostgresIntervalTests,MiscTests,Regression2Tests ✅ 124 run, 0 failures
QA test I added: CAST(CAST(m AS INTERVAL MONTH) AS INTERVAL YEAR) with m = INT_MIN ❌ the pipeline panics at runtime
  • bug (high), gate "tests for changed behaviour": the PR's own Rust unit test fails, so CI will be red. The underlying LongInterval::years() overflow is reachable from SQL.
  • missing (medium): the PR has no test for overflow or error paths in the new constant folding (RexOptimize.intervalProductOrQuotient returns null and defers to the runtime), e.g. INTERVAL '100000000' YEAR * 100 or INTERVAL '1' DAY / 0. The literal and column results should be checked against each other there too.
  • missing (medium): the PR has no test for the new (a - b) <qualifier> semantics with a multi-field qualifier (YEAR TO MONTH, DAY TO HOUR) or with TIMESTAMP WITH TIME ZONE operands. floorToLastField applies to both.
  • Breaking change: it is documented in the changelog and the SQL docs, so that gate passes.

QA test I used (add to TimeArithmeticTests):

@Test
public void qaIntervalEdgeCases() {
    var ccs = this.getCCS("""
            CREATE TABLE Q(m INT);
            CREATE VIEW V AS SELECT
                CAST(CAST(CAST(CAST(m AS INTERVAL MONTH) AS INTERVAL YEAR) AS INTERVAL MONTH) AS INT) AS ym
            FROM Q;""");
    ccs.stepWeightOne("INSERT INTO Q VALUES (-2147483648);", """
             ym
            ----
             -2147483640""");
}
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mihaibudiu
mihaibudiu force-pushed the issue7690 branch from 59e387b to bc73945 Compare October 29, 2026 04:42
gz
gz approved these changes Oct 29, 2026
View reviewed changes

@gz gz left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

hope its worth it, seems scary

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread crates/sqllib/src/casts.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread crates/sqllib/src/casts.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread crates/sqllib/src/casts.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread crates/sqllib/src/casts.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread python/tests/runtime_aggtest/arithmetic_tests/test_time.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mihaibudiu
mihaibudiu added this pull request to the merge queue Oct 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 29, 2026
@mihaibudiu
mihaibudiu force-pushed the issue7690 branch from bc73945 to af09657 Compare October 29, 2026 16:37
@mihaibudiu
mihaibudiu added this pull request to the merge queue Oct 29, 2026
@mihaibudiu
mihaibudiu removed this pull request from the merge queue due to a manual request Oct 29, 2026
@mihaibudiu
mihaibudiu added this pull request to the merge queue Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 30, 2026

Uh oh!

There was an error while loading. Please reload this page.

@mihaibudiu
mihaibudiu added this pull request to the merge queue Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 30, 2026

Uh oh!

There was an error while loading. Please reload this page.

@mihaibudiu
mihaibudiu added this pull request to the merge queue Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 30, 2026

Uh oh!

There was an error while loading. Please reload this page.

@mihaibudiu
mihaibudiu force-pushed the issue7690 branch from af09657 to d66d9ea Compare October 30, 2026 21:24
@mihaibudiu
mihaibudiu added this pull request to the merge queue Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 31, 2026
@mihaibudiu
mihaibudiu force-pushed the issue7690 branch from d66d9ea to ca12040 Compare October 31, 2026 02:27
@mihaibudiu
mihaibudiu added this pull request to the merge queue Oct 31, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 31, 2026

Uh oh!

There was an error while loading. Please reload this page.

@mythical-fred-oss

mythical-fred-oss Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Verdict: PR bug (incomplete test update), high confidence.

ca120407f changed MONTH-interval subtraction and correctly updated the expected
values in aggregate_tests2/test_atbl_interval.py ("Validated on HSQLDB"), but
missed four sibling files in aggregate_tests6 that read the same
atbl_interval_months view and hardcode its old values: test_interval_mths_min.py,
test_interval_mths_max.py, test_interval_mths_argmin.py, test_interval_mths_argmax.py
(plain, DISTINCT, GROUP BY and FILTER variants).

  • Failing job: Runtime Integration Tests (arm64), log lines 726-765
  • interval_argmin_distinct_mths_gby_res mismatch: expected f_c3: -33, f_c5: +56 (id 0), f_c2: +557, f_c3: +87, f_c5: +340 (id 1) — received -34, +57, +558, +88, +341
  • Those "received" values match exactly what the view's ARG_MIN/MIN/MAX/ARG_MAX would recompute from the already-corrected c1_minus_c3/c3_minus_c1/c2_minus_c3/c3_minus_c2 values two rows have in the updated test_atbl_interval.py
  • The test run stops at the first failing assertion (alphabetically interval_argmin_distinct_mths_gby_res is first), which is why only one view showed up as failed — the sibling views above are equally stale and would fail next

Fix on fred/observe-7692-41190119080: recomputed all affected expected values from
the table data and the new, already-validated atbl_interval_months_res numbers.
EVERY/SOME/COUNT(DISTINCT) views over the same table are unaffected (verified the
underlying comparisons/distinct-counts don't change sign or cardinality).

Take the fix:

git fetch origin fred/observe-7692-41190119080 && git cherry-pick dbf6d4c3b

Compare: issue7690...fred/observe-7692-41190119080

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mythical-fred-oss mythical-fred-oss Bot mentioned this pull request Oct 31, 2026
test_runtime_upgrade_round_trip: checkpoint catalog missing but UUID dirs remain (shared cache race) #7763
Open
@mihaibudiu
[SQL] Date and interval arithmetic follow the SQL standard
71a6fd1
An interval holds whole numbers in every field except SECOND.  An
operation that produces an interval truncates the value toward zero to
the last field of its type: a cast between interval types, a cast of a
number, and the product or the quotient of an interval and a number.
The difference of two dates, times or timestamps floors both operands
to the last field of its qualifier.  Constant folding computes the same
values as the runtime, and also reduces the arguments of table function
calls, at every optimization level.

validate-demos.sh prints the compiler output of a demo that fails.

Fixes #7690

Signed-off-by: Mihai Budiu <[email protected]>
@mihaibudiu
mihaibudiu force-pushed the issue7690 branch from ca12040 to 71a6fd1 Compare October 31, 2026 16:35
@mihaibudiu
mihaibudiu added this pull request to the merge queue Oct 31, 2026
Merged via the queue into main with commit 18f734e Oct 31, 2026
1 check passed

Uh oh!

There was an error while loading. Please reload this page.

@mihaibudiu
mihaibudiu deleted the issue7690 branch October 31, 2026 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mythical-fred-oss mythical-fred-oss[bot] mythical-fred-oss[bot] left review comments
@gz gz gz approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[SQL] Interval arithmetic semantics does not match SQL standard

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@mihaibudiu @gz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.