ClickHouse/dbms/src/Interpreters/InterpreterExistsQuery.cpp

42 lines
1021 B
C++
Raw Normal View History

#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/InterpreterExistsQuery.h>
2016-12-12 07:24:56 +00:00
namespace DB
{
BlockIO InterpreterExistsQuery::execute()
{
BlockIO res;
res.in = executeImpl();
res.in_sample = getSampleBlock();
2016-12-12 07:24:56 +00:00
return res;
2016-12-12 07:24:56 +00:00
}
Block InterpreterExistsQuery::getSampleBlock()
{
return {{ std::make_shared<ColumnConstUInt8>(0, 0), std::make_shared<DataTypeUInt8>(), "result" }};
2016-12-12 07:24:56 +00:00
}
BlockInputStreamPtr InterpreterExistsQuery::executeImpl()
{
const ASTExistsQuery & ast = typeid_cast<const ASTExistsQuery &>(*query_ptr);
bool res = context.isTableExist(ast.database, ast.table);
2016-12-12 07:24:56 +00:00
return std::make_shared<OneBlockInputStream>(Block{{
std::make_shared<ColumnConstUInt8>(1, res),
std::make_shared<DataTypeUInt8>(),
"result" }});
2016-12-12 07:24:56 +00:00
}
}