Search in sources :

Example 1 with FilterCondition

use of io.deephaven.web.client.api.filter.FilterCondition in project deephaven-core by deephaven.

the class JsTable method applyFilter.

@JsMethod
@SuppressWarnings("unusable-by-js")
public JsArray<FilterCondition> applyFilter(FilterCondition[] filter) {
    final List<FilterCondition> newFilter = Arrays.asList(filter);
    // take a look at the current filter so we can return it
    final ClientTableState current = state();
    List<FilterCondition> currentFilter = current.getFilters();
    // try to skip work (TODO refactor this into a private method)
    if (!currentFilter.equals(newFilter)) {
        if (batchDepth > 0) {
            // when batching, just record what the user requested, but don't compute anything
            // until the batch is complete.
            workerConnection.getBatcher(this).filter(newFilter);
        } else {
            // we use the batch mechanism to handle unwinding / building table states
            batch(batcher -> {
                batcher.customColumns(current.getCustomColumns());
                batcher.filter(newFilter);
                batcher.sort(current.getSorts());
            }).catch_(logError(() -> "Failed to apply filters: " + Arrays.toString(filter)));
        }
    }
    return JsItr.slice(currentFilter);
}
Also used : JsInputTable(io.deephaven.web.client.api.input.JsInputTable) ActiveTableBinding(io.deephaven.web.client.state.ActiveTableBinding) LazyPromise.logError(io.deephaven.web.client.fu.LazyPromise.logError) JsPropertyMap(jsinterop.base.JsPropertyMap) ThenOnFulfilledCallbackFn(elemental2.promise.IThenable.ThenOnFulfilledCallbackFn) ZoomRange(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.runchartdownsamplerequest.ZoomRange) io.deephaven.web.shared.data(io.deephaven.web.shared.data) SelectDistinctRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.SelectDistinctRequest) FilterCondition(io.deephaven.web.client.api.filter.FilterCondition) JsData(io.deephaven.web.client.fu.JsData) JsLog(io.deephaven.web.client.fu.JsLog) ViewportData(io.deephaven.web.client.api.subscription.ViewportData) ClientTableState(io.deephaven.web.client.state.ClientTableState) JsArray(elemental2.core.JsArray) HasTableBinding(io.deephaven.web.client.state.HasTableBinding) Stream(java.util.stream.Stream) HasLifecycle(io.deephaven.web.client.api.lifecycle.HasLifecycle) TableSubscription(io.deephaven.web.client.api.subscription.TableSubscription) MergeResults(io.deephaven.web.client.api.subscription.ViewportData.MergeResults) AsOfJoinTablesRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.AsOfJoinTablesRequest) Global(elemental2.core.Global) JsRunnable(io.deephaven.web.shared.fu.JsRunnable) JsItr(io.deephaven.web.client.fu.JsItr) java.util(java.util) JsOptional(jsinterop.annotations.JsOptional) RemoverFn(io.deephaven.web.shared.fu.RemoverFn) NaturalJoinTablesRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.NaturalJoinTablesRequest) RunChartDownsampleRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.RunChartDownsampleRequest) ColumnData(io.deephaven.web.shared.data.columns.ColumnData) JsMethod(jsinterop.annotations.JsMethod) Promise(elemental2.promise.Promise) JsTreeTableConfig(io.deephaven.web.client.api.tree.JsTreeTableConfig) StateCache(io.deephaven.web.client.api.state.StateCache) SnapshotType(io.deephaven.web.shared.data.TableSnapshot.SnapshotType) RequestBatcher(io.deephaven.web.client.api.batch.RequestBatcher) JsProperty(jsinterop.annotations.JsProperty) Js(jsinterop.base.Js) TableAttributesDefinition(io.deephaven.web.client.api.barrage.def.TableAttributesDefinition) TableViewportSubscription(io.deephaven.web.client.api.subscription.TableViewportSubscription) JsRollupConfig(io.deephaven.web.client.api.tree.JsRollupConfig) ViewportRow(io.deephaven.web.client.api.subscription.ViewportRow) ExactJoinTablesRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.ExactJoinTablesRequest) JsTreeTable(io.deephaven.web.client.api.tree.JsTreeTable) LazyPromise(io.deephaven.web.client.fu.LazyPromise) JsProvider(io.deephaven.web.shared.fu.JsProvider) JsConsumer(io.deephaven.web.shared.fu.JsConsumer) DomGlobal(elemental2.dom.DomGlobal) CustomEventInit(elemental2.dom.CustomEventInit) NO_ROW_FORMAT_COLUMN(io.deephaven.web.client.api.subscription.ViewportData.NO_ROW_FORMAT_COLUMN) ColumnDefinition(io.deephaven.web.client.api.barrage.def.ColumnDefinition) SnapshotTableRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.SnapshotTableRequest) CrossJoinTablesRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.CrossJoinTablesRequest) FilterCondition(io.deephaven.web.client.api.filter.FilterCondition) ClientTableState(io.deephaven.web.client.state.ClientTableState) JsMethod(jsinterop.annotations.JsMethod)

Example 2 with FilterCondition

use of io.deephaven.web.client.api.filter.FilterCondition in project deephaven-core by deephaven.

the class JsTreeTable method buildQuery.

/**
 * Creates a request object based on the current state of request info. We don't presently build this ahead of time
 * and maintain it as things change, but instead read from the rest of the tree's state to decide what to build.
 *
 * Sort is always assigned, since a node could be expanded, might now have children (and the server needs to know
 * how to sort it), etc - the server will only sort individual "children" tables lazily, so this must always be
 * provided.
 *
 * Filters are sent when the filter changes, or when something else changes that will result in rebuilding one or
 * more children trees - the two cases that exist today are changing the sort, or reconnecting to the server. When
 * filters are changed, the bookkeeping is done automatically, but for other purposes the releaseAllNodes helper
 * method should be used to both release nodes and indicate that when refetched the filter may need to be applied
 * again as well.
 */
private TreeTableRequest buildQuery() {
    TreeTableRequest request = new TreeTableRequest();
    // before building, evaluate all queued operations
    if (queuedOperations != null) {
        queuedOperations.run();
        queuedOperations = null;
    }
    // if any of those operations asks for a close, just do the close and skip the rest
    if (Arrays.asList(nextRequestOps).contains(TreeTableRequest.TreeRequestOperation.Close)) {
        closed = true;
        request.setIncludedOps(new TreeTableRequest.TreeRequestOperation[] { TreeTableRequest.TreeRequestOperation.Close });
        request.setExpandedNodes(new TableDetails[0]);
        request.setSorts(new SortDescriptor[0]);
        request.setFilters(new FilterDescriptor[0]);
        request.setColumns(new BitSet());
        return request;
    }
    request.setExpandedNodes(expandedMap.values().stream().map(TreeNodeState::toTableDetails).toArray(TableDetails[]::new));
    final int hierarchicalChildrenColumnIndex = Arrays.stream(this.baseTable.getTableDef().getColumns()).filter(col -> col.getName().equals(this.baseTable.getTableDef().getAttributes().getTreeHierarchicalColumnName())).mapToInt(ColumnDefinition::getColumnIndex).findFirst().orElseThrow(() -> new IllegalStateException("TreeTable definition has no hierarchy column"));
    request.setKeyColumn(hierarchicalChildrenColumnIndex);
    // filters on child tables, only on the root table
    if (!filters.equals(nextFilters)) {
        request.setFilters(nextFilters.stream().map(FilterCondition::makeDescriptor).toArray(FilterDescriptor[]::new));
    } else {
        request.setFilters(new FilterDescriptor[0]);
    }
    // always include the sort setup, the viewport content could have changed in practically any way
    request.setSorts(nextSort.stream().map(Sort::makeDescriptor).toArray(SortDescriptor[]::new));
    BitSet columnsBitset = baseTable.makeBitset(this.columns);
    columnsBitset.set(hierarchicalChildrenColumnIndex);
    request.setColumns(columnsBitset);
    request.setViewportEnd((long) (double) lastRow);
    request.setViewportStart((long) (double) firstRow);
    request.setIncludedOps(nextRequestOps);
    nextRequestOps = new TreeTableRequest.TreeRequestOperation[0];
    return request;
}
Also used : JsRunnable(io.deephaven.web.shared.fu.JsRunnable) JsItr(io.deephaven.web.client.fu.JsItr) java.util(java.util) JsOptional(jsinterop.annotations.JsOptional) ColumnData(io.deephaven.web.shared.data.columns.ColumnData) JsMethod(jsinterop.annotations.JsMethod) Promise(elemental2.promise.Promise) Any(jsinterop.base.Any) JsProperty(jsinterop.annotations.JsProperty) Js(jsinterop.base.Js) io.deephaven.web.shared.data(io.deephaven.web.shared.data) io.deephaven.web.client.api(io.deephaven.web.client.api) ViewportRow(io.deephaven.web.client.api.subscription.ViewportRow) FilterCondition(io.deephaven.web.client.api.filter.FilterCondition) JsAggregationOperation(io.deephaven.web.client.api.tree.enums.JsAggregationOperation) LazyPromise(io.deephaven.web.client.fu.LazyPromise) JsObject(elemental2.core.JsObject) TreeTableRequest(io.deephaven.web.shared.data.treetable.TreeTableRequest) JsLog(io.deephaven.web.client.fu.JsLog) DomGlobal(elemental2.dom.DomGlobal) ViewportData(io.deephaven.web.client.api.subscription.ViewportData) ClientTableState(io.deephaven.web.client.state.ClientTableState) CustomEventInit(elemental2.dom.CustomEventInit) TreeTableResult(io.deephaven.web.shared.data.treetable.TreeTableResult) NO_ROW_FORMAT_COLUMN(io.deephaven.web.client.api.subscription.ViewportData.NO_ROW_FORMAT_COLUMN) ColumnDefinition(io.deephaven.web.client.api.barrage.def.ColumnDefinition) Key(io.deephaven.web.shared.data.treetable.Key) JsArray(elemental2.core.JsArray) HasLifecycle(io.deephaven.web.client.api.lifecycle.HasLifecycle) TreeRow(io.deephaven.web.client.api.tree.JsTreeTable.TreeViewportData.TreeRow) TableDetails(io.deephaven.web.shared.data.treetable.TableDetails) TableDetails(io.deephaven.web.shared.data.treetable.TableDetails) FilterCondition(io.deephaven.web.client.api.filter.FilterCondition) TreeTableRequest(io.deephaven.web.shared.data.treetable.TreeTableRequest) ColumnDefinition(io.deephaven.web.client.api.barrage.def.ColumnDefinition)

Example 3 with FilterCondition

use of io.deephaven.web.client.api.filter.FilterCondition in project deephaven-core by deephaven.

the class BatchBuilder method buildFilter.

private Operation buildFilter(BatchOp op, Supplier<TableReference> prevTableSupplier, Consumer<Ticket>[] lastOp) {
    FilterTableRequest value = new FilterTableRequest();
    for (FilterCondition filter : op.getFilters()) {
        if (op.getAppendTo() == null || !op.getAppendTo().hasFilter(filter)) {
            value.addFilters(filter.makeDescriptor());
        }
    }
    if (value.getFiltersList().length == 0) {
        return null;
    }
    Operation filterOp = new Operation();
    filterOp.setFilter(value);
    value.setSourceId(prevTableSupplier.get());
    lastOp[0] = value::setResultId;
    return filterOp;
}
Also used : FilterCondition(io.deephaven.web.client.api.filter.FilterCondition) Operation(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.batchtablerequest.Operation)

Aggregations

FilterCondition (io.deephaven.web.client.api.filter.FilterCondition)3 JsArray (elemental2.core.JsArray)2 CustomEventInit (elemental2.dom.CustomEventInit)2 DomGlobal (elemental2.dom.DomGlobal)2 Promise (elemental2.promise.Promise)2 ColumnDefinition (io.deephaven.web.client.api.barrage.def.ColumnDefinition)2 HasLifecycle (io.deephaven.web.client.api.lifecycle.HasLifecycle)2 ViewportData (io.deephaven.web.client.api.subscription.ViewportData)2 NO_ROW_FORMAT_COLUMN (io.deephaven.web.client.api.subscription.ViewportData.NO_ROW_FORMAT_COLUMN)2 ViewportRow (io.deephaven.web.client.api.subscription.ViewportRow)2 JsItr (io.deephaven.web.client.fu.JsItr)2 JsLog (io.deephaven.web.client.fu.JsLog)2 LazyPromise (io.deephaven.web.client.fu.LazyPromise)2 ClientTableState (io.deephaven.web.client.state.ClientTableState)2 io.deephaven.web.shared.data (io.deephaven.web.shared.data)2 ColumnData (io.deephaven.web.shared.data.columns.ColumnData)2 JsRunnable (io.deephaven.web.shared.fu.JsRunnable)2 java.util (java.util)2 JsMethod (jsinterop.annotations.JsMethod)2 JsOptional (jsinterop.annotations.JsOptional)2