How to use the plywood.r function in plywood

To help you get started, we’ve selected a few plywood examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geo-opensource / pivot / src / client / components / dimension-tile / dimension-tile.tsx View on Github external
var filter = essence.getEffectiveFilter(timekeeper);
    // don't remove filter if time
    if (unfolded && dataCube.isMandatoryFilter(dimension.expression)) {
      filter = filter.remove(dimension.expression);
    }

    filter = filter.setExclusionforDimension(false, dimension);

    var filterExpression = filter.toExpression();

    if (!unfolded && colors && colors.dimension === dimension.name && colors.values) {
      filterExpression = filterExpression.and(dimension.expression.in(colors.toSet()));
    }

    if (searchText) {
      filterExpression = filterExpression.and(dimension.expression.contains(r(searchText), 'ignoreCase'));
    }

    var query: any = $('main')
      .filter(filterExpression);

    var sortExpression: Expression = null;

    if (dimension.canBucketByDefault()) {
      const dimensionExpression = dimension.expression as RefExpression;
      const attributeName = dimensionExpression.name;

      const filterSelection: FilterSelection = essence.filter.getSelection(dimensionExpression);

      if (!selectedGranularity) {
        if (filterSelection) {
          var range = dimension.kind === 'time' ? essence.evaluateSelection(filterSelection as Expression, timekeeper) : (filterSelection as Expression).getLiteralValue().extent();
github allegro / turnilo / src / common / utils / query / selectable-string-filter-query.ts View on Github external
export function stringFilterOptionsQuery({ essence, timekeeper, limit, dimension, searchText }: QueryParams): Expression {
  const { dataCube } = essence;
  const nativeCount = dataCube.getMeasure("count");
  const $main = $("main");
  const measureExpression = nativeCount ? nativeCount.expression : $main.count();

  const filter = essence.getEffectiveFilter(timekeeper, { unfilterDimension: dimension }).toExpression(dataCube);

  const filterWithSearch = searchText ? filter.and(dimension.expression.contains(r(searchText), "ignoreCase")) : filter;

  return $main
    .filter(filterWithSearch)
    .split(dimension.expression, dimension.name)
    .apply("MEASURE", measureExpression)
    .sort($("MEASURE"), SortExpression.DESCENDING)
    .limit(limit);
}
github allegro / turnilo / src / client / components / menu-table / menu-table.tsx View on Github external
fetchData(essence: Essence, dimension: Dimension): void {
    var { searchText } = this.state;
    var { dataSource } = essence;
    var nativeCount = dataSource.getMeasure('count');
    var measureExpression = nativeCount ? nativeCount.expression : $('main').count();

    var filterExpression = essence.getEffectiveFilter(null, dimension).toExpression();

    if (searchText) {
      filterExpression = filterExpression.and(dimension.expression.contains(r(searchText), 'ignoreCase'));
    }

    var query = $('main')
      .filter(filterExpression)
      .split(dimension.expression, SEGMENT)
      .apply('MEASURE', measureExpression)
      .sort($('MEASURE'), SortAction.DESCENDING)
      .limit(TOP_N + 1);

    this.setState({
      loading: true,
      fetchQueued: false
    });
    dataSource.executor(query)
      .then(
        (dataset) => {
github allegro / turnilo / src / client / components / dimension-tile / dimension-tile.tsx View on Github external
if (unfolded && dimension !== essence.getTimeDimension()) {
      filter = filter.removeClause(dimension.name);
    }

    filter = filter.setExclusionForDimension(false, dimension);

    let filterExpression = filter.toExpression(dataCube);

    const shouldFoldRows = !unfolded && foldable && colors && colors.dimension === dimension.name && colors.values;

    if (shouldFoldRows) {
      filterExpression = filterExpression.and(dimension.expression.in(colors.toSet()));
    }

    if (searchText) {
      filterExpression = filterExpression.and(dimension.expression.contains(r(searchText), "ignoreCase"));
    }

    let query: any = $("main")
      .filter(filterExpression);

    let sortExpression: Expression = null;

    if (dimension.canBucketByDefault()) {

      if (!selectedGranularity) {
        selectedGranularity = this.bucketForDimension(dimension);
      }

      this.setState({ selectedGranularity });

      query = query.split($(dimension.name).performAction(bucketToAction(selectedGranularity)), dimension.name);
github allegro / turnilo / src / common / models / filter-clause / filter-clause.ts View on Github external
case StringFilterAction.CONTAINS:
          stringExp = expression.contains(r(values.first()));
          break;
        case StringFilterAction.IN:
          stringExp = expression.overlap(r(values.toArray()));
          break;
        case StringFilterAction.MATCH:
          stringExp = expression.match(values.first());
          break;
      }
      return not ? stringExp.not() : stringExp;
    }
    case FilterTypes.FIXED_TIME: {
      const values = (clause as FixedTimeFilterClause).values.toArray();
      const elements = values.map(value => new TimeRange(value));
      return expression.overlap(r(new PlywoodSet({ elements, setType: "TIME_RANGE" })));
    }
    case FilterTypes.RELATIVE_TIME: {
      throw new Error("Can't call toExpression on RelativeFilterClause. Evaluate clause first");
    }
  }
}
github geo-opensource / pivot / src / client / components / preview-string-filter-menu / preview-string-filter-menu.tsx View on Github external
constructFilter(): Filter {
    var { dimension, filterMode, onClauseChange, searchText } = this.props;
    var { expression } = dimension;

    var clause: FilterClause = null;
    if (searchText) {
      if (filterMode === Filter.REGEX) {
        clause = new FilterClause({
          expression,
          selection: searchText,
          action: 'match'
        });
      } else if (filterMode === Filter.CONTAINS) {
        clause = new FilterClause({
          expression,
          selection: r(searchText),
          action: 'contains'
        });
      }
    }

    return onClauseChange(clause);
  }
github allegro / turnilo / src / common / models / filter-clause / filter-clause.ts View on Github external
export function toExpression(clause: FilterClause, { expression }: Dimension): Expression {
  const { type } = clause;
  switch (type) {
    case FilterTypes.BOOLEAN: {
      const { not, values } = clause as BooleanFilterClause;
      const boolExp = expression.overlap(r(values.toArray()));
      return not ? boolExp.not() : boolExp;
    }
    case FilterTypes.NUMBER: {
      const { not, values } = clause as NumberFilterClause;
      const elements = values.toArray().map(range => new PlywoodNumberRange(range));
      const set = new PlywoodSet({ elements, setType: "NUMBER_RANGE" });
      const numExp = expression.overlap(r(set));
      return not ? numExp.not() : numExp;
    }
    case FilterTypes.STRING: {
      const { not, action, values } = clause as StringFilterClause;
      let stringExp: Expression = null;
      switch (action) {
        case StringFilterAction.CONTAINS:
          stringExp = expression.contains(r(values.first()));
          break;