Package org.apache.hadoop.io.SequenceFile

Examples of org.apache.hadoop.io.SequenceFile.Writer


  public void testJavaSerialization() throws Exception {
    Path file = new Path(System.getProperty("test.build.data",".") +
        "/test.seq");
   
    fs.delete(file, true);
    Writer writer = SequenceFile.createWriter(fs, conf, file, Long.class,
        String.class);
   
    writer.append(1L, "one");
    writer.append(2L, "two");
   
    writer.close();
   
    Reader reader = new Reader(fs, file, conf);
    assertEquals(1L, reader.next((Object) null));
    assertEquals("one", reader.getCurrentValue((Object) null));
    assertEquals(2L, reader.next((Object) null));
View Full Code Here


  /**
   *
   * Finds out the cluster directory of the vector and writes it into the specified cluster.
   */
  private void putVectorInRespectiveCluster(String clusterId, WeightedVectorWritable point) throws IOException {
    Writer writer = findWriterForVector(clusterId);
    postProcessedClusterDirectories.put(clusterId,
                                        PathDirectory.getClusterPathForClusterId(clusterPostProcessorOutput, clusterId));
    writeVectorToCluster(writer, point);
  }
View Full Code Here

  /**
   * Finds out the path in cluster where the point is supposed to be written.
   */
  private Writer findWriterForVector(String clusterId) throws IOException {
    Path clusterDirectory = PathDirectory.getClusterPathForClusterId(clusterPostProcessorOutput, clusterId);
    Writer writer = writersForClusters.get(clusterId);
    if (writer == null) {
      Path pathToWrite = new Path(clusterDirectory, new Path("part-m-0"));
      writer = new Writer(fileSystem, conf, pathToWrite, LongWritable.class, VectorWritable.class);
      writersForClusters.put(clusterId, writer);
    }
    return writer;
  }
View Full Code Here

    // store the output in a sequence file
    Path base = getTestTempDirPath("testdata");
    FileSystem fs = base.getFileSystem(conf);

    Path outputFile = new Path(base, "PartialBuilderTest.seq");
    Writer writer = SequenceFile.createWriter(fs, conf, outputFile,
        TreeID.class, MapredOutput.class);

    try {
      for (int index = 0; index < NUM_TREES; index++) {
        writer.append(keys[index], values[index]);
      }
    } finally {
      Closeables.closeQuietly(writer);
    }
View Full Code Here

    FlumeConfiguration conf = FlumeConfiguration.get();
    Path path = new Path("hdfs://localhost/testfile");
    FileSystem hdfs = path.getFileSystem(conf);
    hdfs.deleteOnExit(path);

    Writer w = SequenceFile.createWriter(hdfs, conf, path,
        WriteableEventKey.class, WriteableEvent.class);
    b.mark("hdfs_fileopen_started");

    Event e = null;
    while ((e = mem.next()) != null) {
      // writing
      w.append(new WriteableEventKey(e), new WriteableEvent(e));
    }
    w.close();
    b.mark("seqfile_hdfs_write");

    hdfs.close();
    b.done();
  }
View Full Code Here

  }

  private void createFile(File dir, String fileName, int key, int count) throws IOException {
    File file = new File(dir, fileName);

    Writer writer = SequenceFile.createWriter(FileSystem.get(job), job, new Path(file.getAbsolutePath()), Text.class, IntWritable.class);

    Text text = new Text(Integer.toString(key));
    IntWritable value = new IntWritable();

    for (int i = 0, j = 0; i < count; i++, j = j == 9 ? 0 : j + 1) {
      value.set(j);

      writer.append(text, value);
    }

    writer.close();
  }
View Full Code Here

      writer.close();
    } else {
      CustomWritable key = new CustomWritable();
      CustomWritable value = new CustomWritable();

      Writer writer = SequenceFile.createWriter(getFileSystem(), getFileSystem().getConf(), path, CustomWritable.class,
          CustomWritable.class, CompressionType.BLOCK, defaultCodec);

      for (int k = 1, v = 100 * fileNum + 1; k <= fileNum; k++, v++) {
        key.set(k);
        value.set(v);

        writer.append(key, value);
      }

      writer.close();
    }
  }
View Full Code Here

  }

  @Test
  public void partition() throws IOException {

    Writer writer = SequenceFile.createWriter(fs, job, partitionMap, Text.class, IntWritable.class);

    Text key = new Text();
    IntWritable partNum = new IntWritable();

    key.set("bucket-1");
    partNum.set(0);
    writer.append(key, partNum);

    key.set("bucket-2");
    partNum.set(0);
    writer.append(key, partNum);

    key.set("bucket-3");
    partNum.set(1);
    writer.append(key, partNum);

    key.set("bucket-4");
    partNum.set(2);
    writer.append(key, partNum);

    key.set("bucket-5");
    partNum.set(2);
    writer.append(key, partNum);

    key.set("bucket-6");
    partNum.set(2);
    writer.append(key, partNum);

    writer.close();

    job.setNumReduceTasks(3);


    partitioner.configure(job);
View Full Code Here


  @Test
  public void partitionWithFewerPartitionsThanReduceTasks() throws IOException {

    Writer writer = SequenceFile.createWriter(fs, job, partitionMap, Text.class, IntWritable.class);

    Text key = new Text();
    IntWritable partNum = new IntWritable();

    key.set("bucket-1");
    partNum.set(0);
    writer.append(key, partNum);

    key.set("bucket-2");
    partNum.set(0);
    writer.append(key, partNum);

    key.set("bucket-3");
    partNum.set(1);
    writer.append(key, partNum);

    key.set("bucket-4");
    partNum.set(2);
    writer.append(key, partNum);

    key.set("bucket-5");
    partNum.set(2);
    writer.append(key, partNum);

    key.set("bucket-6");
    partNum.set(2);
    writer.append(key, partNum);

    writer.close();

    job.setNumReduceTasks(40);


    partitioner.configure(job);
View Full Code Here

  }

  @Test
  public void noDupes() throws IOException {

    Writer writer = SequenceFile.createWriter(fs, job, partitionMap, Text.class, IntWritable.class);

    Text key = new Text();
    IntWritable value = new IntWritable();

    key.set("bucket-1");
    value.set(0);
    writer.append(key, value);

    key.set("bucket-2");
    value.set(0);
    writer.append(key, value);

    key.set("bucket-2");
    value.set(1);
    writer.append(key, value);

    writer.close();

    job.setNumReduceTasks(3);

    try {
      partitioner.configure(job);
View Full Code Here

TOP

Related Classes of org.apache.hadoop.io.SequenceFile.Writer

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.