Package org.apache.hadoop.io.SequenceFile

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


    assertEquals(ImmutableList.of("hello", "world"), txt);
  }

  private void createTestSequenceFile(final File seqFile) throws IOException {
    SequenceFile.Writer writer = null;
    writer = new Writer(FileSystem.getLocal(baseTmpDir.getDefaultConfiguration()),
              baseTmpDir.getDefaultConfiguration(),
              new Path(seqFile.toString()),
              IntWritable.class, Text.class);
    writer.append(new IntWritable(1), new Text("hello"));
    writer.append(new IntWritable(2), new Text("world"));
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.close(writer, false);
    }
View Full Code Here

    if (fs.exists(in))
      fs.delete(in, true);

    final NullWritable value = NullWritable.get();

    Writer centerWriter = new SequenceFile.Writer(fs, conf, center,
        VectorWritable.class, NullWritable.class);

    final SequenceFile.Writer dataWriter = SequenceFile.createWriter(fs, conf,
        in, VectorWritable.class, NullWritable.class, CompressionType.NONE);

    int i = 0;

    BufferedReader br = new BufferedReader(
        new InputStreamReader(fs.open(txtIn)));
    String line;
    while ((line = br.readLine()) != null) {
      String[] split = line.split("\t");
      DenseDoubleVector vec = new DenseDoubleVector(split.length);
      for (int j = 0; j < split.length; j++) {
        vec.set(j, Double.parseDouble(split[j]));
      }
      VectorWritable vector = new VectorWritable(vec);
      dataWriter.append(vector, value);
      if (k > i) {
          assert centerWriter != null;
          centerWriter.append(vector, value);
      } else {
        if (centerWriter != null) {
          centerWriter.close();
          centerWriter = null;
        }
      }
      i++;
    }
View Full Code Here

    FileSystem fs = base.getFileSystem(job);
    if (fs.exists(base))
      fs.delete(base, true);

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

    for (int index = 0; index < numTrees; index++) {
      writer.append(keys[index], values[index]);
    }
    writer.close();

    // load the output and make sure its valid
    TreeID[] newKeys = new TreeID[numTrees];
    Node[] newTrees = new Node[numTrees];
   
View Full Code Here

    FileSystem fs = base.getFileSystem(conf);
    if (fs.exists(base))
      fs.delete(base, true);

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

    for (int index = 0; index < numTrees; index++) {
      writer.append(keys[index], values[index]);
    }
    writer.close();

    // load the output and make sure its valid
    TreeID[] newKeys = new TreeID[numTrees];
    Node[] newTrees = new Node[numTrees];
   
View Full Code Here

    }
  }

  private void createTestSequenceFile(final File seqFile) throws IOException {
    SequenceFile.Writer writer = null;
    writer = new Writer(FileSystem.getLocal(baseTmpDir.getDefaultConfiguration()),
              baseTmpDir.getDefaultConfiguration(),
              new Path(seqFile.toString()),
              IntWritable.class, Text.class);
    writer.append(new IntWritable(1), new Text("hello"));
    writer.append(new IntWritable(2), new Text("world"));
View Full Code Here

    FlumeConfiguration conf = FlumeConfiguration.get();

    Path dstPath = new Path(p);
    FileSystem hdfs = dstPath.getFileSystem(conf);

    Writer w = SequenceFile.createWriter(hdfs, conf, dstPath,
        WriteableEventKey.class, WriteableEvent.class);

    return w;
  }
View Full Code Here

   * Writes the message to an HDFS file whose path is substituted with tags
   * drawn from the supplied event
   */
  @Override
  public void append(Event e) throws IOException, InterruptedException  {
    Writer w = writer;

    if (shouldSub) {
      String realPath = e.escapeString(path);
      w = sfWriters.get(realPath);
      if (w == null) {
        w = openWriter(realPath);
        sfWriters.put(realPath, w);
      }
    }

    Preconditions.checkState(w != null,
        "Attempted to append to a null dfs writer!");
    w.append(new WriteableEventKey(e), new WriteableEvent(e));
    super.append(e);
  }
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.