Fix GROUPING function SQL compatibility

This commit is contained in:
Dmitry Novik 2022-08-29 18:26:56 +02:00
parent 5cbe7e0846
commit d32492ce8a
2 changed files with 28 additions and 30 deletions

View File

@ -3,7 +3,6 @@
#include <Columns/ColumnsNumber.h>
#include <Columns/ColumnArray.h>
#include <Columns/ColumnConst.h>
#include <Columns/ColumnFixedString.h>
#include <Core/ColumnNumbers.h>
#include <DataTypes/DataTypesNumber.h>
#include <Functions/FunctionFactory.h>
@ -54,7 +53,7 @@ public:
UInt64 value = 0;
for (auto index : arguments_indexes)
value = (value << 1) + (checker(set_index, index) ? 1 : 0);
value = (value << 1) + (checker(set_index, index) ? 0 : 1);
result_data.push_back(value);
}
@ -73,8 +72,7 @@ public:
ColumnPtr executeImpl(const ColumnsWithTypeAndName &, const DataTypePtr &, size_t input_rows_count) const override
{
UInt64 value = (ONE << arguments_indexes.size()) - 1;
return ColumnUInt64::create(input_rows_count, value);
return ColumnUInt64::create(input_rows_count, 0);
}
};

View File

@ -1,29 +1,29 @@
-- { echoOn }
SELECT count() AS amount, a, b, GROUPING(a, b) FROM test02315 GROUP BY GROUPING SETS ((a, b), (a), ()) ORDER BY (amount, a, b);
1 0 0 3
1 0 2 3
1 0 4 3
1 0 6 3
1 0 8 3
1 1 1 3
1 1 3 3
1 1 5 3
1 1 7 3
1 1 9 3
5 0 0 2
5 1 0 2
10 0 0 0
1 0 0 0
1 0 2 0
1 0 4 0
1 0 6 0
1 0 8 0
1 1 1 0
1 1 3 0
1 1 5 0
1 1 7 0
1 1 9 0
5 0 0 1
5 1 0 1
10 0 0 3
SELECT count() AS amount, a, b, GROUPING(a, b) FROM test02315 GROUP BY ROLLUP(a, b) ORDER BY (amount, a, b);
1 0 0 3
1 0 2 3
1 0 4 3
1 0 6 3
1 0 8 3
1 1 1 3
1 1 3 3
1 1 5 3
1 1 7 3
1 1 9 3
5 0 0 2
5 1 0 2
10 0 0 0
1 0 0 0
1 0 2 0
1 0 4 0
1 0 6 0
1 0 8 0
1 1 1 0
1 1 3 0
1 1 5 0
1 1 7 0
1 1 9 0
5 0 0 1
5 1 0 1
10 0 0 3