Skip to content

feat(sql): add regr_rmse, regression t-statistics and interval to_timezone#1

Open
aydinmrnv wants to merge 1 commit into
masterfrom
claude/questdb-assigned-tasks-rf2z26
Open

feat(sql): add regr_rmse, regression t-statistics and interval to_timezone#1
aydinmrnv wants to merge 1 commit into
masterfrom
claude/questdb-assigned-tasks-rf2z26

Conversation

@aydinmrnv

Copy link
Copy Markdown
Owner

Fixes questdb#7400
Fixes questdb#7401
Fixes questdb#7402

This branch bundles three related SQL changes. Each is described in its own section below.

questdb#7401 - regr_rmse and regression t-statistic aggregates

Adds three aggregate functions over (y, x) pairs:

  • regr_rmse(y, x) - root mean square error of the simple linear regression, sqrt(SSE / n). It divides by n rather than n - 2, so it is a biased estimator of the error standard deviation but matches the literal "root mean square error" definition.
  • regr_slope_tstat(y, x) - t-statistic for the slope under the null hypothesis that the true slope is zero, slope / SE(slope).
  • regr_intercept_tstat(y, x) - t-statistic for the intercept under the null hypothesis that the true intercept is zero, intercept / SE(intercept).

All three extend AbstractRegressionGroupByFunction and reuse its six Welford state slots, so they inherit parallel group-by support through the existing Chan pairwise merge with no new merge code.

Edge cases: the t-statistics have n - 2 degrees of freedom and return NULL for fewer than three points. A non-varying X (Sxx = 0) returns NULL, matching regr_slope/regr_r2. A perfect fit (SSE <= 0) returns NULL for the t-statistics rather than +/-Infinity; regr_rmse clamps tiny negative rounding results to zero so sqrt does not produce NaN.

questdb#7400 - to_timezone() for interval values

Adds a to_timezone(INTERVAL, tz) overload alongside the existing timestamp overload. It shifts both endpoints of the interval by each endpoint's own zone offset, so an interval that straddles a DST transition is converted with the correct offset on each side rather than a single shared offset. Constant, runtime-constant and non-constant timezone arguments are handled on separate paths, mirroring the timestamp overload. A null endpoint yields Interval.NULL; a null timezone is rejected at compile time; an unparseable timezone in a per-row argument leaves the interval unchanged.

questdb#7402 - point unclosed-parenthesis errors at the parenthesis, not at FROM

When a projection list ends at FROM while a ( is still open (for example a function call whose ) was forgotten), the parser previously reported the error at FROM, which is only where it first noticed the imbalance. The parser now looks ahead over the rest of the statement: if no ) closes the enclosing paren before the statement ends, it points the error at the offending ( instead. A stray from inside a balanced pair is a different problem and still reports dangling literal at from.

Tradeoffs and notes

  • The unclosed-paren fix adds a bounded look-ahead over the remaining tokens on the error path only; it does not affect successful parses.
  • regr_rmse intentionally normalises by n, not n - 2; consumers wanting the residual standard error should not use it as a drop-in.
  • No documentation pages are included in this branch.

Test plan

  • New RegressionRmseFunctionFactoryTest, RegressionSlopeTStatFunctionFactoryTest, RegressionInterceptTStatFunctionFactoryTest - values against hand-computed expectations, NULL handling for n < 3, constant/non-varying X, and perfect-fit cases.
  • New ToTimezoneIntervalFunctionFactoryTest (parameterized over MICRO and NANO timestamps) - area names, DST straddle, fixed offsets, null interval, null and invalid timezones, constant and bind-variable timezones.
  • New SqlParserTest#testUnclosedParenthesisIssue6010 - unclosed paren points at (, stray from still reports dangling literal.
  • Regression: full SqlParserTest (1084 tests), existing ToTimezoneTimestampFunctionFactoryTest, RegressionSlopeFunctionFactoryTest and RegressionInterceptFunctionFactoryTest all pass unchanged.

🤖 Generated with Claude Code

https://claude.ai/code/session_013n4FXQQSBadC9pw9Sdzg8b


Generated by Claude Code

Implements three assigned SQL tasks on a single branch.

questdb#7401 regr_rmse and regression t-statistic aggregates
  Adds regr_rmse(y, x), regr_slope_tstat(y, x) and
  regr_intercept_tstat(y, x). All three extend
  AbstractRegressionGroupByFunction and reuse its six Welford state
  slots, so they inherit parallel group-by support through the existing
  Chan pairwise merge. regr_rmse returns sqrt(SSE / n); the t-statistic
  functions return the coefficient divided by its standard error and
  require at least three points (n - 2 degrees of freedom). Perfect fits
  and non-varying X return NULL rather than +/-Infinity.

questdb#7400 to_timezone() for interval values
  Adds a to_timezone(INTERVAL, tz) overload that shifts both endpoints
  of the interval by each endpoint's own zone offset, so an interval
  straddling a DST transition is converted correctly. Constant, runtime
  constant and non-constant timezone arguments are handled separately,
  mirroring the timestamp overload. A null endpoint yields Interval.NULL
  and a null timezone is rejected.

questdb#7402 unclosed-parenthesis error position
  When the projection list ends at FROM while a '(' is still open, the
  parser now looks ahead over the rest of the statement. If no ')'
  closes the enclosing paren, it points the error at the offending '('
  instead of at FROM, which is only where the parser first noticed the
  problem. A stray 'from' inside a balanced pair still reports a
  dangling literal at 'from'.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013n4FXQQSBadC9pw9Sdzg8b
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 10009623-f43d-43b8-8f39-eff3b8778a1e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/questdb-assigned-tasks-rf2z26

Comment @coderabbitai help to get the list of available commands.

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.

2 participants