mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 17:41:59 +00:00
fix push down
This commit is contained in:
parent
6309377323
commit
668b220258
@ -1049,6 +1049,7 @@ void ExpressionAnalyzer::collectUsedColumns()
|
||||
if (!unknown_required_source_columns.empty())
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "query: '" << query << "'" << std::endl;
|
||||
ss << columns_context;
|
||||
ss << "source_columns: ";
|
||||
for (const auto & name : source_columns)
|
||||
|
@ -10,8 +10,10 @@ namespace DB
|
||||
struct FindIdentifierBestTableData
|
||||
{
|
||||
using TypeToVisit = ASTIdentifier;
|
||||
using IdentifierWithTable = std::pair<ASTIdentifier *, const DatabaseAndTableWithAlias *>;
|
||||
|
||||
const std::vector<DatabaseAndTableWithAlias> & tables;
|
||||
std::vector<std::pair<ASTIdentifier *, const DatabaseAndTableWithAlias *>> identifier_table;
|
||||
std::vector<IdentifierWithTable> identifier_table;
|
||||
|
||||
FindIdentifierBestTableData(const std::vector<DatabaseAndTableWithAlias> & tables_);
|
||||
|
||||
|
@ -112,8 +112,21 @@ void IdentifierSemantic::setColumnNormalName(ASTIdentifier & identifier, const D
|
||||
if (identifier.semantic->need_long_name)
|
||||
{
|
||||
String prefix = db_and_table.getQualifiedNamePrefix();
|
||||
identifier.name.insert(identifier.name.begin(), prefix.begin(), prefix.end());
|
||||
if (!prefix.empty())
|
||||
{
|
||||
String short_name = identifier.shortName();
|
||||
identifier.name = prefix + short_name;
|
||||
prefix.resize(prefix.size() - 1); /// crop dot
|
||||
identifier.name_parts = {prefix, short_name};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String IdentifierSemantic::columnNormalName(const ASTIdentifier & identifier, const DatabaseAndTableWithAlias & db_and_table)
|
||||
{
|
||||
ASTPtr copy = identifier.clone();
|
||||
setColumnNormalName(typeid_cast<ASTIdentifier &>(*copy), db_and_table);
|
||||
return copy->getAliasOrColumnName();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ struct IdentifierSemantic
|
||||
static std::pair<String, String> extractDatabaseAndTable(const ASTIdentifier & identifier);
|
||||
|
||||
static size_t canReferColumnToTable(const ASTIdentifier & identifier, const DatabaseAndTableWithAlias & db_and_table);
|
||||
static String columnNormalName(const ASTIdentifier & identifier, const DatabaseAndTableWithAlias & db_and_table);
|
||||
static void setColumnNormalName(ASTIdentifier & identifier, const DatabaseAndTableWithAlias & db_and_table);
|
||||
static void setNeedLongName(ASTIdentifier & identifier, bool); /// if set setColumnNormalName makes qualified name
|
||||
|
||||
|
@ -236,10 +236,22 @@ void PredicateExpressionsOptimizer::setNewAliasesForInnerPredicate(
|
||||
{
|
||||
if (alias == qualified_name)
|
||||
{
|
||||
if (!isIdentifier(ast) && ast->tryGetAlias().empty())
|
||||
ast->setAlias(ast->getColumnName());
|
||||
String name;
|
||||
if (auto * id = typeid_cast<const ASTIdentifier *>(ast.get()))
|
||||
{
|
||||
name = id->tryGetAlias();
|
||||
if (name.empty())
|
||||
name = id->shortName();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ast->tryGetAlias().empty())
|
||||
ast->setAlias(ast->getColumnName());
|
||||
name = ast->getAliasOrColumnName();
|
||||
}
|
||||
|
||||
identifier->resetWithAlias(ast->getAliasOrColumnName());
|
||||
IdentifierSemantic::setNeedLongName(*identifier, false);
|
||||
identifier->setShortName(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
bool compound() const { return !name_parts.empty(); }
|
||||
bool isShort() const { return name_parts.empty() || name == name_parts.back(); }
|
||||
|
||||
void resetWithAlias(const String & new_name)
|
||||
void setShortName(const String & new_name)
|
||||
{
|
||||
name = new_name;
|
||||
name_parts.clear();
|
||||
|
Loading…
Reference in New Issue
Block a user