Missing Visible Column in to_columns() for One-Sided Pivots with Hidden Sort Columns
Bug Report
Steps to Reproduce:
- Create a view with
group_by(one-sided pivot) configuration - Add more than one column to the
sortconfiguration that are NOT in thecolumnslist (hidden sort columns) - Call
view.to_columns() - Observe that the last visible column is missing from the result (for two columns in
sort). - The missing column is NOT used in
sortorgroup_by
Expected Result:
All visible columns specified in the columns configuration should be present in the to_columns() result, regardless of whether hidden sort columns are used.
Actual Result:
The last visible column (when two columns used in sort; if more columns are added to sort then more visible columns get excluded) is incorrectly excluded from the to_columns() output when hidden sort columns are present, even though that column is not itself a hidden sort column. The behavior is inconsistent ("semi-random") depending on the exact values of columns_length, hidden.
Environment:
For JavaScript (browser):
@perspective-dev/client: reproduced on4.1.1and4.5.1- Browser and version:
Chromium Version 151.0.7876.0 (Official Build) canary (arm64) - OS:
macOS 26.5.1
Additional Context:
Root cause
Multi-column sorting is a supported feature and is not the cause of this bug
The bug seems to be in the View<t_ctx1>::to_columns method in rust/perspective-server/cpp/perspective/src/cpp/view.cpp at lines 2702-2718.
The problematic filtering logic:
// Hidden columns are always at the end of the column names
// list, and we need to skip them from the output.
for (auto c = start_col + 1; c < end_col; ++c) {
if ((c - 1) > columns_length - hidden) {
continue;
}
write_column(...);
}
The condition (c - 1) > columns_length - hidden might be incorrect:
columns_lengthis passed asconfig->get_columns().size()(number of visible columns)hiddenis the number of hidden sort columns calculated bycalculate_num_hidden- When
hidden > 0,columns_length - hidden < columns_length
When the column index c reaches columns_length, the condition becomes (columns_length - 1) > columns_length - hidden, which evaluates to true when hidden >= 1. This causes the last visible column to be skipped even though it's not a hidden sort column.
Similar issue on demo page
As you can see on the screnshot chg columns is not rendered, though it should be. If I add more columns to "Order by", say "name", then "bid" column disappears too:
If I leave only 1 column in "Order by", then all 3 visible columns are shown as expected:
view.to_json is not affected
"Luckily" not all view serialization methods are affected. As a workaround I am using view.to_json now instead of view.to_columns as it doesn't skip the visible columns.