Java Code Examples for tech.tablesaw.columns.Column#set()

The following examples show how to use tech.tablesaw.columns.Column#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileReader.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
private void addValuesToColumns(
    Table table,
    int[] columnIndexes,
    String[] nextLine,
    Map<String, AbstractColumnParser<?>> parserMap,
    int rowNumber,
    int rowIndex) {
  // append each column that we're including (not skipping)
  int cellIndex = 0;
  for (int columnIndex : columnIndexes) {
    Column<?> column = table.column(cellIndex);
    AbstractColumnParser<?> parser = parserMap.get(column.name());
    try {
      String value = nextLine[columnIndex];
      if (rowIndex >= 0) {
        column.set(rowIndex, value, parser);
      } else {
        column.appendCell(value, parser);
      }
    } catch (Exception e) {
      throw new AddCellToColumnException(
          e, columnIndex, rowNumber, table.columnNames(), nextLine);
    }
    cellIndex++;
  }
}
 
Example 2
Source File: FileReader.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
private void addValuesToColumns(
    Table table,
    int[] columnIndexes,
    String[] nextLine,
    Map<String, AbstractColumnParser<?>> parserMap,
    int rowNumber,
    int rowIndex) {
  // append each column that we're including (not skipping)
  int cellIndex = 0;
  for (int columnIndex : columnIndexes) {
    Column<?> column = table.column(cellIndex);
    AbstractColumnParser<?> parser = parserMap.get(column.name());
    try {
      String value = nextLine[columnIndex];
      if (rowIndex >= 0) {
        column.set(rowIndex, value, parser);
      } else {
        column.appendCell(value, parser);
      }
    } catch (Exception e) {
      throw new AddCellToColumnException(
          e, columnIndex, rowNumber, table.columnNames(), nextLine);
    }
    cellIndex++;
  }
}
 
Example 3
Source File: AnalyticQueryEngine.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
/**
 * Execute all numbering functions for the given slice setting values in the appropriate
 * destination column.
 */
@SuppressWarnings({"unchecked", "rawtypes"})
private void processNumberingFunctions(TableSlice slice) {
  for (String toColumn : query.getArgumentList().getNumberingFunctions().keySet()) {
    if (rowComparator == null) {
      throw new IllegalArgumentException("Cannot use Numbering Function without OrderBy");
    }
    FunctionCall<NumberingFunctions> functionCall =
        query.getArgumentList().getNumberingFunctions().get(toColumn);
    NumberingFunctions numberingFunctions = functionCall.getFunction();
    NumberingFunction function = numberingFunctions.getImplementation();
    Column<Integer> destinationColumn =
        (Column<Integer>) destination.column(functionCall.getDestinationColumnName());

    int prevRowNumber = -1;
    // Slice has already been ordered.
    for (Row row : slice) {
      if (row.getRowNumber() == 0) {
        function.addNextRow();
      } else {
        // Consecutive rows are equal.
        if (rowComparator.compare(
                slice.mappedRowNumber(prevRowNumber), slice.mappedRowNumber(row.getRowNumber()))
            == 0) {
          function.addEqualRow();
        } else {
          // Consecutive rows are not equal.
          function.addNextRow();
        }
      }
      prevRowNumber = row.getRowNumber();
      // Set the row number in the destination that corresponds to the row in the view.
      destinationColumn.set(slice.mappedRowNumber(row.getRowNumber()), function.getValue());
    }
  }
}
 
Example 4
Source File: Interpolator.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
/** Fills missing values with the next non-missing value */
public Column<T> backfill() {
  Column<T> result = col.copy();
  T lastVal = null;
  for (int i = col.size() - 1; i >= 0; i--) {
    if (col.isMissing(i)) {
      if (lastVal != null) {
        result.set(i, lastVal);
      }
    } else {
      lastVal = col.get(i);
    }
  }
  return result;
}
 
Example 5
Source File: Interpolator.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
/** Fills missing values with the last non-missing value */
public Column<T> frontfill() {
  Column<T> result = col.copy();
  T lastVal = null;
  for (int i = 0; i < col.size(); i++) {
    if (col.isMissing(i)) {
      if (lastVal != null) {
        result.set(i, lastVal);
      }
    } else {
      lastVal = col.get(i);
    }
  }
  return result;
}
 
Example 6
Source File: AnalyticQueryEngine.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
/**
 * Execute all numbering functions for the given slice setting values in the appropriate
 * destination column.
 */
@SuppressWarnings({"unchecked", "rawtypes"})
private void processNumberingFunctions(TableSlice slice) {
  for (String toColumn : query.getArgumentList().getNumberingFunctions().keySet()) {
    if (rowComparator == null) {
      throw new IllegalArgumentException("Cannot use Numbering Function without OrderBy");
    }
    FunctionCall<NumberingFunctions> functionCall =
        query.getArgumentList().getNumberingFunctions().get(toColumn);
    NumberingFunctions numberingFunctions = functionCall.getFunction();
    NumberingFunction function = numberingFunctions.getImplementation();
    Column<Integer> destinationColumn =
        (Column<Integer>) destination.column(functionCall.getDestinationColumnName());

    int prevRowNumber = -1;
    // Slice has already been ordered.
    for (Row row : slice) {
      if (row.getRowNumber() == 0) {
        function.addNextRow();
      } else {
        // Consecutive rows are equal.
        if (rowComparator.compare(
                slice.mappedRowNumber(prevRowNumber), slice.mappedRowNumber(row.getRowNumber()))
            == 0) {
          function.addEqualRow();
        } else {
          // Consecutive rows are not equal.
          function.addNextRow();
        }
      }
      prevRowNumber = row.getRowNumber();
      // Set the row number in the destination that corresponds to the row in the view.
      destinationColumn.set(slice.mappedRowNumber(row.getRowNumber()), function.getValue());
    }
  }
}
 
Example 7
Source File: Interpolator.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
/** Fills missing values with the next non-missing value */
public Column<T> backfill() {
  Column<T> result = col.copy();
  T lastVal = null;
  for (int i = col.size() - 1; i >= 0; i--) {
    if (col.isMissing(i)) {
      if (lastVal != null) {
        result.set(i, lastVal);
      }
    } else {
      lastVal = col.get(i);
    }
  }
  return result;
}
 
Example 8
Source File: Interpolator.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
/** Fills missing values with the last non-missing value */
public Column<T> frontfill() {
  Column<T> result = col.copy();
  T lastVal = null;
  for (int i = 0; i < col.size(); i++) {
    if (col.isMissing(i)) {
      if (lastVal != null) {
        result.set(i, lastVal);
      }
    } else {
      lastVal = col.get(i);
    }
  }
  return result;
}