@Test void createTableOutputColumns() { Table table = Table.create(); List<Field> outputs = Arrays.asList( new Field("double", DataType.DOUBLE), new Field("float", DataType.FLOAT), new Field("integer", DataType.INTEGER), new Field("string", DataType.STRING), new Field("boolean", DataType.BOOLEAN), new Field("date", DataType.DATE) ); TableUtils.createTableOutputColumns(table, outputs); List<String> columnNames = table.columnNames(); assertEquals(6, columnNames.size()); assertEquals( Arrays.asList("double", "float", "integer", "string", "boolean", "date"), columnNames); assertEquals(ColumnType.DOUBLE, table.column("double").type()); assertEquals(ColumnType.FLOAT, table.column("float").type()); assertEquals(ColumnType.INTEGER, table.column("integer").type()); assertEquals(ColumnType.STRING, table.column("string").type()); assertEquals(ColumnType.BOOLEAN, table.column("boolean").type()); assertEquals(ColumnType.LOCAL_DATE, table.column("date").type()); }
public static void createTableOutputColumns(Table table, List<? extends Field> fields) { int rowCount = table.rowCount(); List<String> existingCols = table.columnNames(); for (Field output : fields) { boolean exist = existingCols.contains(output.getName()); switch (output.getType()) { case FLOAT: if (exist) { if (!(table.column(output.getName()) instanceof FloatColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(FloatColumn.create(output.getName(), rowCount)); } break; case DOUBLE: if (exist) { if (!(table.column(output.getName()) instanceof DoubleColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(DoubleColumn.create(output.getName(), rowCount)); } break; case INTEGER: if (exist) { if (!(table.column(output.getName()) instanceof IntColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(IntColumn.create(output.getName(), rowCount)); } break; case LONG: if (exist) { if (!(table.column(output.getName()) instanceof LongColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(LongColumn.create(output.getName(), rowCount)); } break; case DATE: if (exist) { if (!(table.column(output.getName()) instanceof DateColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(DateColumn.create(output.getName(), rowCount)); } break; case BOOLEAN: if (exist) { if (!(table.column(output.getName()) instanceof BooleanColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(BooleanColumn.create(output.getName(), rowCount)); } break; case STRING: if (exist) { if (!(table.column(output.getName()) instanceof StringColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(StringColumn.create(output.getName(), rowCount)); } break; } } }
TableUtils { public static void createTableOutputColumns(Table table, List<? extends Field> fields) { int rowCount = table.rowCount(); List<String> existingCols = table.columnNames(); for (Field output : fields) { boolean exist = existingCols.contains(output.getName()); switch (output.getType()) { case FLOAT: if (exist) { if (!(table.column(output.getName()) instanceof FloatColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(FloatColumn.create(output.getName(), rowCount)); } break; case DOUBLE: if (exist) { if (!(table.column(output.getName()) instanceof DoubleColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(DoubleColumn.create(output.getName(), rowCount)); } break; case INTEGER: if (exist) { if (!(table.column(output.getName()) instanceof IntColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(IntColumn.create(output.getName(), rowCount)); } break; case LONG: if (exist) { if (!(table.column(output.getName()) instanceof LongColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(LongColumn.create(output.getName(), rowCount)); } break; case DATE: if (exist) { if (!(table.column(output.getName()) instanceof DateColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(DateColumn.create(output.getName(), rowCount)); } break; case BOOLEAN: if (exist) { if (!(table.column(output.getName()) instanceof BooleanColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(BooleanColumn.create(output.getName(), rowCount)); } break; case STRING: if (exist) { if (!(table.column(output.getName()) instanceof StringColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(StringColumn.create(output.getName(), rowCount)); } break; } } } }
TableUtils { public static void createTableOutputColumns(Table table, List<? extends Field> fields) { int rowCount = table.rowCount(); List<String> existingCols = table.columnNames(); for (Field output : fields) { boolean exist = existingCols.contains(output.getName()); switch (output.getType()) { case FLOAT: if (exist) { if (!(table.column(output.getName()) instanceof FloatColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(FloatColumn.create(output.getName(), rowCount)); } break; case DOUBLE: if (exist) { if (!(table.column(output.getName()) instanceof DoubleColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(DoubleColumn.create(output.getName(), rowCount)); } break; case INTEGER: if (exist) { if (!(table.column(output.getName()) instanceof IntColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(IntColumn.create(output.getName(), rowCount)); } break; case LONG: if (exist) { if (!(table.column(output.getName()) instanceof LongColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(LongColumn.create(output.getName(), rowCount)); } break; case DATE: if (exist) { if (!(table.column(output.getName()) instanceof DateColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(DateColumn.create(output.getName(), rowCount)); } break; case BOOLEAN: if (exist) { if (!(table.column(output.getName()) instanceof BooleanColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(BooleanColumn.create(output.getName(), rowCount)); } break; case STRING: if (exist) { if (!(table.column(output.getName()) instanceof StringColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(StringColumn.create(output.getName(), rowCount)); } break; } } }  }
TableUtils { public static void createTableOutputColumns(Table table, List<? extends Field> fields) { int rowCount = table.rowCount(); List<String> existingCols = table.columnNames(); for (Field output : fields) { boolean exist = existingCols.contains(output.getName()); switch (output.getType()) { case FLOAT: if (exist) { if (!(table.column(output.getName()) instanceof FloatColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(FloatColumn.create(output.getName(), rowCount)); } break; case DOUBLE: if (exist) { if (!(table.column(output.getName()) instanceof DoubleColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(DoubleColumn.create(output.getName(), rowCount)); } break; case INTEGER: if (exist) { if (!(table.column(output.getName()) instanceof IntColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(IntColumn.create(output.getName(), rowCount)); } break; case LONG: if (exist) { if (!(table.column(output.getName()) instanceof LongColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(LongColumn.create(output.getName(), rowCount)); } break; case DATE: if (exist) { if (!(table.column(output.getName()) instanceof DateColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(DateColumn.create(output.getName(), rowCount)); } break; case BOOLEAN: if (exist) { if (!(table.column(output.getName()) instanceof BooleanColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(BooleanColumn.create(output.getName(), rowCount)); } break; case STRING: if (exist) { if (!(table.column(output.getName()) instanceof StringColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(StringColumn.create(output.getName(), rowCount)); } break; } } }  static void createTableOutputColumns(Table table, List<? extends Field> fields); static Number getNumberFromRow(String name, Row row); static boolean isMissing(Row row, Column<?> column); static Optional<NumberColumn> getNumberColumn(String name, Table table); static void allFieldPresentAndCompatible(Table table, List<Field> fields); static Column<?> listToColumn(List<Object> list, Field expectedField); }
TableUtils { public static void createTableOutputColumns(Table table, List<? extends Field> fields) { int rowCount = table.rowCount(); List<String> existingCols = table.columnNames(); for (Field output : fields) { boolean exist = existingCols.contains(output.getName()); switch (output.getType()) { case FLOAT: if (exist) { if (!(table.column(output.getName()) instanceof FloatColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(FloatColumn.create(output.getName(), rowCount)); } break; case DOUBLE: if (exist) { if (!(table.column(output.getName()) instanceof DoubleColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(DoubleColumn.create(output.getName(), rowCount)); } break; case INTEGER: if (exist) { if (!(table.column(output.getName()) instanceof IntColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(IntColumn.create(output.getName(), rowCount)); } break; case LONG: if (exist) { if (!(table.column(output.getName()) instanceof LongColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(LongColumn.create(output.getName(), rowCount)); } break; case DATE: if (exist) { if (!(table.column(output.getName()) instanceof DateColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(DateColumn.create(output.getName(), rowCount)); } break; case BOOLEAN: if (exist) { if (!(table.column(output.getName()) instanceof BooleanColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(BooleanColumn.create(output.getName(), rowCount)); } break; case STRING: if (exist) { if (!(table.column(output.getName()) instanceof StringColumn)) { throw new EvaluationException("Column %s already exist with a different type"); } } else { table.addColumns(StringColumn.create(output.getName(), rowCount)); } break; } } }  static void createTableOutputColumns(Table table, List<? extends Field> fields); static Number getNumberFromRow(String name, Row row); static boolean isMissing(Row row, Column<?> column); static Optional<NumberColumn> getNumberColumn(String name, Table table); static void allFieldPresentAndCompatible(Table table, List<Field> fields); static Column<?> listToColumn(List<Object> list, Field expectedField);  }