perspective icon indicating copy to clipboard operation
perspective copied to clipboard

Missing Visible Column in to_columns() for One-Sided Pivots with Hidden Sort Columns

Open N1kto opened this issue 4 months ago • 0 comments

Bug Report

Steps to Reproduce:

  1. Create a view with group_by (one-sided pivot) configuration
  2. Add more than one column to the sort configuration that are NOT in the columns list (hidden sort columns)
  3. Call view.to_columns()
  4. Observe that the last visible column is missing from the result (for two columns in sort).
  5. The missing column is NOT used in sort or group_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 on 4.1.1 and 4.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_length is passed as config->get_columns().size() (number of visible columns)
  • hidden is the number of hidden sort columns calculated by calculate_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

Image

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:

Image

If I leave only 1 column in "Order by", then all 3 visible columns are shown as expected:

Image

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.

N1kto avatar Jul 10 '26 12:07 N1kto