Package org.lilyproject.repository.bulk

Examples of org.lilyproject.repository.bulk.RecordWriter


    public int run(CommandLine cmd) throws Exception {
        BulkIngester bulkIngester =
                BulkIngester.newBulkIngester(zkConnectionString, 30000, outputRepository, outputTable, bulkMode);

        BufferedReader bufferedReader = new BufferedReader(new FileReader(inputPath));
        RecordWriter recordWriter;
        if (dryRun) {
            recordWriter = new DebugRecordWriter(System.out);
        } else {
            recordWriter = new ThreadedRecordWriter(zkConnectionString, 10, outputRepository, outputTable, bulkMode);
        }
        long start = System.currentTimeMillis();
        int numLines = 0;

        try {
            LineMapper lineMapper = new JythonLineMapper(Files.toString(new File(pythonMapperPath), Charsets.UTF_8),
                    pythonSymbol);
            LineMappingContext mappingContext = new LineMappingContext(bulkIngester, recordWriter);
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                lineMapper.mapLine(line, mappingContext);
                numLines++;
            }
        } catch (PyException pe) {
            pe.printStackTrace();    // Print the Jython-native stack trace
            log.error("Exception encountered in Python code", pe);
            return -1;
        } finally {
            bufferedReader.close();
            recordWriter.close();
        }
        float duration = (System.currentTimeMillis() - start) / 1000f;
        if (!dryRun) {
            System.out.printf("Imported %d lines as %d records in %.2f seconds\n", numLines, recordWriter.getNumRecords(),
                    duration);
        }

        return 0;
    }
View Full Code Here

TOP

Related Classes of org.lilyproject.repository.bulk.RecordWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.