Examples of RecordWriter


Examples of org.apache.hadoop.record.RecordWriter

    public void testBinary() {
        File tmpfile;
        try {
            tmpfile = File.createTempFile("hadooprec", ".dat");
            FileOutputStream ostream = new FileOutputStream(tmpfile);
            RecordWriter out = new RecordWriter(ostream, "binary");
            RecRecord1 r1 = new RecRecord1();
            r1.setBoolVal(true);
            r1.setByteVal((byte)0x66);
            r1.setFloatVal(3.145F);
            r1.setDoubleVal(1.5234);
            r1.setIntVal(4567);
            r1.setLongVal(0x5a5a5a5a5a5aL);
            r1.setStringVal(new Text("random text"));
            r1.setBufferVal(new ByteArrayOutputStream(20));
            r1.setVectorVal(new ArrayList());
            r1.setMapVal(new TreeMap());
            RecRecord0 r0 = new RecRecord0();
            r0.setStringVal(new Text("other random text"));
            r1.setRecordVal(r0);
            out.write(r1);
            ostream.close();
            FileInputStream istream = new FileInputStream(tmpfile);
            RecordReader in = new RecordReader(istream, "binary");
            RecRecord1 r2 = new RecRecord1();
            in.read(r2);
View Full Code Here

Examples of org.apache.hadoop.record.RecordWriter

    public void testCsv() {
        File tmpfile;
        try {
            tmpfile = File.createTempFile("hadooprec", ".txt");
            FileOutputStream ostream = new FileOutputStream(tmpfile);
            RecordWriter out = new RecordWriter(ostream, "csv");
            RecRecord1 r1 = new RecRecord1();
            r1.setBoolVal(true);
            r1.setByteVal((byte)0x66);
            r1.setFloatVal(3.145F);
            r1.setDoubleVal(1.5234);
            r1.setIntVal(4567);
            r1.setLongVal(0x5a5a5a5a5a5aL);
            r1.setStringVal(new Text("random text"));
            r1.setBufferVal(new ByteArrayOutputStream(20));
            r1.setVectorVal(new ArrayList());
            r1.setMapVal(new TreeMap());
            RecRecord0 r0 = new RecRecord0();
            r0.setStringVal(new Text("other random text"));
            r1.setRecordVal(r0);
            out.write(r1);
            ostream.close();
            FileInputStream istream = new FileInputStream(tmpfile);
            RecordReader in = new RecordReader(istream, "csv");
            RecRecord1 r2 = new RecRecord1();
            in.read(r2);
View Full Code Here

Examples of org.apache.hadoop.record.RecordWriter

    public void testXml() {
        File tmpfile;
        try {
            tmpfile = File.createTempFile("hadooprec", ".xml");
            FileOutputStream ostream = new FileOutputStream(tmpfile);
            RecordWriter out = new RecordWriter(ostream, "xml");
            RecRecord1 r1 = new RecRecord1();
            r1.setBoolVal(true);
            r1.setByteVal((byte)0x66);
            r1.setFloatVal(3.145F);
            r1.setDoubleVal(1.5234);
            r1.setIntVal(4567);
            r1.setLongVal(0x5a5a5a5a5a5aL);
            r1.setStringVal(new Text("ran\002dom &lt; %text<&more"));
            r1.setBufferVal(new ByteArrayOutputStream(20));
            r1.setVectorVal(new ArrayList());
            r1.setMapVal(new TreeMap());
            RecRecord0 r0 = new RecRecord0();
            r0.setStringVal(new Text("other %rando\007m &amp; >&more text"));
            r1.setRecordVal(r0);
            out.write(r1);
            ostream.close();
            FileInputStream istream = new FileInputStream(tmpfile);
            RecordReader in = new RecordReader(istream, "xml");
            RecRecord1 r2 = new RecRecord1();
            in.read(r2);
View Full Code Here

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
Copyright © 2018 www.massapi.com. 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.