2017-04-01 09:19:00 +00:00
|
|
|
#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>
|
2017-05-23 18:01:50 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/InterpreterExistsQuery.h>
|
2017-07-13 20:58:19 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2016-12-12 07:24:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
BlockIO InterpreterExistsQuery::execute()
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockIO res;
|
|
|
|
res.in = executeImpl();
|
|
|
|
return res;
|
2016-12-12 07:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Block InterpreterExistsQuery::getSampleBlock()
|
|
|
|
{
|
2018-02-15 18:54:12 +00:00
|
|
|
return Block{{
|
|
|
|
ColumnUInt8::create(),
|
|
|
|
std::make_shared<DataTypeUInt8>(),
|
|
|
|
"result" }};
|
2016-12-12 07:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BlockInputStreamPtr InterpreterExistsQuery::executeImpl()
|
|
|
|
{
|
2019-03-11 13:22:51 +00:00
|
|
|
const auto * ast = query_ptr->as<ASTExistsQuery>();
|
2019-03-08 09:45:34 +00:00
|
|
|
bool res = ast->temporary ? context.isExternalTableExist(ast->table) : context.isTableExist(ast->database, ast->table);
|
2016-12-12 07:24:56 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return std::make_shared<OneBlockInputStream>(Block{{
|
2017-12-14 01:43:19 +00:00
|
|
|
ColumnUInt8::create(1, res),
|
2017-04-01 07:20:54 +00:00
|
|
|
std::make_shared<DataTypeUInt8>(),
|
|
|
|
"result" }});
|
2016-12-12 07:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|