From 47453e759fe888395f76399ed1bc32e1c1964964 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 14 Aug 2011 01:11:33 +0000 Subject: [PATCH] dbms: development [#CONV-2944]. --- .../src/DataStreams/LimitBlockInputStream.cpp | 12 ++++++++---- .../DataStreams/tests/expression_stream.cpp | 19 +++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/dbms/src/DataStreams/LimitBlockInputStream.cpp b/dbms/src/DataStreams/LimitBlockInputStream.cpp index 4e774264c2d..2d653be7517 100644 --- a/dbms/src/DataStreams/LimitBlockInputStream.cpp +++ b/dbms/src/DataStreams/LimitBlockInputStream.cpp @@ -36,10 +36,14 @@ Block LimitBlockInputStream::read() return res; /// отдать кусок блока - size_t start = std::max(0, static_cast(offset) - static_cast(pos) + static_cast(rows)); - size_t length = std::min(static_cast(limit), std::min( - static_cast(pos) - static_cast(offset), - static_cast(limit) + static_cast(offset) - static_cast(pos) + static_cast(rows))); + size_t start = std::max( + static_cast(0), + static_cast(offset) - static_cast(pos) + static_cast(rows)); + + size_t length = std::min( + static_cast(limit), std::min( + static_cast(pos) - static_cast(offset), + static_cast(limit) + static_cast(offset) - static_cast(pos) + static_cast(rows))); for (size_t i = 0; i < res.columns(); ++i) res.getByPosition(i).column->cut(start, length); diff --git a/dbms/src/DataStreams/tests/expression_stream.cpp b/dbms/src/DataStreams/tests/expression_stream.cpp index 8b518d30299..cc6de41958a 100644 --- a/dbms/src/DataStreams/tests/expression_stream.cpp +++ b/dbms/src/DataStreams/tests/expression_stream.cpp @@ -3,6 +3,7 @@ #include #include +#include #include @@ -19,6 +20,7 @@ #include + using Poco::SharedPtr; @@ -26,16 +28,11 @@ int main(int argc, char ** argv) { try { - size_t n = argc == 2 ? atoi(argv[1]) : 10; - - DB::StorageSystemNumbers table; - - DB::Names column_names; - column_names.push_back("number"); + size_t n = argc == 2 ? Poco::NumberParser::parseUnsigned64(argv[1]) : 10ULL; DB::ParserSelectQuery parser; 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; const char * begin = input.data(); @@ -53,13 +50,19 @@ int main(int argc, char ** argv) context.columns["number"] = new DB::DataTypeUInt64; context.functions["plus"] = new DB::FunctionPlus; context.functions["multiply"] = new DB::FunctionMultiply; + context.functions["divide"] = new DB::FunctionDivideFloating; Poco::SharedPtr expression = new DB::Expression(ast, context); + DB::StorageSystemNumbers table; + + DB::Names column_names; + column_names.push_back("number"); + Poco::SharedPtr in1(table.read(column_names, 0)); Poco::SharedPtr in2 = new DB::ExpressionBlockInputStream(in1, expression); - DB::LimitBlockInputStream in3(in2, 10, std::max(0, static_cast(n) - 10)); + DB::LimitBlockInputStream in3(in2, 10, std::max(static_cast(0), static_cast(n) - 10)); DB::WriteBufferFromOStream out1(std::cout); DB::TabSeparatedRowOutputStream out2(out1, new DB::DataTypes(expression->getReturnTypes()));