List of usage examples for org.apache.hadoop.fs Path Path
public Path(Path parent, Path child)
From source file:alluxio.client.hadoop.DFSIOIntegrationTest.java
License:Apache License
@Nullable private Path getReduceFilePath(TestType testType) { switch (testType) { case TEST_TYPE_WRITE: return new Path(getWriteDir(mConfig), "part-00000"); case TEST_TYPE_APPEND: return new Path(getAppendDir(mConfig), "part-00000"); case TEST_TYPE_READ: return new Path(getReadDir(mConfig), "part-00000"); case TEST_TYPE_READ_RANDOM: case TEST_TYPE_READ_BACKWARD: case TEST_TYPE_READ_SKIP: return new Path(getRandomReadDir(mConfig), "part-00000"); default:// ww w . j ava 2s .c om } return null; }
From source file:alluxio.hadoop.AbstractFileSystem.java
License:Apache License
@Override public void setWorkingDirectory(Path path) { LOG.info("setWorkingDirectory({})", path); if (path.isAbsolute()) { mWorkingDir = path;// w ww . j a v a 2 s. c o m } else { mWorkingDir = new Path(mWorkingDir, path); } }
From source file:alluxio.hadoop.fs.DFSIOIntegrationTest.java
License:Apache License
private Path getReduceFilePath(TestType testType) { switch (testType) { case TEST_TYPE_WRITE: return new Path(getWriteDir(mConfig), "part-00000"); case TEST_TYPE_APPEND: return new Path(getAppendDir(mConfig), "part-00000"); case TEST_TYPE_READ: return new Path(getReadDir(mConfig), "part-00000"); case TEST_TYPE_READ_RANDOM: case TEST_TYPE_READ_BACKWARD: case TEST_TYPE_READ_SKIP: return new Path(getRandomReadDir(mConfig), "part-00000"); default://from ww w. j a va 2s.c o m } return null; }
From source file:at.illecker.hadoop.rootbeer.examples.matrixmultiplication.DistributedRowMatrix.java
License:Apache License
@Override public Iterator<MatrixSlice> iterateAll() { try {/*from w w w . j av a2 s . c om*/ Path pathPattern = rowPath; if (FileSystem.get(conf).getFileStatus(rowPath).isDir()) { pathPattern = new Path(rowPath, "*"); } return Iterators.transform( new SequenceFileDirIterator<IntWritable, VectorWritable>(pathPattern, PathType.GLOB, PathFilters.logsCRCFilter(), null, true, conf), new Function<Pair<IntWritable, VectorWritable>, MatrixSlice>() { @Override public MatrixSlice apply(Pair<IntWritable, VectorWritable> from) { return new MatrixSlice(from.getSecond().get(), from.getFirst().get()); } }); } catch (IOException ioe) { throw new IllegalStateException(ioe); } }
From source file:at.illecker.hadoop.rootbeer.examples.matrixmultiplication.DistributedRowMatrix.java
License:Apache License
/** * Returns the column-wise mean of a DistributedRowMatrix * //www. j av a 2 s . c om * @param vectorClass desired class for the column-wise mean vector e.g. * RandomAccessSparseVector, DenseVector * @return Vector containing the column-wise mean of this */ public Vector columnMeans(String vectorClass) throws IOException { Path outputVectorTmpPath = new Path(outputTmpBasePath, new Path(Long.toString(System.nanoTime()))); Configuration initialConf = getConf() == null ? new Configuration() : getConf(); String vectorClassFull = "org.apache.mahout.math." + vectorClass; Vector mean = MatrixColumnMeansJob.run(initialConf, rowPath, outputVectorTmpPath, vectorClassFull); if (!keepTempFiles) { FileSystem fs = outputVectorTmpPath.getFileSystem(conf); fs.delete(outputVectorTmpPath, true); } return mean; }
From source file:at.illecker.hadoop.rootbeer.examples.matrixmultiplication.DistributedRowMatrix.java
License:Apache License
public DistributedRowMatrix transpose() throws IOException { Path outputPath = new Path(outputTmpBasePath, "transpose-" + (System.nanoTime() & 0xFF)); Configuration initialConf = getConf() == null ? new Configuration() : getConf(); Configuration conf = TransposeJob.buildTransposeJobConf(initialConf, rowPath, outputPath, numRows); JobClient.runJob(new JobConf(conf)); DistributedRowMatrix m = new DistributedRowMatrix(outputPath, outputTmpPath, numCols, numRows); m.setConf(this.conf); return m;/* w ww . jav a 2 s.c o m*/ }
From source file:at.illecker.hadoop.rootbeer.examples.matrixmultiplication.DistributedRowMatrix.java
License:Apache License
@Override public Vector times(Vector v) { try {/*from ww w . j av a 2 s. c o m*/ Configuration initialConf = getConf() == null ? new Configuration() : getConf(); Path outputVectorTmpPath = new Path(outputTmpBasePath, new Path(Long.toString(System.nanoTime()))); Configuration conf = TimesSquaredJob.createTimesJobConf(initialConf, v, numRows, rowPath, outputVectorTmpPath); JobClient.runJob(new JobConf(conf)); Vector result = TimesSquaredJob.retrieveTimesSquaredOutputVector(conf); if (!keepTempFiles) { FileSystem fs = outputVectorTmpPath.getFileSystem(conf); fs.delete(outputVectorTmpPath, true); } return result; } catch (IOException ioe) { throw new IllegalStateException(ioe); } }
From source file:at.illecker.hadoop.rootbeer.examples.matrixmultiplication.DistributedRowMatrix.java
License:Apache License
@Override public Vector timesSquared(Vector v) { try {/* ww w .j av a 2 s .c o m*/ Configuration initialConf = getConf() == null ? new Configuration() : getConf(); Path outputVectorTmpPath = new Path(outputTmpBasePath, new Path(Long.toString(System.nanoTime()))); Configuration conf = TimesSquaredJob.createTimesSquaredJobConf(initialConf, v, rowPath, outputVectorTmpPath); JobClient.runJob(new JobConf(conf)); Vector result = TimesSquaredJob.retrieveTimesSquaredOutputVector(conf); if (!keepTempFiles) { FileSystem fs = outputVectorTmpPath.getFileSystem(conf); fs.delete(outputVectorTmpPath, true); } return result; } catch (IOException ioe) { throw new IllegalStateException(ioe); } }
From source file:at.illecker.hadoop.rootbeer.examples.matrixmultiplication.MatrixMultiplicationBenchmark.java
License:Apache License
@Override protected void setUp() throws Exception { m_conf = new Configuration(); // Try to load Hadoop configuration String HADOOP_HOME = System.getenv("HADOOP_HOME"); String HADOOP_INSTALL = System.getenv("HADOOP_INSTALL"); if ((HADOOP_HOME != null) || (HADOOP_INSTALL != null) && (!m_runLocally)) { String HADOOP = ((HADOOP_HOME != null) ? HADOOP_HOME : HADOOP_INSTALL); m_conf.addResource(new Path(HADOOP, "src/core/core-default.xml")); m_conf.addResource(new Path(HADOOP, "src/hdfs/hdfs-default.xml")); m_conf.addResource(new Path(HADOOP, "src/mapred/mapred-default.xml")); m_conf.addResource(new Path(HADOOP, "conf/core-site.xml")); m_conf.addResource(new Path(HADOOP, "conf/hdfs-site.xml")); m_conf.addResource(new Path(HADOOP, "conf/mapred-site.xml")); // System.out.println("Loaded Hadoop configuration from " + HADOOP); try {/*from w ww.j a v a 2 s . com*/ // Connect to HDFS Filesystem FileSystem.get(m_conf); } catch (Exception e) { // HDFS not reachable run Benchmark locally m_conf = new Configuration(); m_runLocally = true; } } // Create random DistributedRowMatrix and write out transposed DistributedRowMatrix.createRandomDistributedRowMatrix(m_conf, n, n, new Random(42L), m_transposedMatrixAPath, true); DistributedRowMatrix.createRandomDistributedRowMatrix(m_conf, n, n, new Random(), m_matrixBPath, false); // Load DistributedRowMatrix A and B m_transposedMatrixA = new DistributedRowMatrix(m_transposedMatrixAPath, CONF_INPUT_DIR, n, n); m_transposedMatrixA.setConf(m_conf); m_matrixB = new DistributedRowMatrix(m_matrixBPath, CONF_INPUT_DIR, n, n); m_matrixB.setConf(m_conf); // Debug output System.out.println("CONF_TMP_DIR: " + CONF_TMP_DIR.toString()); System.out.println("Benchmark " + n + " x " + n + " matrix on " + type); }
From source file:at.illecker.hama.hybrid.examples.hellohybrid.HelloHybridBSP.java
License:Apache License
@Override public void bsp(BSPPeer<IntWritable, NullWritable, IntWritable, NullWritable, NullWritable> peer) throws IOException, SyncException, InterruptedException { BSPJob job = new BSPJob((HamaConfiguration) peer.getConfiguration()); FileSystem fs = FileSystem.get(peer.getConfiguration()); FSDataOutputStream outStream = fs//from w w w . ja v a 2 s .c o m .create(new Path(FileOutputFormat.getOutputPath(job), peer.getTaskId() + ".log")); outStream.writeChars("HelloHybrid.bsp executed on CPU!\n"); ArrayList<Integer> summation = new ArrayList<Integer>(); // test input IntWritable key = new IntWritable(); NullWritable nullValue = NullWritable.get(); while (peer.readNext(key, nullValue)) { outStream.writeChars("input: key: '" + key.get() + "'\n"); summation.add(key.get()); } // test sequenceFileReader Path example = new Path(peer.getConfiguration().get(CONF_EXAMPLE_PATH)); SequenceFile.Reader reader = null; try { reader = new SequenceFile.Reader(fs, example, peer.getConfiguration()); int i = 0; while (reader.next(key, nullValue)) { outStream.writeChars("sequenceFileReader: key: '" + key.get() + "'\n"); if (i < summation.size()) { summation.set(i, summation.get(i) + key.get()); } i++; } } catch (IOException e) { throw new RuntimeException(e); } finally { if (reader != null) { reader.close(); } } // test output for (Integer i : summation) { key.set(i); outStream.writeChars("output: key: '" + key.get() + "'\n"); peer.write(key, nullValue); } // test getAllPeerNames outStream.writeChars("getAllPeerNames: '" + Arrays.toString(peer.getAllPeerNames()) + "'\n"); // test String.split String splitString = "boo:and:foo"; String[] splits; outStream.writeChars("splitString: '" + splitString + "'\n"); splits = splitString.split(":"); outStream.writeChars("split(\":\") len: " + splits.length + " values: '" + Arrays.toString(splits) + "'\n"); splits = splitString.split(":", 2); outStream.writeChars( "split(\":\",2) len: " + splits.length + " values: '" + Arrays.toString(splits) + "'\n"); splits = splitString.split(":", 5); outStream.writeChars( "split(\":\",5) len: " + splits.length + " values: '" + Arrays.toString(splits) + "'\n"); splits = splitString.split(":", -2); outStream.writeChars( "split(\":\",-2) len: " + splits.length + " values: '" + Arrays.toString(splits) + "'\n"); splits = splitString.split(";"); outStream.writeChars("split(\";\") len: " + splits.length + " values: '" + Arrays.toString(splits) + "'\n"); outStream.close(); }