Skip to content

[CALCITE-7696] COVAR result type is derived only from first argument type - #5164

Merged
mihaibudiu merged 1 commit into
apache:mainfrom
mihaibudiu:issue7696
Aug 7, 2026
Merged

[CALCITE-7696] COVAR result type is derived only from first argument type#5164
mihaibudiu merged 1 commit into
apache:mainfrom
mihaibudiu:issue7696

Conversation

@mihaibudiu

Copy link
Copy Markdown
Contributor

Jira Link

CALCITE-7696

Changes Proposed

The result type is now defined to be the least restrictive of the two input types.

One additional related bug was fixed: the division required by these functions in the last step also needs to also use a wider type.

@xuzifu666 xuzifu666 left a comment

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.

Overall LGTM, only left a comment for test case.

f.checkAggType("covar_pop(1.5, 2.5)", "DECIMAL(2, 1) NOT NULL");
// [CALCITE-7696] Result type is the least restrictive of the two
// argument types, not the type of the first argument
f.checkAggType("covar_pop(1, cast(2 as double))", "DOUBLE NOT NULL");

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.

Right now only the INT + DOUBLE case is covered. It would be safer to add a few more edge cases:

  1. Mixed decimal/numeric combinations, e.g. DECIMAL + DOUBLE, DECIMAL + INT
  2. Nullable scenarios: both arguments NULL, or one of them NULL

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added more tests, but by mistake I amended my commit, I apologize

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 these changes are fine.

…type

Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
@sonarqubecloud

sonarqubecloud Bot commented Aug 7, 2026

Copy link
Copy Markdown

@mihaibudiu
mihaibudiu merged commit 9383880 into apache:main Aug 7, 2026
19 checks passed
@mihaibudiu
mihaibudiu deleted the issue7696 branch August 7, 2026 07:00
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