Skip to content

Commit

Permalink
Add less-equal, greater-equal, null, not null filter types, get thing…
Browse files Browse the repository at this point in the history
…s working
  • Loading branch information
wesm committed Apr 12, 2024
1 parent a0a6031 commit dd0bfbb
Show file tree
Hide file tree
Showing 10 changed files with 316 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from .access_keys import decode_access_key
from .data_explorer_comm import (
BackendState,
ColumnFrequencyTable,
ColumnHistogram,
ColumnSummaryStats,
Expand All @@ -35,7 +36,6 @@
ColumnSortKey,
DataExplorerBackendMessageContent,
DataExplorerFrontendEvent,
DataExplorerState,
FilterResult,
GetColumnProfilesFeatures,
GetColumnProfilesRequest,
Expand Down Expand Up @@ -222,7 +222,7 @@ def _prof_histogram(self, column_index: int) -> ColumnHistogram:
pass

@abc.abstractmethod
def _get_state(self) -> DataExplorerState:
def _get_state(self) -> BackendState:
pass


Expand Down Expand Up @@ -724,13 +724,13 @@ def _prof_histogram(self, column_index: int):
get_column_profiles=_column_profile_features,
)

def _get_state(self) -> DataExplorerState:
def _get_state(self) -> BackendState:
if self.view_indices is not None:
num_rows = len(self.view_indices)
else:
num_rows = self.table.shape[0]

return DataExplorerState(
return BackendState(
table_shape=TableShape(num_rows=num_rows, num_columns=self.table.shape[1]),
row_filters=self.filters,
sort_keys=self.sort_keys,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class FilterResult(BaseModel):
)


class DataExplorerState(BaseModel):
class BackendState(BaseModel):
"""
The current backend state for the data explorer
"""
Expand Down Expand Up @@ -270,6 +270,10 @@ class RowFilter(BaseModel):
Specifies a table row filter based on a single column's values
"""

filter_id: str = Field(
description="Unique identifier for this filter",
)

filter_type: RowFilterType = Field(
description="Type of row filter to apply",
)
Expand Down Expand Up @@ -903,7 +907,7 @@ class SchemaUpdateParams(BaseModel):

FilterResult.update_forward_refs()

DataExplorerState.update_forward_refs()
BackendState.update_forward_refs()

TableShape.update_forward_refs()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ def test_pandas_get_data_values(dxf: DataExplorerFixture):
def _filter(filter_type, column_index, condition="and", is_valid=None, **kwargs):
kwargs.update(
{
"filter_id": guid(),
"filter_type": filter_type,
"column_index": column_index,
"condition": condition,
Expand Down
7 changes: 6 additions & 1 deletion positron/comms/data_explorer-backend-openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
"result": {
"schema": {
"type": "object",
"name": "data_explorer_state",
"name": "backend_state",
"description": "The current backend state for the data explorer",
"required": [
"table_shape",
Expand Down Expand Up @@ -385,11 +385,16 @@
"type": "object",
"description": "Specifies a table row filter based on a single column's values",
"required": [
"filter_id",
"filter_type",
"column_index",
"condition"
],
"properties": {
"filter_id": {
"type": "string",
"description": "Unique identifier for this filter"
},
"filter_type": {
"description": "Type of row filter to apply",
"$ref": "#/components/schemas/row_filter_type"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { DataExplorerClientInstance } from 'vs/workbench/services/languageRuntim
import { DropDownListBox, DropDownListBoxEntry } from 'vs/workbench/browser/positronComponents/dropDownListBox/dropDownListBox';
import { RowFilterParameter } from 'vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/components/rowFilterParameter';
import { DropDownColumnSelector } from 'vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/components/dropDownColumnSelector';
import { RangeRowFilterDescriptor, RowFilterDescriptor, RowFilterCondition, RowFilterDescriptorIsBetween, RowFilterDescriptorIsEmpty, RowFilterDescriptorIsEqualTo, RowFilterDescriptorIsGreaterThan, RowFilterDescriptorIsLessThan, RowFilterDescriptorIsNotBetween, RowFilterDescriptorIsNotEmpty, SingleValueRowFilterDescriptor } from 'vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/rowFilterDescriptor';
import { RangeRowFilterDescriptor, RowFilterDescriptor, RowFilterCondition, RowFilterDescriptorIsBetween, RowFilterDescriptorIsEmpty, RowFilterDescriptorIsEqualTo, RowFilterDescriptorIsGreaterThan, RowFilterDescriptorIsLessThan, RowFilterDescriptorIsNotBetween, RowFilterDescriptorIsNotEmpty, SingleValueRowFilterDescriptor, RowFilterDescriptorIsLessOrEqual, RowFilterDescriptorIsGreaterOrEqual, RowFilterDescriptorIsNotNull, RowFilterDescriptorIsNull } from 'vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/rowFilterDescriptor';

/**
* Validates a row filter value.
Expand Down Expand Up @@ -141,25 +141,46 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp
// Build the condition entries.
const conditionEntries: DropDownListBoxEntry<RowFilterCondition, void>[] = [];

// Every type allows is empty and is not empty conditions.
// Every type allows is null and is not null conditions.
conditionEntries.push(new DropDownListBoxItem({
identifier: RowFilterCondition.CONDITION_IS_EMPTY,
identifier: RowFilterCondition.CONDITION_IS_NULL,
title: localize(
'positron.addEditRowFilter.conditionIsEmpty',
"is empty"
'positron.addEditRowFilter.conditionIsNull',
"is null"
),
value: RowFilterCondition.CONDITION_IS_EMPTY
value: RowFilterCondition.CONDITION_IS_NULL
}));
conditionEntries.push(new DropDownListBoxItem({
identifier: RowFilterCondition.CONDITION_IS_NOT_EMPTY,
identifier: RowFilterCondition.CONDITION_IS_NOT_NULL,
title: localize(
'positron.addEditRowFilter.conditionIsNotEmpty',
"is not empty"
'positron.addEditRowFilter.conditionIsNotNull',
"is not null"
),
value: RowFilterCondition.CONDITION_IS_NOT_EMPTY
value: RowFilterCondition.CONDITION_IS_NOT_NULL
}));
conditionEntries.push(new DropDownListBoxSeparator());

if (selectedColumnSchema.type_display === ColumnDisplayType.String) {
// String types support is empty, is not empty filter types
conditionEntries.push(new DropDownListBoxItem({
identifier: RowFilterCondition.CONDITION_IS_EMPTY,
title: localize(
'positron.addEditRowFilter.conditionIsEmpty',
"is empty"
),
value: RowFilterCondition.CONDITION_IS_EMPTY
}));
conditionEntries.push(new DropDownListBoxItem({
identifier: RowFilterCondition.CONDITION_IS_NOT_EMPTY,
title: localize(
'positron.addEditRowFilter.conditionIsNotEmpty',
"is not empty"
),
value: RowFilterCondition.CONDITION_IS_NOT_EMPTY
}));
conditionEntries.push(new DropDownListBoxSeparator());
}

// Add is less than / is greater than conditions.
switch (selectedColumnSchema.type_display) {
case ColumnDisplayType.Number:
Expand All @@ -174,6 +195,14 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp
),
value: RowFilterCondition.CONDITION_IS_LESS_THAN
}));
conditionEntries.push(new DropDownListBoxItem({
identifier: RowFilterCondition.CONDITION_IS_LESS_OR_EQUAL,
title: localize(
'positron.addEditRowFilter.conditionIsLessThanOrEqual',
"is less than or equal to"
),
value: RowFilterCondition.CONDITION_IS_LESS_OR_EQUAL
}));
conditionEntries.push(new DropDownListBoxItem({
identifier: RowFilterCondition.CONDITION_IS_GREATER_THAN,
title: localize(
Expand All @@ -182,6 +211,14 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp
),
value: RowFilterCondition.CONDITION_IS_GREATER_THAN
}));
conditionEntries.push(new DropDownListBoxItem({
identifier: RowFilterCondition.CONDITION_IS_GREATER_OR_EQUAL,
title: localize(
'positron.addEditRowFilter.conditionIsGreaterThanOrEqual',
"is greater than or equal to"
),
value: RowFilterCondition.CONDITION_IS_GREATER_OR_EQUAL
}));
break;
}

Expand Down Expand Up @@ -240,13 +277,17 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp
switch (selectedCondition) {
// Do not render the first row filter parameter component.
case undefined:
case RowFilterCondition.CONDITION_IS_NULL:
case RowFilterCondition.CONDITION_IS_NOT_NULL:
case RowFilterCondition.CONDITION_IS_EMPTY:
case RowFilterCondition.CONDITION_IS_NOT_EMPTY:
return null;

// Render the first row filter parameter component in single-value mode.
case RowFilterCondition.CONDITION_IS_LESS_THAN:
case RowFilterCondition.CONDITION_IS_LESS_OR_EQUAL:
case RowFilterCondition.CONDITION_IS_GREATER_THAN:
case RowFilterCondition.CONDITION_IS_GREATER_OR_EQUAL:
case RowFilterCondition.CONDITION_IS_EQUAL_TO:
placeholderText = localize(
'positron.addEditRowFilter.valuePlaceholder',
Expand Down Expand Up @@ -287,10 +328,14 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp
switch (selectedCondition) {
// Do not render the second row filter parameter component.
case undefined:
case RowFilterCondition.CONDITION_IS_NULL:
case RowFilterCondition.CONDITION_IS_NOT_NULL:
case RowFilterCondition.CONDITION_IS_EMPTY:
case RowFilterCondition.CONDITION_IS_NOT_EMPTY:
case RowFilterCondition.CONDITION_IS_LESS_THAN:
case RowFilterCondition.CONDITION_IS_LESS_OR_EQUAL:
case RowFilterCondition.CONDITION_IS_GREATER_THAN:
case RowFilterCondition.CONDITION_IS_GREATER_OR_EQUAL:
case RowFilterCondition.CONDITION_IS_EQUAL_TO:
return null;

Expand Down Expand Up @@ -469,6 +514,18 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp
break;
}

// Apply the is null row filter.
case RowFilterCondition.CONDITION_IS_NULL: {
applyRowFilter(new RowFilterDescriptorIsNull(selectedColumnSchema));
break;
}

// Apply the is not null row filter.
case RowFilterCondition.CONDITION_IS_NOT_NULL: {
applyRowFilter(new RowFilterDescriptorIsNotNull(selectedColumnSchema));
break;
}

// Apply the is less than row filter.
case RowFilterCondition.CONDITION_IS_LESS_THAN: {
if (!validateFirstRowFilterValue()) {
Expand All @@ -481,6 +538,18 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp
break;
}

// Apply the is less than row filter.
case RowFilterCondition.CONDITION_IS_LESS_OR_EQUAL: {
if (!validateFirstRowFilterValue()) {
return;
}
applyRowFilter(new RowFilterDescriptorIsLessOrEqual(
selectedColumnSchema,
firstRowFilterValue
));
break;
}

// Apply the is greater than row filter.
case RowFilterCondition.CONDITION_IS_GREATER_THAN: {
if (!validateFirstRowFilterValue()) {
Expand All @@ -493,6 +562,18 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp
break;
}

// Apply the is greater than row filter.
case RowFilterCondition.CONDITION_IS_GREATER_OR_EQUAL: {
if (!validateFirstRowFilterValue()) {
return;
}
applyRowFilter(new RowFilterDescriptorIsGreaterOrEqual(
selectedColumnSchema,
firstRowFilterValue
));
break;
}

// Apply the is equal to row filter.
case RowFilterCondition.CONDITION_IS_EQUAL_TO: {
if (!validateFirstRowFilterValue()) {
Expand All @@ -505,6 +586,7 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp
break;
}


// Apply the is between row filter.
case RowFilterCondition.CONDITION_IS_BETWEEN: {
if (!validateFirstRowFilterValue()) {
Expand Down
Loading

0 comments on commit dd0bfbb

Please sign in to comment.