2015-10-05 01:35:28 +00:00
|
|
|
#include <DB/Common/Exception.h>
|
2010-03-12 18:25:35 +00:00
|
|
|
#include <DB/Columns/ColumnsNumber.h>
|
2017-03-12 10:13:45 +00:00
|
|
|
#include <DB/DataTypes/DataTypesNumber.h>
|
2014-08-22 17:26:43 +00:00
|
|
|
#include <DB/DataStreams/IProfilingBlockInputStream.h>
|
2015-09-24 03:50:09 +00:00
|
|
|
#include <DB/Storages/System/StorageSystemNumbers.h>
|
2010-03-04 19:20:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2014-08-22 17:26:43 +00:00
|
|
|
class NumbersBlockInputStream : public IProfilingBlockInputStream
|
2010-03-04 19:20:28 +00:00
|
|
|
{
|
2014-08-22 17:26:43 +00:00
|
|
|
public:
|
|
|
|
NumbersBlockInputStream(size_t block_size_, size_t offset_, size_t step_)
|
|
|
|
: block_size(block_size_), next(offset_), step(step_) {}
|
|
|
|
|
2015-06-08 20:22:02 +00:00
|
|
|
String getName() const { return "Numbers"; }
|
2014-08-22 17:26:43 +00:00
|
|
|
String getID() const { return "Numbers"; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Block readImpl()
|
|
|
|
{
|
|
|
|
Block res;
|
|
|
|
|
2016-07-30 04:39:51 +00:00
|
|
|
ColumnWithTypeAndName column_with_type_and_name;
|
2014-08-22 17:26:43 +00:00
|
|
|
|
2016-07-30 04:39:51 +00:00
|
|
|
column_with_type_and_name.name = "number";
|
|
|
|
column_with_type_and_name.type = std::make_shared<DataTypeUInt64>();
|
2016-05-28 05:31:36 +00:00
|
|
|
auto column = std::make_shared<ColumnUInt64>(block_size);
|
2014-08-22 17:26:43 +00:00
|
|
|
ColumnUInt64::Container_t & vec = column->getData();
|
2016-07-30 04:39:51 +00:00
|
|
|
column_with_type_and_name.column = column;
|
2014-08-22 17:26:43 +00:00
|
|
|
|
2017-03-12 19:18:07 +00:00
|
|
|
size_t curr = next; /// The local variable for some reason works faster (>20%) than member of class.
|
|
|
|
UInt64 * pos = &vec[0]; /// This also accelerates the code.
|
2014-08-22 17:26:43 +00:00
|
|
|
UInt64 * end = &vec[block_size];
|
|
|
|
while (pos < end)
|
|
|
|
*pos++ = curr++;
|
|
|
|
|
2016-08-04 23:35:07 +00:00
|
|
|
res.insert(std::move(column_with_type_and_name));
|
2014-08-22 17:26:43 +00:00
|
|
|
|
|
|
|
next += step;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
size_t block_size;
|
|
|
|
UInt64 next;
|
|
|
|
UInt64 step;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
StorageSystemNumbers::StorageSystemNumbers(const std::string & name_, bool multithreaded_)
|
2016-05-28 07:48:40 +00:00
|
|
|
: name(name_), columns{{"number", std::make_shared<DataTypeUInt64>()}}, multithreaded(multithreaded_)
|
2010-03-04 19:20:28 +00:00
|
|
|
{
|
2011-08-15 02:24:44 +00:00
|
|
|
}
|
2010-03-04 19:20:28 +00:00
|
|
|
|
2014-08-22 17:26:43 +00:00
|
|
|
StoragePtr StorageSystemNumbers::create(const std::string & name_, bool multithreaded_)
|
2013-02-06 11:26:35 +00:00
|
|
|
{
|
2016-08-26 21:25:05 +00:00
|
|
|
return make_shared(name_, multithreaded_);
|
2013-02-06 11:26:35 +00:00
|
|
|
}
|
|
|
|
|
2010-03-04 19:20:28 +00:00
|
|
|
|
2012-01-09 19:20:48 +00:00
|
|
|
BlockInputStreams StorageSystemNumbers::read(
|
2014-12-17 11:53:17 +00:00
|
|
|
const Names & column_names,
|
|
|
|
ASTPtr query,
|
|
|
|
const Context & context,
|
|
|
|
const Settings & settings,
|
|
|
|
QueryProcessingStage::Enum & processed_stage,
|
|
|
|
const size_t max_block_size,
|
|
|
|
unsigned threads)
|
2011-08-15 02:24:44 +00:00
|
|
|
{
|
|
|
|
check(column_names);
|
2012-05-22 18:32:45 +00:00
|
|
|
processed_stage = QueryProcessingStage::FetchColumns;
|
2014-08-22 17:26:43 +00:00
|
|
|
|
|
|
|
if (!multithreaded)
|
|
|
|
threads = 1;
|
|
|
|
|
|
|
|
BlockInputStreams res(threads);
|
|
|
|
for (size_t i = 0; i < threads; ++i)
|
2016-05-28 12:22:22 +00:00
|
|
|
res[i] = std::make_shared<NumbersBlockInputStream>(max_block_size, i * max_block_size, threads * max_block_size);
|
2014-08-22 17:26:43 +00:00
|
|
|
|
|
|
|
return res;
|
2010-03-04 19:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|