Merge branch 'fix-bad-cast' of github.com:yandex/ClickHouse into fix-bad-cast

This commit is contained in:
Alexey Milovidov 2021-08-08 04:00:56 +03:00
commit 42342fc0d6
4 changed files with 11 additions and 27 deletions

View File

@ -793,12 +793,15 @@ ExpressionActionsChain::JoinStep::JoinStep(
: Step({})
, analyzed_join(std::move(analyzed_join_))
, join(std::move(join_))
, result_columns(std::move(required_columns_))
{
for (const auto & column : result_columns)
for (const auto & column : required_columns_)
required_columns.emplace_back(column.name, column.type);
analyzed_join->addJoinedColumnsAndCorrectTypes(result_columns);
NamesAndTypesList result_names_and_types = required_columns;
analyzed_join->addJoinedColumnsAndCorrectTypes(result_names_and_types);
for (const auto & [name, type] : result_names_and_types)
/// `column` is `nullptr` because we don't care on constness here, it may be changed in join
result_columns.emplace_back(nullptr, type, name);
}
void ExpressionActionsChain::JoinStep::finalize(const NameSet & required_output_)

View File

@ -216,7 +216,7 @@ void ExpressionAnalyzer::analyzeAggregation()
if (join)
{
getRootActionsNoMakeSet(analyzedJoin().leftKeysList(), true, temp_actions, false);
auto sample_columns = temp_actions->getResultColumns();
auto sample_columns = temp_actions->getNamesAndTypesList();
analyzedJoin().addJoinedColumnsAndCorrectTypes(sample_columns);
temp_actions = std::make_shared<ActionsDAG>(sample_columns);
}
@ -1206,7 +1206,7 @@ void SelectQueryExpressionAnalyzer::appendSelect(ExpressionActionsChain & chain,
}
ActionsDAGPtr SelectQueryExpressionAnalyzer::appendOrderBy(ExpressionActionsChain & chain, bool only_types, bool optimize_read_in_order,
ManyExpressionActions & order_by_elements_actions)
ManyExpressionActions & order_by_elements_actions)
{
const auto * select_query = getSelectQuery();

View File

@ -231,20 +231,7 @@ void TableJoin::addJoinedColumn(const NameAndTypePair & joined_column)
void TableJoin::addJoinedColumnsAndCorrectTypes(NamesAndTypesList & names_and_types, bool correct_nullability) const
{
ColumnsWithTypeAndName columns;
for (auto & pair : names_and_types)
columns.emplace_back(nullptr, std::move(pair.type), std::move(pair.name));
names_and_types.clear();
addJoinedColumnsAndCorrectTypes(columns, correct_nullability);
for (auto & col : columns)
names_and_types.emplace_back(std::move(col.name), std::move(col.type));
}
void TableJoin::addJoinedColumnsAndCorrectTypes(ColumnsWithTypeAndName & columns, bool correct_nullability) const
{
for (auto & col : columns)
for (auto & col : names_and_types)
{
if (hasUsing())
{
@ -252,17 +239,12 @@ void TableJoin::addJoinedColumnsAndCorrectTypes(ColumnsWithTypeAndName & columns
col.type = it->second;
}
if (correct_nullability && leftBecomeNullable(col.type))
{
/// No need to nullify constants
bool is_column_const = col.column && isColumnConst(*col.column);
if (!is_column_const)
col.type = JoinCommon::convertTypeToNullable(col.type);
}
col.type = JoinCommon::convertTypeToNullable(col.type);
}
/// Types in columns_added_by_join already converted and set nullable if needed
for (const auto & col : columns_added_by_join)
columns.emplace_back(nullptr, col.type, col.name);
names_and_types.emplace_back(col.name, col.type);
}
bool TableJoin::sameStrictnessAndKind(ASTTableJoin::Strictness strictness_, ASTTableJoin::Kind kind_) const

View File

@ -191,7 +191,6 @@ public:
void addJoinedColumn(const NameAndTypePair & joined_column);
void addJoinedColumnsAndCorrectTypes(NamesAndTypesList & names_and_types, bool correct_nullability = true) const;
void addJoinedColumnsAndCorrectTypes(ColumnsWithTypeAndName & columns, bool correct_nullability = true) const;
/// Calculates common supertypes for corresponding join key columns.
bool inferJoinKeyCommonType(const NamesAndTypesList & left, const NamesAndTypesList & right);