Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Commit 5e72166

Browse files
committed
Remove decimal overflow validator entirely
Decimal validation occurs on parse, when the input value (string, etc) is converted to an arrow::DecimalXX value.
1 parent e00a35e commit 5e72166

File tree

6 files changed

+10
-64
lines changed

6 files changed

+10
-64
lines changed

omniscidb/DataMgr/Encoder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ Encoder* Encoder::Create(Data_Namespace::AbstractBuffer* buffer,
118118
Encoder::Encoder(Data_Namespace::AbstractBuffer* buffer)
119119
: num_elems_(0)
120120
, buffer_(buffer)
121-
, decimal_overflow_validator_(buffer ? buffer->type() : nullptr)
122121
, date_days_overflow_validator_(buffer ? buffer->type() : nullptr){};
123122

124123
std::shared_ptr<ChunkMetadata> Encoder::getMetadata() {

omniscidb/DataMgr/Encoder.h

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -36,61 +36,6 @@ class AbstractBuffer;
3636
// default max input buffer size to 1MB
3737
#define MAX_INPUT_BUF_SIZE 1048576
3838

39-
class DecimalOverflowValidator {
40-
public:
41-
DecimalOverflowValidator(const hdk::ir::Type* type) {
42-
if (type && type->isArray()) {
43-
type = type->as<hdk::ir::ArrayBaseType>()->elemType();
44-
}
45-
46-
if (type && type->isDecimal()) {
47-
do_check_ = true;
48-
int precision = type->as<hdk::ir::DecimalType>()->precision();
49-
int scale = type->as<hdk::ir::DecimalType>()->scale();
50-
max_ = (int64_t)std::pow((double)10.0, precision);
51-
min_ = -max_;
52-
pow10_ = precision - scale;
53-
54-
} else {
55-
do_check_ = false;
56-
max_ = 1;
57-
min_ = -1;
58-
pow10_ = 0;
59-
}
60-
}
61-
62-
template <typename T>
63-
void validate(T value) const {
64-
if (std::is_integral<T>::value) {
65-
do_validate(static_cast<int64_t>(value));
66-
}
67-
}
68-
69-
void do_validate(int64_t value) const {
70-
if (!do_check_) {
71-
return;
72-
}
73-
74-
if (value >= max_) {
75-
throw std::runtime_error("Decimal overflow: value is greater than 10^" +
76-
std::to_string(pow10_) + " max " + std::to_string(max_) +
77-
" value " + std::to_string(value));
78-
}
79-
80-
if (value <= min_) {
81-
throw std::runtime_error("Decimal overflow: value is less than -10^" +
82-
std::to_string(pow10_) + " min " + std::to_string(min_) +
83-
" value " + std::to_string(value));
84-
}
85-
}
86-
87-
private:
88-
bool do_check_;
89-
int64_t max_;
90-
int64_t min_;
91-
int pow10_;
92-
};
93-
9439
template <typename INNER_VALIDATOR>
9540
class NullAwareValidator {
9641
public:
@@ -253,7 +198,6 @@ class Encoder {
253198

254199
Data_Namespace::AbstractBuffer* buffer_;
255200

256-
DecimalOverflowValidator decimal_overflow_validator_;
257201
DateDaysOverflowValidator date_days_overflow_validator_;
258202
};
259203

omniscidb/DataMgr/FixedLengthArrayNoneEncoder.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,9 @@ class FixedLengthArrayNoneEncoder : public Encoder {
325325
if (bigint_array[i] == NULL_BIGINT) {
326326
has_nulls = true;
327327
} else if (initialized) {
328-
decimal_overflow_validator_.validate(bigint_array[i]);
329328
elem_min.bigintval = std::min(elem_min.bigintval, bigint_array[i]);
330329
elem_max.bigintval = std::max(elem_max.bigintval, bigint_array[i]);
331330
} else {
332-
decimal_overflow_validator_.validate(bigint_array[i]);
333331
elem_min.bigintval = bigint_array[i];
334332
elem_max.bigintval = bigint_array[i];
335333
initialized = true;

omniscidb/DataMgr/FixedLengthEncoder.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class FixedLengthEncoder : public Encoder {
9191
for (size_t i = range.begin(); i < range.end(); i++) {
9292
if (data[i] != inline_null_value<V>()) {
9393
if (!fixlen_array || data[i] != inline_null_array_value<V>()) {
94-
decimal_overflow_validator_.validate(data[i]);
9594
min = std::min(min, data[i]);
9695
max = std::max(max, data[i]);
9796
}
@@ -189,7 +188,6 @@ class FixedLengthEncoder : public Encoder {
189188
V encodeDataAndUpdateStats(const T& unencoded_data) {
190189
V encoded_data = static_cast<V>(unencoded_data);
191190
if (unencoded_data != encoded_data) {
192-
decimal_overflow_validator_.validate(unencoded_data);
193191
LOG(ERROR) << "Fixed encoding failed, Unencoded: " +
194192
std::to_string(unencoded_data) +
195193
" encoded: " + std::to_string(encoded_data);
@@ -198,7 +196,6 @@ class FixedLengthEncoder : public Encoder {
198196
if (data == std::numeric_limits<V>::min()) {
199197
has_nulls = true;
200198
} else {
201-
decimal_overflow_validator_.validate(data);
202199
dataMin = std::min(dataMin, data);
203200
dataMax = std::max(dataMax, data);
204201
}

omniscidb/DataMgr/NoneEncoder.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ class NoneEncoder : public Encoder {
9494
for (size_t i = range.begin(); i < range.end(); i++) {
9595
if (data[i] != inline_null_value<T>()) {
9696
if (!fixlen_array || data[i] != inline_null_array_value<T>()) {
97-
decimal_overflow_validator_.validate(data[i]);
9897
min = std::min(min, data[i]);
9998
max = std::max(max, data[i]);
10099
}
@@ -192,7 +191,6 @@ class NoneEncoder : public Encoder {
192191
if (unencoded_data == none_encoded_null_value<T>()) {
193192
has_nulls = true;
194193
} else {
195-
decimal_overflow_validator_.validate(unencoded_data);
196194
dataMin = std::min(dataMin, unencoded_data);
197195
dataMax = std::max(dataMax, unencoded_data);
198196
}

omniscidb/Tests/ArrowStorageTest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,16 @@ TEST_F(ArrowStorageTest, AppendCsvData_Decimals) {
17341734
std::vector<int64_t>({22200, 22222, 20000, inline_null_value<int64_t>()}));
17351735
}
17361736

1737+
TEST_F(ArrowStorageTest, AppendCsvData_Decimals_OutOfRange) {
1738+
ArrowStorage storage(TEST_SCHEMA_ID, "test", TEST_DB_ID, config_);
1739+
ArrowStorage::CsvParseOptions parse_options;
1740+
parse_options.header = false;
1741+
TableInfoPtr tinfo = storage.createTable(
1742+
"table1", {{"d1", ctx.decimal64(10, 4)}, {"d2", ctx.decimal64(10, 6)}});
1743+
EXPECT_ANY_THROW(storage.appendCsvData(
1744+
"12345678910.12345,12345678910.1234567", tinfo->table_id, parse_options));
1745+
}
1746+
17371747
TEST_F(ArrowStorageTest, AppendJsonData_DecimalArrays) {
17381748
ArrowStorage storage(TEST_SCHEMA_ID, "test", TEST_DB_ID, config_);
17391749
auto decimal_3 = ctx.arrayFixed(3, ctx.decimal64(10, 2));

0 commit comments

Comments
 (0)