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

Fix Internal Error for an INNER JOIN query #11578

Merged
merged 4 commits into from
Jul 23, 2024

Conversation

xinlifoobar
Copy link
Contributor

Which issue does this PR close?

Closes #11412

Rationale for this change

This issue has affected the join using query with type coercions, for the specific query in this issue.

/*DML*/CREATE TABLE t60(v0 BIGINT, v1 BIGINT, v2 BOOLEAN, v3 BOOLEAN);
/*DML*/CREATE TABLE t0(v0 DOUBLE, v1 BIGINT);
/*DML*/CREATE TABLE t1(v0 DOUBLE);
SELECT COUNT(*)
FROM t1
NATURAL JOIN t60
INNER JOIN t0
ON t60.v1 = t0.v0
AND t0.v1 > t60.v1;
  1. The type_coercion transform Column(c) to Cast(Column(c)
    https://github.com/apache/datafusion/blob/5da7ab300215c44ca5dc16771091890de22af99b/datafusion/optimizer/src/analyzer/type_coercion.rs#L180C1-L195C6

  2. Then in the using_columns the issue pops up.
    https://github.com/apache/datafusion/blob/5da7ab300215c44ca5dc16771091890de22af99b/datafusion/expr/src/logical_plan/plan.rs#L497C1-L512C25

This also indicates the using_columns should not be called after type_coercion

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt) labels Jul 21, 2024
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @xinlifoobar -- this looks good to me. I left a comment about how to improve the code, but I also think we could do that as a follow on

@alamb alamb merged commit f9ee64a into apache:main Jul 23, 2024
24 checks passed
@alamb
Copy link
Contributor

alamb commented Jul 23, 2024

Thanks again @xinlifoobar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Internal Error for an INNER JOIN query (SQLancer)
2 participants