From 43951e4879e9b73d72641b1aa4259be221cf96eb Mon Sep 17 00:00:00 2001 From: CurtizJ Date: Mon, 17 Sep 2018 22:16:51 +0300 Subject: [PATCH] add test --- dbms/src/DataStreams/CubeBlockInputStream.cpp | 8 +++++++ dbms/src/DataStreams/CubeBlockInputStream.h | 2 +- .../Interpreters/InterpreterSelectQuery.cpp | 10 ++++++-- .../0_stateless/00718_with_cube.reference | 23 +++++++++++++++++++ .../queries/0_stateless/00718_with_cube.sql | 17 ++++++++++++++ 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 dbms/tests/queries/0_stateless/00718_with_cube.reference create mode 100644 dbms/tests/queries/0_stateless/00718_with_cube.sql diff --git a/dbms/src/DataStreams/CubeBlockInputStream.cpp b/dbms/src/DataStreams/CubeBlockInputStream.cpp index b178e36e849..ec9467b1f86 100644 --- a/dbms/src/DataStreams/CubeBlockInputStream.cpp +++ b/dbms/src/DataStreams/CubeBlockInputStream.cpp @@ -8,10 +8,18 @@ namespace DB { +namespace ErrorCodes +{ + extern const int TOO_MANY_COLUMNS; +} + CubeBlockInputStream::CubeBlockInputStream( const BlockInputStreamPtr & input_, const Aggregator::Params & params_) : aggregator(params_), keys(params_.keys) { + if (keys.size() > 30) + throw Exception("Too many columns for cube", ErrorCodes::TOO_MANY_COLUMNS); + children.push_back(input_); Aggregator::CancellationHook hook = [this]() { return this->isCancelled(); }; aggregator.setCancellationHook(hook); diff --git a/dbms/src/DataStreams/CubeBlockInputStream.h b/dbms/src/DataStreams/CubeBlockInputStream.h index 5f58fc5dc9a..53cca98f654 100644 --- a/dbms/src/DataStreams/CubeBlockInputStream.h +++ b/dbms/src/DataStreams/CubeBlockInputStream.h @@ -34,7 +34,7 @@ protected: private: Aggregator aggregator; ColumnNumbers keys; - size_t mask = 0; + UInt32 mask = 0; Block source_block; }; diff --git a/dbms/src/Interpreters/InterpreterSelectQuery.cpp b/dbms/src/Interpreters/InterpreterSelectQuery.cpp index 00a79bf8fbf..56477ce38e3 100644 --- a/dbms/src/Interpreters/InterpreterSelectQuery.cpp +++ b/dbms/src/Interpreters/InterpreterSelectQuery.cpp @@ -558,7 +558,10 @@ void InterpreterSelectQuery::executeImpl(Pipeline & pipeline, const BlockInputSt if (!aggregate_final) { if (query.group_by_with_totals) - executeTotalsAndHaving(pipeline, expressions.has_having, expressions.before_having, aggregate_overflow_row, !query.group_by_with_rollup); + { + bool final = !query.group_by_with_rollup && !query.group_by_with_cube; + executeTotalsAndHaving(pipeline, expressions.has_having, expressions.before_having, aggregate_overflow_row, final); + } if (query.group_by_with_rollup) executeRollupOrCube(pipeline, true); @@ -578,7 +581,10 @@ void InterpreterSelectQuery::executeImpl(Pipeline & pipeline, const BlockInputSt need_second_distinct_pass = query.distinct && pipeline.hasMoreThanOneStream(); if (query.group_by_with_totals && !aggregate_final) - executeTotalsAndHaving(pipeline, false, nullptr, aggregate_overflow_row, !query.group_by_with_rollup); + { + bool final = !query.group_by_with_rollup && !query.group_by_with_cube; + executeTotalsAndHaving(pipeline, expressions.has_having, expressions.before_having, aggregate_overflow_row, final); + } if (query.group_by_with_rollup && !aggregate_final) executeRollupOrCube(pipeline, true); diff --git a/dbms/tests/queries/0_stateless/00718_with_cube.reference b/dbms/tests/queries/0_stateless/00718_with_cube.reference new file mode 100644 index 00000000000..ae0eaa122af --- /dev/null +++ b/dbms/tests/queries/0_stateless/00718_with_cube.reference @@ -0,0 +1,23 @@ + 0 120 8 + 1 40 4 + 2 80 4 +a 0 70 4 +a 1 25 2 +a 2 45 2 +b 0 50 4 +b 1 15 2 +b 2 35 2 + 0 120 8 + 1 40 4 + 2 80 4 +a 0 70 4 +a 1 25 2 +a 2 45 2 +b 0 50 4 +b 1 15 2 +b 2 35 2 + + 0 120 8 + 120 8 +a 70 4 +b 50 4 diff --git a/dbms/tests/queries/0_stateless/00718_with_cube.sql b/dbms/tests/queries/0_stateless/00718_with_cube.sql new file mode 100644 index 00000000000..7b19119478f --- /dev/null +++ b/dbms/tests/queries/0_stateless/00718_with_cube.sql @@ -0,0 +1,17 @@ +DROP TABLE IF EXISTS test.rollup; +CREATE TABLE test.rollup(a String, b Int32, s Int32) ENGINE = Memory; + +INSERT INTO test.rollup VALUES('a', 1, 10); +INSERT INTO test.rollup VALUES('a', 1, 15); +INSERT INTO test.rollup VALUES('a', 2, 20); +INSERT INTO test.rollup VALUES('a', 2, 25); +INSERT INTO test.rollup VALUES('b', 1, 10); +INSERT INTO test.rollup VALUES('b', 1, 5); +INSERT INTO test.rollup VALUES('b', 2, 20); +INSERT INTO test.rollup VALUES('b', 2, 15); + +SELECT a, b, sum(s), count() from test.rollup GROUP BY CUBE(a, b) ORDER BY a, b; + +SELECT a, b, sum(s), count() from test.rollup GROUP BY CUBE(a, b) WITH TOTALS ORDER BY a, b; + +SELECT a, sum(s), count() from test.rollup GROUP BY CUBE(a) ORDER BY a; \ No newline at end of file