mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-16 11:22:12 +00:00
77 lines
2.2 KiB
C++
77 lines
2.2 KiB
C++
#include <Storages/IStorage.h>
|
|
#include <Parsers/TablePropertiesQueriesASTs.h>
|
|
#include <DataStreams/OneBlockInputStream.h>
|
|
#include <DataStreams/BlockIO.h>
|
|
#include <DataStreams/copyData.h>
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
#include <Columns/ColumnsNumber.h>
|
|
#include <Interpreters/Context.h>
|
|
#include <Interpreters/InterpreterExistsQuery.h>
|
|
#include <Access/AccessFlags.h>
|
|
#include <Common/typeid_cast.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int SYNTAX_ERROR;
|
|
}
|
|
|
|
BlockIO InterpreterExistsQuery::execute()
|
|
{
|
|
BlockIO res;
|
|
res.in = executeImpl();
|
|
return res;
|
|
}
|
|
|
|
|
|
Block InterpreterExistsQuery::getSampleBlock()
|
|
{
|
|
return Block{{
|
|
ColumnUInt8::create(),
|
|
std::make_shared<DataTypeUInt8>(),
|
|
"result" }};
|
|
}
|
|
|
|
|
|
BlockInputStreamPtr InterpreterExistsQuery::executeImpl()
|
|
{
|
|
ASTQueryWithTableAndOutput * exists_query;
|
|
bool result = false;
|
|
if ((exists_query = query_ptr->as<ASTExistsTableQuery>()))
|
|
{
|
|
if (exists_query->temporary)
|
|
{
|
|
context.checkAccess(AccessType::EXISTS, "", exists_query->table);
|
|
result = context.isExternalTableExist(exists_query->table);
|
|
}
|
|
else
|
|
{
|
|
String database = exists_query->database;
|
|
if (database.empty())
|
|
database = context.getCurrentDatabase();
|
|
context.checkAccess(AccessType::EXISTS, database, exists_query->table);
|
|
result = context.isTableExist(database, exists_query->table);
|
|
}
|
|
}
|
|
else if ((exists_query = query_ptr->as<ASTExistsDictionaryQuery>()))
|
|
{
|
|
if (exists_query->temporary)
|
|
throw Exception("Temporary dictionaries are not possible.", ErrorCodes::SYNTAX_ERROR);
|
|
String database = exists_query->database;
|
|
if (database.empty())
|
|
database = context.getCurrentDatabase();
|
|
context.checkAccess(AccessType::EXISTS, database, exists_query->table);
|
|
result = context.isDictionaryExists(exists_query->database, exists_query->table);
|
|
}
|
|
|
|
return std::make_shared<OneBlockInputStream>(Block{{
|
|
ColumnUInt8::create(1, result),
|
|
std::make_shared<DataTypeUInt8>(),
|
|
"result" }});
|
|
}
|
|
|
|
}
|