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

Throw DB Exception when AggregateFunctionNullUnary handles unexpected column #1493

Closed
wants to merge 3 commits into from
Closed

Throw DB Exception when AggregateFunctionNullUnary handles unexpected column #1493

wants to merge 3 commits into from

Conversation

tisonkun
Copy link
Contributor

@tisonkun tisonkun commented Feb 26, 2021

What problem does this PR solve?

Issue Number: close #1492

Follow up for #481

Problem Summary:

What is changed and how it works?

Properly handle nonnull column case when empty_input_as_null is true to get the correct semantic and avoid nullptr.

Related changes

  • Need to cherry-pick to the release branch @windtalker which branch should this fix pick to?

Check List

It is an obvious fix but we can add the original SQL as an integrated test.

Release note

N/A

@ti-srebot ti-srebot added the first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. label Feb 26, 2021
@tisonkun tisonkun requested a review from windtalker February 26, 2021 10:52
@tisonkun tisonkun self-assigned this Feb 26, 2021
const ColumnNullable * column = static_cast<const ColumnNullable *>(columns[0]);
if (!column->isNullAt(row_num))
const IColumn * column = columns[0];
const auto * maybe_nullable_column = dynamic_cast<const ColumnNullable *>(column);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the input is a nullable type, and it can not be converted to ColumnNullable, I guess that it is a ColumnConst, so I think its better to
organize the code as follows:

if (const auto * column_nullable= dynamic_cast<const ColumnNullable *>(column))
{}
else if (const auto * column_const = dynamic_cast<const ColumnConst *>(column))
{}
eles
{
    // throw error
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After throw custom exception it is revealed that the actual column type of issue SQL is Int64 a.k.a ColumnVector<Int64>, not ColumnConst.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, as we discussed offline, this is because the type passed by TiDB is not correct, we should fix the TiDB bug and to see what happens here.

@windtalker
Copy link
Contributor

Should add some tests to verify the fix.

@tisonkun
Copy link
Contributor Author

tisonkun commented Mar 1, 2021

/run-all-tests

@tisonkun tisonkun changed the title reconile add non-null column Handle various case when cast column in AggregateFunctionNullUnary Mar 1, 2021
@tisonkun
Copy link
Contributor Author

tisonkun commented Mar 2, 2021

/run-all-tests

@tisonkun tisonkun changed the title Handle various case when cast column in AggregateFunctionNullUnary Throw DB Exception when AggregateFunctionNullUnary handles unexpected column Mar 8, 2021
@tisonkun
Copy link
Contributor Author

tisonkun commented Mar 8, 2021

/run-all-tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NULL pointer when pushdown aggregation
4 participants