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

split query router #1031

Merged
merged 11 commits into from
Feb 13, 2023

This file was deleted.

This file was deleted.

17 changes: 7 additions & 10 deletions src/client/components/number-range-picker/number-range-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
* limitations under the License.
*/

import { $, Dataset, ply } from "plywood";
import { Dataset } from "plywood";
import React from "react";
import { Dimension } from "../../../common/models/dimension/dimension";
import { Essence } from "../../../common/models/essence/essence";
import { Timekeeper } from "../../../common/models/timekeeper/timekeeper";
import { getNumberOfWholeDigits, isTruthy, toSignificantDigits } from "../../../common/utils/general/general";
import { clamp, classNames, getXFromEvent } from "../../utils/dom/dom";
import { ApiContext, ApiContextValue } from "../../views/cube-view/api-context";
import { Loader } from "../loader/loader";
import { QueryError } from "../query-error/query-error";
import { RangeHandle } from "../range-handle/range-handle";
Expand Down Expand Up @@ -72,6 +73,9 @@ export interface NumberRangePickerState {
}

export class NumberRangePicker extends React.Component<NumberRangePickerProps, NumberRangePickerState> {
static contextType = ApiContext;

context: ApiContextValue;
public mounted: boolean;
private picker = React.createRef<HTMLDivElement>();

Expand All @@ -87,19 +91,12 @@ export class NumberRangePicker extends React.Component<NumberRangePickerProps, N
}

fetchData(essence: Essence, timekeeper: Timekeeper, dimension: Dimension, rightBound: number): void {
const { dataCube } = essence;
const filterExpression = essence.getEffectiveFilter(timekeeper, { unfilterDimension: dimension }).toExpression(dataCube);
const $main = $("main");
const query = ply()
.apply("main", $main.filter(filterExpression))
.apply("Min", $main.min($(dimension.name)))
.apply("Max", $main.max($(dimension.name)));

const { numberFilterQuery } = this.context;
this.setState({
loading: true
});

dataCube.executor(query)
numberFilterQuery(essence, dimension)
.then(
(dataset: Dataset) => {
if (!this.mounted) return;
Expand Down
72 changes: 60 additions & 12 deletions src/client/components/pinboard-tile/pinboard-tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,32 @@ import { Set } from "immutable";
import { Dataset, Datum } from "plywood";
import React from "react";
import { Clicker } from "../../../common/models/clicker/clicker";
import { DatasetRequest, error, isError, isLoaded, isLoading, loaded, loading } from "../../../common/models/dataset-request/dataset-request";
import {
DatasetRequest,
error,
isError,
isLoaded,
isLoading,
loaded,
loading
} from "../../../common/models/dataset-request/dataset-request";
import { Dimension } from "../../../common/models/dimension/dimension";
import { Essence } from "../../../common/models/essence/essence";
import { BooleanFilterClause, StringFilterAction, StringFilterClause } from "../../../common/models/filter-clause/filter-clause";
import {
BooleanFilterClause,
StringFilterAction,
StringFilterClause
} from "../../../common/models/filter-clause/filter-clause";
import { SortOn } from "../../../common/models/sort-on/sort-on";
import { SortDirection } from "../../../common/models/sort/sort";
import { Split } from "../../../common/models/split/split";
import { Timekeeper } from "../../../common/models/timekeeper/timekeeper";
import { debounceWithPromise, Unary } from "../../../common/utils/functional/functional";
import { MAX_SEARCH_LENGTH } from "../../config/constants";
import { setDragData, setDragGhost } from "../../utils/dom/dom";
import { DragManager } from "../../utils/drag-manager/drag-manager";
import { reportError } from "../../utils/error-reporter/error-reporter";
import { ApiContext, ApiContextValue } from "../../views/cube-view/api-context";
import { Loader } from "../loader/loader";
import { QueryError } from "../query-error/query-error";
import { SearchableTile } from "../searchable-tile/searchable-tile";
Expand All @@ -37,7 +52,6 @@ import { pinboardIcons } from "./pinboard-icons";
import "./pinboard-tile.scss";
import { isClauseEditable } from "./utils/is-clause-editable";
import { isDimensionPinnable } from "./utils/is-dimension-pinnable";
import { makeQuery } from "./utils/make-query";
import { isPinnableClause, PinnableClause } from "./utils/pinnable-clause";
import { equalParams, QueryParams } from "./utils/query-params";
import { EditState, RowMode, RowModeId } from "./utils/row-mode";
Expand All @@ -60,16 +74,19 @@ export interface PinboardTileState {
}

export class PinboardTile extends React.Component<PinboardTileProps, PinboardTileState> {
static contextType = ApiContext;

context: ApiContextValue;

state: PinboardTileState = {
searchText: "",
showSearch: false,
datasetLoad: loading
};

private loadData(params: QueryParams) {
private loadData() {
this.setState({ datasetLoad: loading });
this.fetchData(params)
this.fetchData(this.constructQueryParams())
.then(loadedDataset => {
// TODO: encode it better
// null is here when we get out of order request, so we just ignore it
Expand All @@ -86,8 +103,9 @@ export class PinboardTile extends React.Component<PinboardTileProps, PinboardTil
private lastQueryParams: Partial<QueryParams> = {};

private callExecutor = (params: QueryParams): Promise<DatasetRequest | null> => {
const { essence: { timezone, dataCube } } = params;
return dataCube.executor(makeQuery(params), { timezone })
const { essence, clause, split } = params;
const { pinboardQuery } = this.context;
return pinboardQuery(essence, clause, split)
.then((dataset: Dataset) => {
// signal out of order requests with null
if (!equalParams(params, this.lastQueryParams)) return null;
Expand All @@ -104,8 +122,7 @@ export class PinboardTile extends React.Component<PinboardTileProps, PinboardTil
private debouncedCallExecutor = debounceWithPromise(this.callExecutor, 500);

componentDidMount() {
const { essence, timekeeper, dimension, sortOn } = this.props;
this.loadData({ essence, timekeeper, dimension, sortOn, searchText: "" });
this.loadData();
}

componentWillUnmount() {
Expand All @@ -114,9 +131,7 @@ export class PinboardTile extends React.Component<PinboardTileProps, PinboardTil

componentDidUpdate(previousProps: PinboardTileProps, previousState: PinboardTileState) {
if (shouldFetchData(this.props, previousProps, this.state, previousState)) {
const { essence, timekeeper, dimension, sortOn } = this.props;
const { searchText } = this.state;
this.loadData({ essence, timekeeper, dimension, sortOn, searchText });
this.loadData();
}
}

Expand All @@ -141,6 +156,39 @@ export class PinboardTile extends React.Component<PinboardTileProps, PinboardTil
this.setState({ searchText });
};

constructQueryParams(): QueryParams {
const { sortOn, essence, dimension } = this.props;
const split = new Split({
reference: dimension.name,
sort: sortOn.toSort(SortDirection.descending),
// TODO: magic number
limit: 100
});
return {
clause: this.constructSearchTextClause(),
essence,
split
};
}

constructSearchTextClause(): StringFilterClause | null {
const { dimension } = this.props;
switch (dimension.kind) {
case "boolean":
return null;
case "string":
const { name: reference } = dimension;
const { searchText } = this.state;
return new StringFilterClause({
action: StringFilterAction.CONTAINS,
reference,
values: Set.of(searchText)
});
default:
throw new Error(`Expected String or Boolean dimension kind, got ${dimension.kind}`);
}
}

private getFormatter(): Unary<Datum, string> {
const { sortOn, essence } = this.props;
const series = essence.findConcreteSeries(sortOn.key);
Expand Down
64 changes: 0 additions & 64 deletions src/client/components/pinboard-tile/utils/make-query.ts

This file was deleted.

Loading