Skip to content

Commit b9df24f

Browse files
committed
Raise exception if SortOrder::Unknown when building comparator and noop the usage of comparator
1 parent cdbe4e2 commit b9df24f

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

cpp/src/parquet/statistics.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,11 @@ class TypedStatisticsImpl : public TypedStatistics<DType> {
578578
min_buffer_(AllocateBuffer(pool_, 0)),
579579
max_buffer_(AllocateBuffer(pool_, 0)),
580580
logical_type_(LogicalTypeId(descr_)) {
581-
comparator_ = MakeComparator<DType>(descr);
581+
try {
582+
comparator_ = MakeComparator<DType>(descr);
583+
} catch (const std::exception& e) {
584+
comparator_ = nullptr;
585+
}
582586
TypedStatisticsImpl::Reset();
583587
}
584588

@@ -737,6 +741,7 @@ class TypedStatisticsImpl : public TypedStatistics<DType> {
737741
return;
738742
}
739743

744+
if (comparator_ == nullptr) return;
740745
SetMinMaxPair(comparator_->GetMinMax(values));
741746
}
742747

@@ -839,7 +844,7 @@ class TypedStatisticsImpl : public TypedStatistics<DType> {
839844
void SetMinMaxPair(std::pair<T, T> min_max) {
840845
// CleanStatistic can return a nullopt in case of erroneous values, e.g. NaN
841846
auto maybe_min_max = CleanStatistic(min_max, logical_type_);
842-
if (!maybe_min_max) return;
847+
if (!maybe_min_max || comparator_ == nullptr) return;
843848

844849
auto min = maybe_min_max.value().first;
845850
auto max = maybe_min_max.value().second;
@@ -899,7 +904,7 @@ void TypedStatisticsImpl<DType>::Update(const T* values, int64_t num_values,
899904
IncrementNullCount(null_count);
900905
IncrementNumValues(num_values);
901906

902-
if (num_values == 0) return;
907+
if (num_values == 0 || comparator_ == nullptr) return;
903908
SetMinMaxPair(comparator_->GetMinMax(values, num_values));
904909
}
905910

@@ -914,7 +919,7 @@ void TypedStatisticsImpl<DType>::UpdateSpaced(const T* values, const uint8_t* va
914919
IncrementNullCount(null_count);
915920
IncrementNumValues(num_values);
916921

917-
if (num_values == 0) return;
922+
if (num_values == 0 || comparator_ == nullptr) return;
918923
SetMinMaxPair(comparator_->GetMinMaxSpaced(values, num_spaced_values, valid_bits,
919924
valid_bits_offset));
920925
}
@@ -996,8 +1001,6 @@ std::shared_ptr<Comparator> DoMakeComparator(Type::type physical_type,
9961001
default:
9971002
ParquetException::NYI("Unsigned Compare not implemented");
9981003
}
999-
} else if (SortOrder::UNKNOWN == sort_order) {
1000-
return nullptr;
10011004
} else {
10021005
throw ParquetException("UNKNOWN Sort Order");
10031006
}

cpp/src/parquet/statistics_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ TEST(Comparison, UnknownSortOrder) {
296296
ConvertedType::INTERVAL, 12);
297297
ColumnDescriptor descr(node, 0, 0);
298298

299-
ASSERT_EQ(Comparator::Make(&descr), nullptr);
299+
ASSERT_THROW(Comparator::Make(&descr), ParquetException);
300300
}
301301

302302
// ----------------------------------------------------------------------

0 commit comments

Comments
 (0)