How to use plywood - 10 common examples

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 implydata / plyql / src / cli.ts View on Github external
case 'json':
              outputStr = JSON.stringify(data, null, 2);
              break;

            case 'csv':
              data = Dataset.fromJS(data.toJS()); // Temp hack
              outputStr = data.toCSV();
              break;

            case 'tsv':
              data = Dataset.fromJS(data.toJS()); // Temp hack
              outputStr = data.toTSV();
              break;

            case 'flat':
              data = Dataset.fromJS(data.toJS()); // Temp hack
              outputStr = JSON.stringify(data.flatten(), null, 2);
              break;

            default:
              outputStr = 'Unknown output type';
              break;
          }
          console.log(outputStr);
        },
        (err: Error) => {
github implydata / plyql / src / cli.ts View on Github external
(data: Dataset) => {
          var outputStr: string;
          switch (output) {
            case 'json':
              outputStr = JSON.stringify(data, null, 2);
              break;

            case 'csv':
              data = Dataset.fromJS(data.toJS()); // Temp hack
              outputStr = data.toCSV();
              break;

            case 'tsv':
              data = Dataset.fromJS(data.toJS()); // Temp hack
              outputStr = data.toTSV();
              break;

            case 'flat':
              data = Dataset.fromJS(data.toJS()); // Temp hack
              outputStr = JSON.stringify(data.flatten(), null, 2);
              break;

            default:
              outputStr = 'Unknown output type';
              break;
          }
          console.log(outputStr);
        },
        (err: Error) => {
github allegro / turnilo / src / common / models / series / quantile-concrete-series.mocha.ts View on Github external
it("should throw if expression is not a quantile expression", () => {
      const expression = Expression.parse("$main.count()");
      // @ts-ignore: access protected property
      expect(() => quantileConcreteSeries.applyExpression(expression, "name", 0)).throws();
    });
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 hortonworks / streamline / pivot / src / client / applications / pivot-application / pivot-application.tsx View on Github external
getSelectedItemFromHash(items: (DataCube | Collection)[], hash: string, viewType: ViewType): DataCube | Collection {
    // can change header from hash
    var parts = this.parseHash(hash);
    var itemName = parts[viewType === COLLECTION ? 1 : 0];

    return findByName(items, itemName);
  }
github geo-opensource / pivot / src / client / applications / pivot-application / pivot-application.tsx View on Github external
getSelectedItemFromHash(items: (DataCube | Collection)[], hash: string, viewType: ViewType): DataCube | Collection {
    // can change header from hash
    var parts = this.parseHash(hash);
    var itemName = parts[viewType === COLLECTION ? 1 : 0];

    return findByName(items, itemName);
  }
github allegro / turnilo / src / client / visualizations / line-chart / line-chart.tsx View on Github external
floorRange(dragRange: PlywoodRange): PlywoodRange | null {
    const { essence } = this.props;
    const { splits, timezone } = essence;
    const continuousSplit = splits.splits.last();
    if (!continuousSplit.bucket) return dragRange; // temp solution for non-bucketed reaching here

    if (TimeRange.isTimeRange(dragRange)) {
      const duration = continuousSplit.bucket as Duration;
      return TimeRange.fromJS({
        start: duration.floor(dragRange.start, timezone),
        end: duration.shift(duration.floor(dragRange.end, timezone), timezone, 1)
      });
    }
    if (NumberRange.isNumberRange(dragRange)) {
      const bucketSize = continuousSplit.bucket as number;
      const startFloored = roundTo((dragRange as NumberRange).start, bucketSize);
      let endFloored = roundTo((dragRange as NumberRange).end, bucketSize);

      if (endFloored - startFloored < bucketSize) {
        endFloored += bucketSize;
      }

      return NumberRange.fromJS({
        start: startFloored,
        end: endFloored
github allegro / turnilo / src / client / components / date-range-picker / date-range-picker.tsx View on Github external
calculateHoverTimeRange(mouseEnteredDay: Date) {
    const { startTime, endTime } = this.props;
    let hoverTimeRange: TimeRange = null;
    if (startTime && !endTime) {
      let start = startTime;
      let end = mouseEnteredDay;
      // if mousing over backwards, set end to old start time
      if (mouseEnteredDay < startTime) {
        start = mouseEnteredDay;
        end = startTime;
      }
      hoverTimeRange = new TimeRange({ start, end, bounds: "[]" });
    }

    this.setState({ hoverTimeRange });
  }
github implydata / plyql / src / plyql-json-server.ts View on Github external
createJSONServer(port, (parameters: JSONParameters, res: any) => {
    let { sql, expression } = parameters;

    let resultPromise: Promise;

    if (expression) {
      let ex: Expression;
      try {
        ex = Expression.fromJSLoose(expression);
      } catch (e) {
        res.status(400).send({ error: e.message });
        return;
      }

      resultPromise = executePlywood(ex, context, timezone);
    } else {
      let sqlParse: SQLParse;
      try {
        sqlParse = Expression.parseSQL(sql);
      } catch (e) {
        res.status(400).send({ error: e.message });
        return;
      }

      if (sqlParse.verb && sqlParse.verb !== 'SELECT') { // DESCRIBE + SHOW get re-written
github allegro / turnilo / src / server / routes / query / query.ts View on Github external
function makeExternal(dataSource: any): External {
  var attributes: AttributeJSs = {};

  // Right here we have the classic mega hack.
  for (var dimension of dataSource.dimensions) {
    attributes[dimension.name] = { type: dimension.type || 'STRING' };
  }

  for (var measure of dataSource.measures) {
    var expression = measure.expression ? Expression.fromJSLoose(measure.expression) : $(measure.name);
    var freeReferences = expression.getFreeReferences();
    for (var freeReference of freeReferences) {
      if (freeReference === 'main') continue;
      if (JSON.stringify(expression).indexOf('countDistinct') !== -1) {
        attributes[freeReference] = { special: 'unique' };
      } else {
        attributes[freeReference] = { type: 'NUMBER' };
      }
    }
  }
  // Mega hack ends here

  return External.fromJS({
    engine: 'druid',
    dataSource: dataSource.source,
    timeAttribute: dataSource.timeAttribute,