Search in sources :

Example 6 with ParsingContext

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);
    }
}
Also used : ParsingContext(com.univocity.parsers.common.ParsingContext) AbstractRowProcessor(com.univocity.parsers.common.processor.AbstractRowProcessor) Reader(java.io.Reader) CsvParserSettings(com.univocity.parsers.csv.CsvParserSettings) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 7 with ParsingContext

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);
}
Also used : ParsingContext(com.univocity.parsers.common.ParsingContext) TsvParserSettings(com.univocity.parsers.tsv.TsvParserSettings) ObjectRowProcessor(com.univocity.parsers.common.processor.ObjectRowProcessor) TsvParser(com.univocity.parsers.tsv.TsvParser)

Example 8 with ParsingContext

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);
    }
}
Also used : ParsingContext(com.univocity.parsers.common.ParsingContext) AbstractRowProcessor(com.univocity.parsers.common.processor.AbstractRowProcessor) Reader(java.io.Reader) CsvParserSettings(com.univocity.parsers.csv.CsvParserSettings) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 9 with ParsingContext

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);
    }
}
Also used : CsvParserSettings(com.univocity.parsers.csv.CsvParserSettings) ParsingContext(com.univocity.parsers.common.ParsingContext) Reader(java.io.Reader) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 10 with ParsingContext

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);
    }
}
Also used : ParsingContext(com.univocity.parsers.common.ParsingContext) Reader(java.io.Reader) CsvParam(org.simpleflatmapper.param.CsvParam) CsvParserSettings(com.univocity.parsers.csv.CsvParserSettings)

Aggregations

ParsingContext (com.univocity.parsers.common.ParsingContext)10 ObjectRowProcessor (com.univocity.parsers.common.processor.ObjectRowProcessor)5 CsvParserSettings (com.univocity.parsers.csv.CsvParserSettings)5 TsvParser (com.univocity.parsers.tsv.TsvParser)5 TsvParserSettings (com.univocity.parsers.tsv.TsvParserSettings)5 Reader (java.io.Reader)5 Benchmark (org.openjdk.jmh.annotations.Benchmark)4 AbstractRowProcessor (com.univocity.parsers.common.processor.AbstractRowProcessor)2 Path (java.nio.file.Path)1 Entry (java.util.Map.Entry)1 ParsedQuery (org.openrdf.query.parser.ParsedQuery)1 CsvParam (org.simpleflatmapper.param.CsvParam)1 OpenRDFQueryHandler (query.OpenRDFQueryHandler)1 QueryHandler (query.QueryHandler)1