mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 16:42:05 +00:00
SummingMergeTree for Decimal128 [issue-3282]
This commit is contained in:
parent
b8543bcd4d
commit
5896e45dac
@ -107,7 +107,7 @@ public:
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
||||
{
|
||||
/// TODO Do positions need to be 1-based for this function?
|
||||
size_t position = columns[1]->get64(row_num);
|
||||
size_t position = columns[1]->getUInt(row_num);
|
||||
|
||||
/// If position is larger than size to which array will be cutted - simply ignore value.
|
||||
if (length_to_resize && position >= length_to_resize)
|
||||
|
@ -1,6 +1,3 @@
|
||||
#include <cmath>
|
||||
#include <ext/bit_cast.h>
|
||||
|
||||
#include <Common/Exception.h>
|
||||
#include <Common/Arena.h>
|
||||
#include <Common/SipHash.h>
|
||||
@ -53,7 +50,7 @@ UInt64 ColumnDecimal<T>::get64(size_t n) const
|
||||
{
|
||||
if constexpr (sizeof(T) > sizeof(UInt64))
|
||||
throw Exception(String("Method get64 is not supported for ") + getFamilyName(), ErrorCodes::NOT_IMPLEMENTED);
|
||||
return ext::bit_cast<UInt64>(data[n]);
|
||||
return static_cast<typename T::NativeType>(data[n]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -112,6 +112,7 @@ public:
|
||||
bool getBool(size_t n) const override { return bool(data[n]); }
|
||||
Int64 getInt(size_t n) const override { return Int64(data[n] * scale); }
|
||||
UInt64 get64(size_t n) const override;
|
||||
bool isDefaultAt(size_t n) const override { return data[n] == 0; }
|
||||
|
||||
ColumnPtr filter(const IColumn::Filter & filt, ssize_t result_size_hint) const override;
|
||||
ColumnPtr permute(const IColumn::Permutation & perm, size_t limit) const override;
|
||||
|
@ -105,6 +105,7 @@ public:
|
||||
throw Exception("Method getInt is not supported for " + getName(), ErrorCodes::NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
virtual bool isDefaultAt(size_t n) const { return get64(n) == 0; }
|
||||
virtual bool isNullAt(size_t /*n*/) const { return false; }
|
||||
|
||||
/** If column is numeric, return value of n-th element, casted to bool.
|
||||
|
@ -132,7 +132,7 @@ void GraphiteRollupSortedBlockInputStream::merge(MutableColumns & merged_columns
|
||||
|
||||
is_first = false;
|
||||
|
||||
time_t next_row_time = next_cursor->all_columns[time_column_num]->get64(next_cursor->pos);
|
||||
time_t next_row_time = next_cursor->all_columns[time_column_num]->getUInt(next_cursor->pos);
|
||||
/// Is new key before rounding.
|
||||
bool is_new_key = new_path || next_row_time != current_time;
|
||||
|
||||
|
@ -216,7 +216,7 @@ void SummingSortedBlockInputStream::insertCurrentRowIfNeeded(MutableColumns & me
|
||||
if (desc.column_numbers.size() == 1)
|
||||
{
|
||||
// Flag row as non-empty if at least one column number if non-zero
|
||||
current_row_is_zero = current_row_is_zero && desc.merged_column->get64(desc.merged_column->size() - 1) == 0;
|
||||
current_row_is_zero = current_row_is_zero && desc.merged_column->isDefaultAt(desc.merged_column->size() - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
2
dbms/tests/queries/0_stateless/issue_3282.reference
Normal file
2
dbms/tests/queries/0_stateless/issue_3282.reference
Normal file
@ -0,0 +1,2 @@
|
||||
2001-01-01 2.0000 0.00000000 -2.0000000000
|
||||
2001-01-01 0.0000 1.00000000 0.0000000000
|
27
dbms/tests/queries/0_stateless/issue_3282.sql
Normal file
27
dbms/tests/queries/0_stateless/issue_3282.sql
Normal file
@ -0,0 +1,27 @@
|
||||
CREATE DATABASE IF NOT EXISTS test;
|
||||
DROP TABLE IF EXISTS test.decimal_sum;
|
||||
CREATE TABLE test.decimal_sum
|
||||
(
|
||||
date Date,
|
||||
sum32 Decimal32(4),
|
||||
sum64 Decimal64(8),
|
||||
sum128 Decimal128(10)
|
||||
) Engine = SummingMergeTree(date, (date), 8192);
|
||||
|
||||
INSERT INTO test.decimal_sum VALUES ('2001-01-01', 1, 1, -1);
|
||||
INSERT INTO test.decimal_sum VALUES ('2001-01-01', 1, -1, -1);
|
||||
|
||||
OPTIMIZE TABLE test.decimal_sum;
|
||||
SELECT * FROM test.decimal_sum;
|
||||
|
||||
INSERT INTO test.decimal_sum VALUES ('2001-01-01', -2, 1, 2);
|
||||
|
||||
OPTIMIZE TABLE test.decimal_sum;
|
||||
SELECT * FROM test.decimal_sum;
|
||||
|
||||
INSERT INTO test.decimal_sum VALUES ('2001-01-01', 0, -1, 0);
|
||||
|
||||
OPTIMIZE TABLE test.decimal_sum;
|
||||
SELECT * FROM test.decimal_sum;
|
||||
|
||||
drop table test.decimal_sum;
|
Loading…
Reference in New Issue
Block a user