Skip to content

ASTTableIdentifier part #2: Introduce ASTTableIdentifier#16401

Merged
nikitamikhaylov merged 45 commits intoClickHouse:masterfrom
abyss7:ast-table-identifier-2
Jun 15, 2021
Merged

ASTTableIdentifier part #2: Introduce ASTTableIdentifier#16401
nikitamikhaylov merged 45 commits intoClickHouse:masterfrom
abyss7:ast-table-identifier-2

Conversation

@abyss7
Copy link
Copy Markdown
Contributor

@abyss7 abyss7 commented Oct 26, 2020

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Changelog category (leave one):

  • Other

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Introduce ASTTableIdentifier into the code

@robot-clickhouse robot-clickhouse added the pr-other Pull request with changes not fitting to other categories label Oct 26, 2020
@abyss7 abyss7 changed the title Introduce ASTTableIdentifier ASTTableIdentifier part #2: Introduce ASTTableIdentifier Oct 26, 2020
@nikitamikhaylov nikitamikhaylov self-assigned this Nov 10, 2020
@qoega qoega marked this pull request as draft February 8, 2021 08:27
@alexey-milovidov
Copy link
Copy Markdown
Member

Maybe reopen later.

@abyss7 abyss7 reopened this Apr 12, 2021
@abyss7
Copy link
Copy Markdown
Contributor Author

abyss7 commented May 21, 2021

@mergify update

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented May 21, 2021

Command update: success

Branch has been successfully updated

Hey, I reacted but my real name is @Mergifyio

@abyss7 abyss7 marked this pull request as ready for review May 31, 2021 18:50
fuzz(table_expr->database_and_table_name);
fuzz(table_expr->subquery);
fuzz(table_expr->table_function);
fuzz(table_expr->children);
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.

Have you removed the database_and_table_name and table_function fields from ASTTableExpression?

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.

No, but they are included as children already, so it just simplifies the code.

{
auto subquery_it = data.subqueries.find(table_id.table_name);
/// Clang-tidy is wrong on this line, because `func.arguments->children.at(1)` gets replaced before last use of `name`.
auto name = identifier->shortName(); // NOLINT
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.

Better to point out the warning name such as // NOLINTNEXTLINE(google-explicit-constructor, google-runtime-int)

{
auto & ast_identifier = ast->as<ASTIdentifier &>();
if (ast_identifier.children.empty())
auto ast_identifier = dynamic_pointer_cast<ASTIdentifier>(ast);
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.

typeid_cast or assert_cast?

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.

It's a shortcut - not to check ASTIdentifier and ASTTableIdentifier with the same code.


if (!ast_identifier.semantic->special && name_parts.size() >= 2)
ast_identifier.semantic->table = ast_identifier.name_parts.end()[-2];
/// FIXME: what should this mean?
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 don't know too. Maybe we can delete it and see what will happen in tests?

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.

I suggest to leave it for the next iteration of refactoring.

if (ast)
{
if (const auto * node = ast->as<ASTIdentifier>())
if (const auto * node = dynamic_cast<const ASTIdentifier *>(ast))
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.

Why dynamic cast?

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.

It's a shortcut - not to check ASTIdentifier and ASTTableIdentifier with the same code.

Comment on lines +252 to +266
if (s_uuid.ignore(pos, expected))
{
ParserStringLiteral uuid_p;
ASTPtr ast_uuid;
if (!uuid_p.parse(pos, ast_uuid, expected))
return false;
uuid = parseFromString<UUID>(ast_uuid->as<ASTLiteral>()->value.get<String>());
}

if (parts.size() == 1) node = std::make_shared<ASTTableIdentifier>(parts[0], std::move(params));
else node = std::make_shared<ASTTableIdentifier>(parts[0], parts[1], std::move(params));
node->as<ASTTableIdentifier>()->uuid = uuid;
}
else
node = std::make_shared<ASTIdentifier>(std::move(parts), false, std::move(params));
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.

What is going on here?

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.

It's parsing of a table identifier - it may have only table name, or both database and table names. Also it may have UUID.

if (ParserKeyword("LIKE").ignore(pos, expected))
{
if (!ParserCompoundIdentifier(false).parse(pos, like_table, expected))
if (!ParserCompoundIdentifier(true).parse(pos, like_table, expected))
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.

Why we change table_name_with_optional_uuid_ ctor parameter to true?

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.

Because ParserCompoundIdentifier(true) stands for now for ParseTableIdentifier - it returns ASTTableIdentifier and parses it accordingly (i.e. with UUID).

Co-authored-by: Nikita Mikhaylov <[email protected]>
@abyss7 abyss7 requested a review from nikitamikhaylov June 13, 2021 19:28
@nikitamikhaylov nikitamikhaylov merged commit a52bba9 into ClickHouse:master Jun 15, 2021
@abyss7 abyss7 deleted the ast-table-identifier-2 branch June 15, 2021 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-other Pull request with changes not fitting to other categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants