Search in sources :

Example 11 with Writer

use of org.apache.hadoop.io.file.tfile.TFile.Writer in project hadoop by apache.

the class TestTFileComparator2 method testSortedLongWritable.

@Test
public void testSortedLongWritable() throws IOException {
    Configuration conf = new Configuration();
    Path path = new Path(ROOT, name);
    FileSystem fs = path.getFileSystem(conf);
    FSDataOutputStream out = fs.create(path);
    try {
        TFile.Writer writer = new Writer(out, BLOCK_SIZE, "gz", jClassLongWritableComparator, conf);
        try {
            LongWritable key = new LongWritable(0);
            for (long i = 0; i < NENTRY; ++i) {
                key.set(cube(i - NENTRY / 2));
                DataOutputStream dos = writer.prepareAppendKey(-1);
                try {
                    key.write(dos);
                } finally {
                    dos.close();
                }
                dos = writer.prepareAppendValue(-1);
                try {
                    dos.write(buildValue(i).getBytes());
                } finally {
                    dos.close();
                }
            }
        } finally {
            writer.close();
        }
    } finally {
        out.close();
    }
    FSDataInputStream in = fs.open(path);
    try {
        TFile.Reader reader = new TFile.Reader(in, fs.getFileStatus(path).getLen(), conf);
        try {
            TFile.Reader.Scanner scanner = reader.createScanner();
            long i = 0;
            BytesWritable value = new BytesWritable();
            for (; !scanner.atEnd(); scanner.advance()) {
                scanner.entry().getValue(value);
                assertEquals(buildValue(i), new String(value.getBytes(), 0, value.getLength()));
                ++i;
            }
        } finally {
            reader.close();
        }
    } finally {
        in.close();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) Writer(org.apache.hadoop.io.file.tfile.TFile.Writer) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) DataOutputStream(java.io.DataOutputStream) BytesWritable(org.apache.hadoop.io.BytesWritable) FileSystem(org.apache.hadoop.fs.FileSystem) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) LongWritable(org.apache.hadoop.io.LongWritable) Writer(org.apache.hadoop.io.file.tfile.TFile.Writer) Test(org.junit.Test)

Example 12 with Writer

use of org.apache.hadoop.io.file.tfile.TFile.Writer in project hadoop by apache.

the class TestTFileComparators method testFailureBadComparatorNames.

// bad comparator format
@Test
public void testFailureBadComparatorNames() throws IOException {
    try {
        writer = new Writer(out, BLOCK_SIZE, compression, "badcmp", conf);
        Assert.fail("Failed to catch unsupported comparator names");
    } catch (Exception e) {
        // noop, expecting exceptions
        e.printStackTrace();
    }
}
Also used : Writer(org.apache.hadoop.io.file.tfile.TFile.Writer) IOException(java.io.IOException) Test(org.junit.Test)

Example 13 with Writer

use of org.apache.hadoop.io.file.tfile.TFile.Writer in project hadoop by apache.

the class TestTFileComparators method testFailureBadJClassNames.

// jclass that doesn't exist
@Test
public void testFailureBadJClassNames() throws IOException {
    try {
        writer = new Writer(out, BLOCK_SIZE, compression, "jclass: some.non.existence.clazz", conf);
        Assert.fail("Failed to catch unsupported comparator names");
    } catch (Exception e) {
        // noop, expecting exceptions
        e.printStackTrace();
    }
}
Also used : Writer(org.apache.hadoop.io.file.tfile.TFile.Writer) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 with Writer

use of org.apache.hadoop.io.file.tfile.TFile.Writer in project hadoop by apache.

the class TestTFileStreams method setUp.

@Before
public void setUp() throws IOException {
    conf = new Configuration();
    path = new Path(ROOT, outputFile);
    fs = path.getFileSystem(conf);
    out = fs.create(path);
    writer = new Writer(out, BLOCK_SIZE, compression, comparator, conf);
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) Writer(org.apache.hadoop.io.file.tfile.TFile.Writer) Before(org.junit.Before)

Aggregations

Writer (org.apache.hadoop.io.file.tfile.TFile.Writer)14 Path (org.apache.hadoop.fs.Path)8 Test (org.junit.Test)7 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)6 IOException (java.io.IOException)5 Configuration (org.apache.hadoop.conf.Configuration)4 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)4 Reader (org.apache.hadoop.io.file.tfile.TFile.Reader)3 Before (org.junit.Before)3 EOFException (java.io.EOFException)2 BytesWritable (org.apache.hadoop.io.BytesWritable)2 Scanner (org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner)2 DataOutputStream (java.io.DataOutputStream)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 LongWritable (org.apache.hadoop.io.LongWritable)1