Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: DH-16595: Fix null partition filter #1954

Merged
merged 5 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/iris-grid/src/IrisGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,11 @@ class IrisGrid extends Component<IrisGridProps, IrisGridState> {
return;
}
const row = data.rows[0];
const values = keyTable.columns.map(column => row.get(column));
// Core JSAPI returns undefined for null table values, IrisGridPartitionSelector expects null
vbabich marked this conversation as resolved.
Show resolved Hide resolved
// https://github.com/deephaven/deephaven-core/issues/5400
const values = keyTable.columns.map(
column => row.get(column) ?? null
);
const newPartition: PartitionConfig = {
partitions: values,
mode: 'partition',
Expand Down
35 changes: 17 additions & 18 deletions packages/iris-grid/src/IrisGridPartitionSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,19 @@ class IrisGridPartitionSelector extends Component<
.slice(0, index + 1)
.map((partition, i) => {
const partitionColumn = t.columns[i];
return partitionColumn
.filter()
.eq(
this.tableUtils.makeFilterRawValue(
partitionColumn.type,
partition
)
);
return this.tableUtils.makeNullableEqFilter(
partitionColumn,
partition
);
});
t.applyFilter(partitionFilters);
t.setViewport(0, 0, t.columns);
const data = await this.pending.add(t.getViewportData());
const newConfig: PartitionConfig = {
partitions: t.columns.map(column => data.rows[0].get(column)),
// Core JSAPI returns undefined for null table values,
// coalesce with null to differentiate null from no selection in the dropdown
// https://github.com/deephaven/deephaven-core/issues/5400
partitions: t.columns.map(column => data.rows[0].get(column) ?? null),
mode: 'partition',
};
t.close();
Expand Down Expand Up @@ -214,7 +213,11 @@ class IrisGridPartitionSelector extends Component<
getDisplayValue(index: number, value: unknown): string {
const { model } = this.props;

if (value == null || value === '') {
if (value === null) {
return '(null)';
}

if (value === undefined || value === '') {
return '';
}
const column = model.partitionColumns[index];
Expand Down Expand Up @@ -267,14 +270,10 @@ class IrisGridPartitionSelector extends Component<
const previousColumn = model.partitionColumns[i - 1];
const partitionFilter = [
...previousFilter,
previousColumn
.filter()
.eq(
this.tableUtils.makeFilterRawValue(
previousColumn.type,
previousPartition
)
),
this.tableUtils.makeNullableEqFilter(
previousColumn,
previousPartition
),
];
partitionFilters.push(partitionFilter);
}
Expand Down
7 changes: 3 additions & 4 deletions packages/iris-grid/src/IrisGridTableModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,11 @@ class IrisGridTableModel
for (let i = 0; i < this.partitionColumns.length; i += 1) {
const partition = partitions[i];
const partitionColumn = this.partitionColumns[i];

const partitionFilter = this.tableUtils.makeFilterRawValue(
partitionColumn.type,
const partitionFilter = this.tableUtils.makeNullableEqFilter(
partitionColumn,
partition
);
partitionFilters.push(partitionColumn.filter().eq(partitionFilter));
partitionFilters.push(partitionFilter);
}

const t = await this.table.copy();
Expand Down
5 changes: 4 additions & 1 deletion packages/jsapi-components/src/TableDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export function TableDropdown({
dh.Table.EVENT_UPDATED,
(event: CustomEvent<DhType.ViewportData>) => {
const { detail } = event;
const newValues = detail.rows.map(row => row.get(tableColumn));
// Core JSAPI returns undefined for null table values,
// coalesce with null to differentiate null from no selection in the dropdown
// https://github.com/deephaven/deephaven-core/issues/5400
const newValues = detail.rows.map(row => row.get(tableColumn) ?? null);
setValues(newValues);
}
);
Expand Down
16 changes: 16 additions & 0 deletions packages/jsapi-utils/src/TableUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,22 @@ export class TableUtils {
return dh.FilterValue.ofNumber(rawValue as number);
}

/**
* Creates an Eq filter for the given column and raw value
* @param column The column to set the filter on
* @param rawValue The nullable value to filter on
* @returns The filter for this column/value combination
*/
makeNullableEqFilter(
column: DhType.Column,
rawValue: unknown
): DhType.FilterCondition {
if (rawValue == null) {
return column.filter().isNull();
}
return column.filter().eq(this.makeFilterRawValue(column.type, rawValue));
}

/**
* Converts a string value to a value appropriate for the column
* @param columnType The column type to make the value for
Expand Down
Loading