mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
dbms: development [#CONV-2944].
This commit is contained in:
parent
987784ed80
commit
47453e759f
@ -36,10 +36,14 @@ Block LimitBlockInputStream::read()
|
|||||||
return res;
|
return res;
|
||||||
|
|
||||||
/// отдать кусок блока
|
/// отдать кусок блока
|
||||||
size_t start = std::max(0, static_cast<int>(offset) - static_cast<int>(pos) + static_cast<int>(rows));
|
size_t start = std::max(
|
||||||
size_t length = std::min(static_cast<int>(limit), std::min(
|
static_cast<Int64>(0),
|
||||||
static_cast<int>(pos) - static_cast<int>(offset),
|
static_cast<Int64>(offset) - static_cast<Int64>(pos) + static_cast<Int64>(rows));
|
||||||
static_cast<int>(limit) + static_cast<int>(offset) - static_cast<int>(pos) + static_cast<int>(rows)));
|
|
||||||
|
size_t length = std::min(
|
||||||
|
static_cast<Int64>(limit), std::min(
|
||||||
|
static_cast<Int64>(pos) - static_cast<Int64>(offset),
|
||||||
|
static_cast<Int64>(limit) + static_cast<Int64>(offset) - static_cast<Int64>(pos) + static_cast<Int64>(rows)));
|
||||||
|
|
||||||
for (size_t i = 0; i < res.columns(); ++i)
|
for (size_t i = 0; i < res.columns(); ++i)
|
||||||
res.getByPosition(i).column->cut(start, length);
|
res.getByPosition(i).column->cut(start, length);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <Poco/SharedPtr.h>
|
#include <Poco/SharedPtr.h>
|
||||||
#include <Poco/Stopwatch.h>
|
#include <Poco/Stopwatch.h>
|
||||||
|
#include <Poco/NumberParser.h>
|
||||||
|
|
||||||
#include <DB/IO/WriteBufferFromOStream.h>
|
#include <DB/IO/WriteBufferFromOStream.h>
|
||||||
|
|
||||||
@ -19,6 +20,7 @@
|
|||||||
|
|
||||||
#include <DB/Parsers/ParserSelectQuery.h>
|
#include <DB/Parsers/ParserSelectQuery.h>
|
||||||
|
|
||||||
|
|
||||||
using Poco::SharedPtr;
|
using Poco::SharedPtr;
|
||||||
|
|
||||||
|
|
||||||
@ -26,16 +28,11 @@ int main(int argc, char ** argv)
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
size_t n = argc == 2 ? atoi(argv[1]) : 10;
|
size_t n = argc == 2 ? Poco::NumberParser::parseUnsigned64(argv[1]) : 10ULL;
|
||||||
|
|
||||||
DB::StorageSystemNumbers table;
|
|
||||||
|
|
||||||
DB::Names column_names;
|
|
||||||
column_names.push_back("number");
|
|
||||||
|
|
||||||
DB::ParserSelectQuery parser;
|
DB::ParserSelectQuery parser;
|
||||||
DB::ASTPtr ast;
|
DB::ASTPtr ast;
|
||||||
std::string input = "SELECT number, number + 1, number * 2, number * 2 + 1";
|
std::string input = "SELECT number, number / 3, number * number";
|
||||||
std::string expected;
|
std::string expected;
|
||||||
|
|
||||||
const char * begin = input.data();
|
const char * begin = input.data();
|
||||||
@ -53,13 +50,19 @@ int main(int argc, char ** argv)
|
|||||||
context.columns["number"] = new DB::DataTypeUInt64;
|
context.columns["number"] = new DB::DataTypeUInt64;
|
||||||
context.functions["plus"] = new DB::FunctionPlus;
|
context.functions["plus"] = new DB::FunctionPlus;
|
||||||
context.functions["multiply"] = new DB::FunctionMultiply;
|
context.functions["multiply"] = new DB::FunctionMultiply;
|
||||||
|
context.functions["divide"] = new DB::FunctionDivideFloating;
|
||||||
|
|
||||||
Poco::SharedPtr<DB::Expression> expression = new DB::Expression(ast, context);
|
Poco::SharedPtr<DB::Expression> expression = new DB::Expression(ast, context);
|
||||||
|
|
||||||
|
DB::StorageSystemNumbers table;
|
||||||
|
|
||||||
|
DB::Names column_names;
|
||||||
|
column_names.push_back("number");
|
||||||
|
|
||||||
Poco::SharedPtr<DB::IBlockInputStream> in1(table.read(column_names, 0));
|
Poco::SharedPtr<DB::IBlockInputStream> in1(table.read(column_names, 0));
|
||||||
|
|
||||||
Poco::SharedPtr<DB::ExpressionBlockInputStream> in2 = new DB::ExpressionBlockInputStream(in1, expression);
|
Poco::SharedPtr<DB::ExpressionBlockInputStream> in2 = new DB::ExpressionBlockInputStream(in1, expression);
|
||||||
DB::LimitBlockInputStream in3(in2, 10, std::max(0, static_cast<int>(n) - 10));
|
DB::LimitBlockInputStream in3(in2, 10, std::max(static_cast<Int64>(0), static_cast<Int64>(n) - 10));
|
||||||
|
|
||||||
DB::WriteBufferFromOStream out1(std::cout);
|
DB::WriteBufferFromOStream out1(std::cout);
|
||||||
DB::TabSeparatedRowOutputStream out2(out1, new DB::DataTypes(expression->getReturnTypes()));
|
DB::TabSeparatedRowOutputStream out2(out1, new DB::DataTypes(expression->getReturnTypes()));
|
||||||
|
Loading…
Reference in New Issue
Block a user