feat(sql): add regr_rmse, regression t-statistics and interval to_timezone#1
Open
aydinmrnv wants to merge 1 commit into
Open
feat(sql): add regr_rmse, regression t-statistics and interval to_timezone#1aydinmrnv wants to merge 1 commit into
aydinmrnv wants to merge 1 commit into
Conversation
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
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 bynrather thann - 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
AbstractRegressionGroupByFunctionand 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 - 2degrees of freedom and return NULL for fewer than three points. A non-varying X (Sxx = 0) returns NULL, matchingregr_slope/regr_r2. A perfect fit (SSE <= 0) returns NULL for the t-statistics rather than +/-Infinity;regr_rmseclamps tiny negative rounding results to zero sosqrtdoes 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 yieldsInterval.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
FROMwhile a(is still open (for example a function call whose)was forgotten), the parser previously reported the error atFROM, 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 strayfrominside a balanced pair is a different problem and still reportsdangling literalatfrom.Tradeoffs and notes
regr_rmseintentionally normalises byn, notn - 2; consumers wanting the residual standard error should not use it as a drop-in.Test plan
RegressionRmseFunctionFactoryTest,RegressionSlopeTStatFunctionFactoryTest,RegressionInterceptTStatFunctionFactoryTest- values against hand-computed expectations, NULL handling for n < 3, constant/non-varying X, and perfect-fit cases.ToTimezoneIntervalFunctionFactoryTest(parameterized over MICRO and NANO timestamps) - area names, DST straddle, fixed offsets, null interval, null and invalid timezones, constant and bind-variable timezones.SqlParserTest#testUnclosedParenthesisIssue6010- unclosed paren points at(, strayfromstill reports dangling literal.SqlParserTest(1084 tests), existingToTimezoneTimestampFunctionFactoryTest,RegressionSlopeFunctionFactoryTestandRegressionInterceptFunctionFactoryTestall pass unchanged.🤖 Generated with Claude Code
https://claude.ai/code/session_013n4FXQQSBadC9pw9Sdzg8b
Generated by Claude Code