mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
ISSUES-117 resolve some opinions
This commit is contained in:
parent
4875a80825
commit
982b2ee7ca
@ -46,11 +46,16 @@ BlockIO InterpreterDropQuery::execute()
|
||||
}
|
||||
|
||||
/// Drop temporary table.
|
||||
if (drop.temporary)
|
||||
if (drop.database.empty() || drop.temporary)
|
||||
{
|
||||
StoragePtr table = (context.hasSessionContext() ? context.getSessionContext() : context).tryRemoveExternalTable(drop.table);
|
||||
if (table)
|
||||
{
|
||||
if (drop.database.empty() && !drop.temporary)
|
||||
{
|
||||
LOG_WARNING((&Logger::get("InterpreterDropQuery")),
|
||||
"It is recommended to use `DROP TEMPORARY TABLE ` to delete temporary tables");
|
||||
}
|
||||
table->shutdown();
|
||||
/// If table was already dropped by anyone, an exception will be thrown
|
||||
auto table_lock = table->lockForAlter(__PRETTY_FUNCTION__);
|
||||
|
@ -38,12 +38,13 @@ String InterpreterShowTablesQuery::getRewrittenQuery()
|
||||
*/
|
||||
context.assertDatabaseExists(database, false);
|
||||
|
||||
if (query.temporary) {
|
||||
database = "";
|
||||
}
|
||||
|
||||
std::stringstream rewritten_query;
|
||||
rewritten_query << "SELECT name FROM system.tables WHERE database = " << std::quoted(database, '\'');
|
||||
rewritten_query << "SELECT name FROM system.tables WHERE ";
|
||||
|
||||
if (query.temporary)
|
||||
rewritten_query << "temporary = 0";
|
||||
else
|
||||
rewritten_query << "database = " << std::quoted(database, '\'');
|
||||
|
||||
if (!query.like.empty())
|
||||
rewritten_query << " AND name " << (query.not_like ? "NOT " : "") << "LIKE " << std::quoted(query.like, '\'');
|
||||
|
@ -38,14 +38,19 @@ bool ParserShowTablesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expec
|
||||
if (s_databases.ignore(pos))
|
||||
{
|
||||
query->databases = true;
|
||||
} else {
|
||||
if (s_temporary.ignore(pos)) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_temporary.ignore(pos))
|
||||
query->temporary = true;
|
||||
}
|
||||
|
||||
if (s_tables.ignore(pos, expected))
|
||||
{
|
||||
if (s_from.ignore(pos, expected)) {
|
||||
if (s_from.ignore(pos, expected))
|
||||
{
|
||||
if (query->temporary)
|
||||
throw Exception("Unable to parse FROM,Because the temporary table does not have a database.");
|
||||
|
||||
if (!name_p.parse(pos, database, expected))
|
||||
return false;
|
||||
}
|
||||
@ -53,12 +58,15 @@ bool ParserShowTablesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expec
|
||||
if (s_not.ignore(pos, expected))
|
||||
query->not_like = true;
|
||||
|
||||
if (s_like.ignore(pos, expected)) {
|
||||
if (s_like.ignore(pos, expected))
|
||||
{
|
||||
if (!like_p.parse(pos, like, expected))
|
||||
return false;
|
||||
} else if (query->not_like)
|
||||
}
|
||||
else if (query->not_like)
|
||||
return false;
|
||||
} else
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -31,9 +31,6 @@ static ColumnPtr getFilteredDatabases(const ASTPtr & query, const Context & cont
|
||||
for (const auto & db : context.getDatabases())
|
||||
column->insert(db.first);
|
||||
|
||||
std::string temporary_database = "";
|
||||
column->insert(temporary_database);
|
||||
|
||||
Block block { ColumnWithTypeAndName( std::move(column), std::make_shared<DataTypeString>(), "database" ) };
|
||||
VirtualColumnUtils::filterBlockWithQuery(query, block, context);
|
||||
return block.getByPosition(0).column;
|
||||
@ -59,37 +56,37 @@ BlockInputStreams StorageSystemTables::read(
|
||||
{
|
||||
std::string database_name = filtered_databases_column->getDataAt(row_number).toString();
|
||||
|
||||
if (!database_name.empty())
|
||||
auto database = context.tryGetDatabase(database_name);
|
||||
|
||||
if (!database)
|
||||
{
|
||||
auto database = context.tryGetDatabase(database_name);
|
||||
/// Database was deleted just now.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!database) {
|
||||
/// Database was deleted just now.
|
||||
continue;
|
||||
}
|
||||
|
||||
for (auto iterator = database->getIterator(context); iterator->isValid(); iterator->next())
|
||||
{
|
||||
auto table_name = iterator->name();
|
||||
res_columns[0]->insert(database_name);
|
||||
res_columns[1]->insert(table_name);
|
||||
res_columns[2]->insert(iterator->table()->getName());
|
||||
res_columns[3]->insert(
|
||||
static_cast<UInt64>(database->getTableMetadataModificationTime(context, table_name)));
|
||||
res_columns[4]->insert(UInt64(0));
|
||||
}
|
||||
} else if (context.hasSessionContext())
|
||||
for (auto iterator = database->getIterator(context); iterator->isValid(); iterator->next())
|
||||
{
|
||||
Tables externalTables = context.getSessionContext().getExternalTables();
|
||||
auto table_name = iterator->name();
|
||||
res_columns[0]->insert(database_name);
|
||||
res_columns[1]->insert(table_name);
|
||||
res_columns[2]->insert(iterator->table()->getName());
|
||||
res_columns[3]->insert(
|
||||
static_cast<UInt64>(database->getTableMetadataModificationTime(context, table_name)));
|
||||
res_columns[4]->insert(UInt64(0));
|
||||
}
|
||||
}
|
||||
|
||||
for (auto table = externalTables.begin(); table != externalTables.end(); table++)
|
||||
{
|
||||
res_columns[0]->insert(database_name);
|
||||
res_columns[1]->insert(table->first);
|
||||
res_columns[2]->insert(table->second->getName());
|
||||
res_columns[3]->insert(UInt64(0));
|
||||
res_columns[4]->insert(UInt64(1));
|
||||
}
|
||||
if (context.hasSessionContext())
|
||||
{
|
||||
Tables external_tables = context.getSessionContext().getExternalTables();
|
||||
|
||||
for (auto table = external_tables.begin(); table != external_tables.end(); table++)
|
||||
{
|
||||
res_columns[0]->insert(String{});
|
||||
res_columns[1]->insert(table->first);
|
||||
res_columns[2]->insert(table->second->getName());
|
||||
res_columns[3]->insert(UInt64(0));
|
||||
res_columns[4]->insert(UInt64(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ DROP TEMPORARY TABLE IF EXISTS temp_tab;
|
||||
CREATE TEMPORARY TABLE temp_tab (number UInt64);
|
||||
INSERT INTO temp_tab SELECT number FROM system.numbers LIMIT 1;
|
||||
SELECT number FROM temp_tab;
|
||||
DROP TEMPORARY TABLE temp_tab;
|
||||
DROP TABLE temp_tab;
|
||||
CREATE TEMPORARY TABLE temp_tab (number UInt64);
|
||||
SELECT number FROM temp_tab;
|
||||
DROP TEMPORARY TABLE temp_tab;
|
||||
|
Loading…
Reference in New Issue
Block a user