@@ -15,45 +15,53 @@ ::size_t findLeastUpperBound(std::vector<std::unique_ptr<cudf::table>> const &ta
15
15
auto action = [&tables, &colNo]<typename T>() {
16
16
using CudfScalarType = cudf::scalar_type_t <T>;
17
17
::size_t lubTableIndex = 0 ;
18
- std::unique_ptr<cudf::scalar> currentLub =
19
- cudf::get_element (tables.front ()->get_column (colNo), tables.front ()->get_column (colNo).size () - 1 );
18
+ std::unique_ptr<cudf::scalar> currentLub;
20
19
// Loop over each table view, grab the last element in the sort column and find the lowest
21
20
for (::size_t idx = 0 ; std::unique_ptr<cudf::table> const &table : tables) {
22
-
23
- std::unique_ptr<cudf::scalar> lastElement =
24
- cudf::get_element (table->view ().column (colNo), table->view ().column (colNo).size () - 1 );
25
- auto const lub_ptr = static_cast <CudfScalarType *>(currentLub.get ());
26
- auto const lastElement_ptr = static_cast <CudfScalarType *>(lastElement.get ());
27
-
28
- // Branch on template type if it's a string column or numeric column
29
- if constexpr (std::is_same_v<T, cudf::string_view>) {
30
- auto const lub = lub_ptr->to_string ();
31
- auto const last = lastElement_ptr->to_string ();
32
- // Perform string compare
33
- if (last < lub) {
21
+ if (table->num_rows () > 0 ) {
22
+ std::unique_ptr<cudf::scalar> lastElement =
23
+ cudf::get_element (table->view ().column (colNo), table->view ().column (colNo).size () - 1 );
24
+ // Skip rest of checks if this is the first table with data
25
+ if (!currentLub) {
26
+ SPDLOG_INFO (" Table {:d} is first with data" , idx);
34
27
currentLub = std::move (lastElement);
35
28
lubTableIndex = idx;
36
- SPDLOG_INFO (" Current least bound '{}' candidate '{}' is lower" , lub, last);
37
29
} else {
38
- SPDLOG_INFO (" Current least bound '{}' candidate '{}'" , lub, last);
39
- }
40
- } else if constexpr (cudf::is_integral_not_bool<T>()) {
41
- auto const lub = lub_ptr->value ();
42
- auto const last = lastElement_ptr->value ();
43
- // Perform numeric compare
44
- if (std::cmp_less (last, lub)) {
45
- currentLub = std::move (lastElement);
46
- lubTableIndex = idx;
47
- SPDLOG_INFO (" Current least bound '{}' candidate '{}' is lower" , lub, last);
48
- } else {
49
- SPDLOG_INFO (" Current least bound '{}' candidate '{}'" , lub, last);
30
+ auto const lub_ptr = static_cast <CudfScalarType *>(currentLub.get ());
31
+ auto const lastElement_ptr = static_cast <CudfScalarType *>(lastElement.get ());
32
+
33
+ // Branch on template type if it's a string column or numeric column
34
+ if constexpr (std::is_same_v<T, cudf::string_view>) {
35
+ auto const lub = lub_ptr->to_string ();
36
+ auto const last = lastElement_ptr->to_string ();
37
+ // Perform string compare
38
+ if (last < lub) {
39
+ currentLub = std::move (lastElement);
40
+ lubTableIndex = idx;
41
+ SPDLOG_INFO (" Current least bound '{}' candidate '{}' is lower" , lub, last);
42
+ } else {
43
+ SPDLOG_INFO (" Current least bound '{}' candidate '{}'" , lub, last);
44
+ }
45
+ } else if constexpr (cudf::is_integral_not_bool<T>()) {
46
+ auto const lub = lub_ptr->value ();
47
+ auto const last = lastElement_ptr->value ();
48
+ // Perform numeric compare
49
+ if (std::cmp_less (last, lub)) {
50
+ currentLub = std::move (lastElement);
51
+ lubTableIndex = idx;
52
+ SPDLOG_INFO (" Current least bound '{}' candidate '{}' is lower" , lub, last);
53
+ } else {
54
+ SPDLOG_INFO (" Current least bound '{}' candidate '{}'" , lub, last);
55
+ }
56
+ } else {
57
+ CUDF_FAIL (" Column type not supported" );
58
+ }
50
59
}
51
- } else {
52
- CUDF_FAIL (" Column type not supported" );
53
60
}
54
61
idx++;
55
62
}
56
63
SPDLOG_INFO (" Found least upper bound on file no {:d}" , lubTableIndex);
64
+ CUDF_EXPECTS (currentLub, " No table contained any data!" );
57
65
return lubTableIndex;
58
66
};
59
67
0 commit comments