in common/src/main/java/org/opensearch/ml/common/dataframe/DataFrameBuilder.java [66:104]
public DataFrame load(final ColumnMeta[] columnMetas, final List<Map<String, Object>> input){
if(columnMetas == null || columnMetas.length == 0) {
throw new IllegalArgumentException("columnMetas array is null or empty");
}
if(input == null || input.isEmpty()) {
throw new IllegalArgumentException("input data list is null or empty");
}
int columnSize = columnMetas.length;
Map<String, Integer> columnsMap = new HashMap<>();
for(int i = 0; i < columnSize; i++) {
columnsMap.put(columnMetas[i].getName(), i);
}
List<Row> rows = input.stream().map(item -> {
Row row = new Row(columnSize);
if(item.size() != columnSize) {
throw new IllegalArgumentException("input item map size is different in the map");
}
for(Map.Entry<String, Object> entry : item.entrySet()) {
if(!columnsMap.containsKey(entry.getKey())) {
throw new IllegalArgumentException("field of input item doesn't exist in columns, filed:" + entry.getKey());
}
String columnName = entry.getKey();
int index = columnsMap.get(columnName);
ColumnType columnType = columnMetas[index].getColumnType();
ColumnValue value = ColumnValueBuilder.build(entry.getValue());
if(columnType != value.columnType()) {
throw new IllegalArgumentException("the same field has different data type");
}
row.setValue(index, value);
}
return row;
}).collect(Collectors.toList());
return new DefaultDataFrame(columnMetas, rows);
}