use of com.opencsv.CSVReaderBuilder in project fql by CategoricalData.
the class InstExpCsv method start2.
/*
* @Override public boolean equals(Object obj) { return (obj instanceof
* InstExpCsv) && super.equals(obj); }
*/
/**
* Expects filenames in the map
*/
public static Map<En, List<String[]>> start2(Map<String, String> map, AqlOptions op, Schema<Ty, En, Sym, Fk, Att> sch, boolean omitCheck) throws Exception {
Character sepChar = (Character) op.getOrDefault(AqlOption.csv_field_delim_char);
Character quoteChar = (Character) op.getOrDefault(AqlOption.csv_quote_char);
Character escapeChar = (Character) op.getOrDefault(AqlOption.csv_escape_char);
final CSVParser parser = new CSVParserBuilder().withSeparator(sepChar).withQuoteChar(quoteChar).withEscapeChar(escapeChar).withFieldAsNull(CSVReaderNullFieldIndicator.EMPTY_SEPARATORS).build();
Map<En, List<String[]>> ret = new HashMap<>();
for (String k : map.keySet()) {
if (!omitCheck) {
if (!sch.ens.contains(new En(k))) {
throw new RuntimeException("Not an entity: " + k);
}
}
File file = new File(map.get(k));
FileReader fileReader = new FileReader(file);
final CSVReader reader = new CSVReaderBuilder(fileReader).withCSVParser(parser).withFieldAsNull(CSVReaderNullFieldIndicator.EMPTY_SEPARATORS).build();
List<String[]> rows = reader.readAll();
fileReader.close();
ret.put(new En(k), rows);
}
if (!omitCheck) {
for (En en : sch.ens) {
if (!ret.containsKey(en)) {
ret.put(en, new LinkedList<>(Util.singList(Util.union(sch.attsFrom(en).stream().map(Object::toString).collect(Collectors.toList()), sch.fksFrom(en).stream().map(Object::toString).collect(Collectors.toList())).toArray(new String[0]))));
}
}
}
return ret;
}
Aggregations