loadParagraphResult()

in zeppelin-web/src/app/tabledata/networkdata.js [30:84]


  loadParagraphResult(paragraphResult) {
    if (!paragraphResult || paragraphResult.type !== DatasetType.NETWORK) {
      console.log('Can not load paragraph result');
      return;
    }

    this.graph = JSON.parse(paragraphResult.msg.trim() || '{}');

    if (!this.graph.nodes) {
      console.log('Graph result is empty');
      return;
    }

    this.graph.edges = this.graph.edges || [];
    this.networkNodes = angular.equals({}, this.graph.labels || {})
      ? null : {count: this.graph.nodes.length, labels: this.graph.labels};
    this.networkRelationships = angular.equals([], this.graph.types || [])
      ? null : {count: this.graph.edges.length, types: this.graph.types};

    const rows = [];
    const comment = '';
    const entities = this.graph.nodes.concat(this.graph.edges);
    const baseColumnNames = [{name: 'id', index: 0, aggr: 'sum'}];
    const containsLabelField = _.find(entities, (entity) => 'label' in entity) !== undefined;
    if (this.graph.labels || this.graph.types || containsLabelField) {
      baseColumnNames.push({name: 'label', index: 1, aggr: 'sum'});
    }
    const internalFieldsToJump = ['count', 'size', 'totalCount',
      'data', 'x', 'y', 'labels', 'source', 'target'];
    const baseCols = _.map(baseColumnNames, (col) => col.name);
    let keys = _.map(entities, (elem) => Object.keys(elem.data || {}));
    keys = _.flatten(keys);
    keys = _.uniq(keys).filter((key) => baseCols.indexOf(key) === -1);
    const entityColumnNames = _.map(keys, (elem, i) => {
      return {name: elem, index: i + baseColumnNames.length, aggr: 'sum'};
    });
    const columnNames = baseColumnNames.concat(entityColumnNames);
    for (let i = 0; i < entities.length; i++) {
      const entity = entities[i];
      const col = [];
      entity.data = entity.data || {};
      for (let j = 0; j < columnNames.length; j++) {
        const name = columnNames[j].name;
        const value = name in entity && internalFieldsToJump.indexOf(name) === -1
          ? entity[name] : entity.data[name];
        const parsedValue = value === null || value === undefined ? '' : value;
        col.push(parsedValue);
      }
      rows.push(col);
    }

    this.comment = comment;
    this.columns = columnNames;
    this.rows = rows;
  }