Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CALCITE-6559] Query with measure that applies AVG to SMALLINT throws AssertionError "Cannot add expression of different type to set" #3950

Closed
wants to merge 3 commits into from

Conversation

julianhyde
Copy link
Contributor

No description provided.

When a query has a measure that is AVG applied to a SMALLINT or TINYINT
column, we get the following assertion failure:

  java.lang.AssertionError: Cannot add expression of different type to set:
  set type is RecordType(VARCHAR(9) JOB, MEASURE<SMALLINT NOT NULL> NOT NULL $f1, SMALLINT $f0) NOT NULL
  expression type is RecordType(VARCHAR(9) JOB, MEASURE<SMALLINT NOT NULL> NOT NULL $f1, SMALLINT NOT NULL $f0) NOT NULL

The problem is that a cast is added internally to the result of
SUM / COUNT, but this cast prevents a cast to nullable for the
null-generating side of the outer join. (The outer join comes from
the expansion of the measure as a correlated scalar subquery.)

Close apache/calcite#xxxx
Add tests to scalar.iq and lateral.iq for some tricky query patterns
that already work.

!ok

!if (false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an issue filed for this other problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@julianhyde
Copy link
Contributor Author

@amarkowitz, PTAL

@@ -179,6 +179,53 @@ from empm;

!ok

# [CALCITE-6559] LogicalCorrelate Type mismatch
# Occurs when AVG measure is applied to SMALLINT or TINYINT column.
# A CAST is added internally to the result of SUM / COUNT, but this cast

Choose a reason for hiding this comment

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

It's difficult to tell from this comment whether this was the cause of the bug or whether this is the new expectation after fixing. Have you considered moving this comment to CALCITE-6559 instead?

Copy link

sonarqubecloud bot commented Sep 5, 2024

@julianhyde julianhyde closed this in ded0651 Sep 5, 2024
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.

3 participants