2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/Exception.h>
|
|
|
|
#include <Columns/ColumnsNumber.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <DataStreams/IProfilingBlockInputStream.h>
|
|
|
|
#include <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:
|
2017-04-01 07:20:54 +00:00
|
|
|
NumbersBlockInputStream(size_t block_size_, size_t offset_, size_t step_)
|
|
|
|
: block_size(block_size_), next(offset_), step(step_) {}
|
2014-08-22 17:26:43 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String getName() const { return "Numbers"; }
|
|
|
|
String getID() const { return "Numbers"; }
|
2014-08-22 17:26:43 +00:00
|
|
|
|
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
Block readImpl()
|
|
|
|
{
|
|
|
|
Block res;
|
2014-08-22 17:26:43 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ColumnWithTypeAndName column_with_type_and_name;
|
2014-08-22 17:26:43 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
column_with_type_and_name.name = "number";
|
|
|
|
column_with_type_and_name.type = std::make_shared<DataTypeUInt64>();
|
|
|
|
auto column = std::make_shared<ColumnUInt64>(block_size);
|
|
|
|
ColumnUInt64::Container_t & vec = column->getData();
|
|
|
|
column_with_type_and_name.column = column;
|
2014-08-22 17:26:43 +00:00
|
|
|
|
2017-04-01 07:20:54 +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.
|
|
|
|
UInt64 * end = &vec[block_size];
|
|
|
|
while (pos < end)
|
|
|
|
*pos++ = curr++;
|
2014-08-22 17:26:43 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
res.insert(std::move(column_with_type_and_name));
|
2014-08-22 17:26:43 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
next += step;
|
|
|
|
return res;
|
|
|
|
}
|
2014-08-22 17:26:43 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t block_size;
|
|
|
|
UInt64 next;
|
|
|
|
UInt64 step;
|
2014-08-22 17:26:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
StorageSystemNumbers::StorageSystemNumbers(const std::string & name_, bool multithreaded_)
|
2017-04-01 07:20:54 +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
|
|
|
|
|
|
|
|
2012-01-09 19:20:48 +00:00
|
|
|
BlockInputStreams StorageSystemNumbers::read(
|
2017-04-01 07:20:54 +00:00
|
|
|
const Names & column_names,
|
2017-05-25 01:12:41 +00:00
|
|
|
const ASTPtr & query,
|
2017-04-01 07:20:54 +00:00
|
|
|
const Context & context,
|
|
|
|
QueryProcessingStage::Enum & processed_stage,
|
|
|
|
const size_t max_block_size,
|
2017-06-02 15:54:39 +00:00
|
|
|
unsigned num_streams)
|
2011-08-15 02:24:44 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
check(column_names);
|
|
|
|
processed_stage = QueryProcessingStage::FetchColumns;
|
2014-08-22 17:26:43 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!multithreaded)
|
2017-06-02 15:54:39 +00:00
|
|
|
num_streams = 1;
|
2014-08-22 17:26:43 +00:00
|
|
|
|
2017-06-02 15:54:39 +00:00
|
|
|
BlockInputStreams res(num_streams);
|
|
|
|
for (size_t i = 0; i < num_streams; ++i)
|
|
|
|
res[i] = std::make_shared<NumbersBlockInputStream>(max_block_size, i * max_block_size, num_streams * max_block_size);
|
2014-08-22 17:26:43 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return res;
|
2010-03-04 19:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|