Skip to content

Commit 1cc7532

Browse files
committed
improve the logic to handle groups split by opposite-signed index
1 parent 41fb595 commit 1cc7532

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

Framework/Core/include/Framework/Kernels.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,29 @@ auto sliceByColumn(
8181
for (auto i = 0; i < column->num_chunks(); ++i) {
8282
T prev = 0;
8383
T cur = 0;
84-
T nprev = -1;
84+
T lastNeg = -1;
85+
T lastPos = 0;
86+
8587
auto array = static_cast<arrow::NumericArray<typename detail::ConversionTraits<T>::ArrowType>>(column->chunk(i)->data());
8688
for (auto e = 0; e < array.length(); ++e) {
87-
if (cur >= 0) {
88-
prev = cur;
89+
prev = cur;
90+
if (prev >= 0) {
91+
lastPos = prev;
8992
} else {
90-
nprev = cur;
93+
lastNeg = prev;
9194
}
9295
cur = array.Value(e);
9396
if (cur >= 0) {
94-
if (prev > cur) {
95-
throw runtime_error_f("Table %s index %s is not sorted: next value %d < previous value %d!", target, key, cur, prev);
97+
if (lastPos > cur) {
98+
throw runtime_error_f("Table %s index %s is not sorted: next value %d < previous value %d!", target, key, cur, lastPos);
99+
} else if (lastPos == cur && prev < 0) {
100+
throw runtime_error_f("Table %s index %s has a group with index %d that is split by %d", target, key, cur, prev);
96101
}
97102
} else {
98-
if (nprev < cur) {
99-
throw runtime_error_f("Table %s index %s is not sorted: next negative value %d > previous negative value %d!", target, key, cur, nprev);
103+
if (lastNeg < cur) {
104+
throw runtime_error_f("Table %s index %s is not sorted: next negative value %d > previous negative value %d!", target, key, cur, lastNeg);
105+
} else if (lastNeg == cur && prev >= 0) {
106+
throw runtime_error_f("Table %s index %s has a group with index %d that is split by %d", target, key, cur, prev);
100107
}
101108
}
102109
}

0 commit comments

Comments
 (0)