use of com.univocity.parsers.common.ParsingContext in project mapping-benchmark by arnaudroger.
the class UnivocityCsvParserBenchmark method parseCsv.
@Benchmark
public void parseCsv(Blackhole blackhole, CsvParam csvParam) throws IOException {
CsvParserSettings settings = new CsvParserSettings();
// turning off features enabled by default
settings.setIgnoreLeadingWhitespaces(false);
settings.setIgnoreTrailingWhitespaces(false);
settings.setSkipEmptyLines(false);
settings.setColumnReorderingEnabled(false);
settings.setReadInputOnSeparateThread(false);
settings.setRowProcessor(new AbstractRowProcessor() {
@Override
public void rowProcessed(String[] row, ParsingContext context) {
blackhole.consume(row);
}
});
com.univocity.parsers.csv.CsvParser parser = new com.univocity.parsers.csv.CsvParser(settings);
try (Reader reader = csvParam.getReader()) {
parser.parse(reader);
}
}
use of com.univocity.parsers.common.ParsingContext in project QueryAnalysis by Wikidata.
the class Main method loadPropertyGroupMapping.
/**
* Loads the mapping of property to groups.
*/
private static void loadPropertyGroupMapping() {
TsvParserSettings parserSettings = new TsvParserSettings();
parserSettings.setLineSeparatorDetectionEnabled(true);
parserSettings.setHeaderExtractionEnabled(true);
parserSettings.setSkipEmptyLines(true);
parserSettings.setReadInputOnSeparateThread(true);
ObjectRowProcessor rowProcessor = new ObjectRowProcessor() {
@Override
public void rowProcessed(Object[] row, ParsingContext parsingContext) {
if (row.length <= 1) {
logger.warn("Ignoring line without tab while parsing.");
return;
}
if (row.length == 2) {
if (row[1] == null) {
return;
}
propertyGroupMapping.put(row[0].toString(), new HashSet<String>(Arrays.asList(row[1].toString().split(","))));
return;
}
logger.warn("Line with row length " + row.length + " found. Is the formatting of propertyGroupMapping.tsv correct?");
return;
}
};
parserSettings.setProcessor(rowProcessor);
TsvParser parser = new TsvParser(parserSettings);
File file = new File("propertyClassification/propertyGroupMapping.tsv");
parser.parse(file);
}
use of com.univocity.parsers.common.ParsingContext in project mapping-benchmark by arnaudroger.
the class UnivocityConcurrentCsvParserBenchmark method parseCsv.
@Benchmark
public void parseCsv(Blackhole blackhole) throws IOException {
CsvParserSettings settings = new CsvParserSettings();
// turning off features enabled by default
settings.setIgnoreLeadingWhitespaces(false);
settings.setIgnoreTrailingWhitespaces(false);
settings.setSkipEmptyLines(false);
settings.setColumnReorderingEnabled(false);
settings.setReadInputOnSeparateThread(true);
settings.setRowProcessor(new AbstractRowProcessor() {
@Override
public void rowProcessed(String[] row, ParsingContext context) {
blackhole.consume(row);
}
});
com.univocity.parsers.csv.CsvParser parser = new com.univocity.parsers.csv.CsvParser(settings);
try (Reader reader = CsvParam.getSingleThreadedReader(quotes, nbRows)) {
parser.parse(reader);
}
}
use of com.univocity.parsers.common.ParsingContext in project mapping-benchmark by arnaudroger.
the class UnivocityConcurrentCsvParserBenchmark method mapCsv.
@Benchmark
public void mapCsv(Blackhole blackhole) throws IOException {
CsvParserSettings settings = new CsvParserSettings();
// turning off features enabled by default
settings.setIgnoreLeadingWhitespaces(false);
settings.setIgnoreTrailingWhitespaces(false);
settings.setSkipEmptyLines(false);
settings.setColumnReorderingEnabled(false);
settings.setRowProcessor(new BeanProcessor<City>(City.class) {
@Override
public void beanProcessed(City bean, ParsingContext context) {
blackhole.consume(bean);
}
});
com.univocity.parsers.csv.CsvParser parser = new com.univocity.parsers.csv.CsvParser(settings);
try (Reader reader = CsvParam.getSingleThreadedReader(quotes, nbRows)) {
parser.parse(reader);
}
}
use of com.univocity.parsers.common.ParsingContext in project mapping-benchmark by arnaudroger.
the class UnivocityCsvParserBenchmark method main.
public static void main(String[] args) throws IOException {
CsvParam csvParam = new CsvParam();
csvParam.setUp();
CsvParserSettings settings = new CsvParserSettings();
// turning off features enabled by default
settings.setIgnoreLeadingWhitespaces(false);
settings.setIgnoreTrailingWhitespaces(false);
settings.setSkipEmptyLines(false);
settings.setColumnReorderingEnabled(false);
settings.setReadInputOnSeparateThread(false);
settings.setProcessor(new BeanProcessor<City>(City.class) {
@Override
public void beanProcessed(City bean, ParsingContext context) {
System.out.println(bean);
}
});
com.univocity.parsers.csv.CsvParser parser = new com.univocity.parsers.csv.CsvParser(settings);
try (Reader reader = csvParam.getReader()) {
parser.parse(reader);
}
}
Aggregations