本文整理匯總了Java中org.apache.hadoop.io.SequenceFile.Writer.append方法的典型用法代碼示例。如果您正苦於以下問題:Java Writer.append方法的具體用法?Java Writer.append怎麽用?Java Writer.append使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.hadoop.io.SequenceFile.Writer
的用法示例。
在下文中一共展示了Writer.append方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testJavaSerialization
import org.apache.hadoop.io.SequenceFile.Writer; //導入方法依賴的package包/類
@Test
public void testJavaSerialization() throws Exception {
Path file = new Path(System.getProperty("test.build.data",".") +
"/testseqser.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));
assertEquals("two", reader.getCurrentValue((Object) null));
assertNull(reader.next((Object) null));
reader.close();
}
示例2: testJavaSerialization
import org.apache.hadoop.io.SequenceFile.Writer; //導入方法依賴的package包/類
public void testJavaSerialization() throws Exception {
Path file = new Path(System.getProperty("test.build.data",".") +
"/testseqser.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));
assertEquals("two", reader.getCurrentValue((Object) null));
assertNull(reader.next((Object) null));
reader.close();
}
示例3: testJavaSerialization
import org.apache.hadoop.io.SequenceFile.Writer; //導入方法依賴的package包/類
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));
assertEquals("two", reader.getCurrentValue((Object) null));
assertNull(reader.next((Object) null));
reader.close();
}
示例4: testJavaSerialization
import org.apache.hadoop.io.SequenceFile.Writer; //導入方法依賴的package包/類
@Test
public void testJavaSerialization() throws Exception {
Path file = new Path(GenericTestUtils.getTempPath("testseqser.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));
assertEquals("two", reader.getCurrentValue((Object) null));
assertNull(reader.next((Object) null));
reader.close();
}
示例5: writeRowIds
import org.apache.hadoop.io.SequenceFile.Writer; //導入方法依賴的package包/類
private void writeRowIds(Writer writer, SegmentReader segmentReader) throws IOException {
Terms terms = segmentReader.terms(BlurConstants.ROW_ID);
if (terms == null) {
return;
}
TermsEnum termsEnum = terms.iterator(null);
BytesRef rowId;
long s = System.nanoTime();
while ((rowId = termsEnum.next()) != null) {
long n = System.nanoTime();
if (n + _10_SECONDS > s) {
_progressable.progress();
s = System.nanoTime();
}
writer.append(new Text(rowId.utf8ToString()), NullWritable.get());
}
}
示例6: storeGenerations
import org.apache.hadoop.io.SequenceFile.Writer; //導入方法依賴的package包/類
private synchronized void storeGenerations() throws IOException {
FileSystem fileSystem = _path.getFileSystem(_configuration);
FileStatus[] listStatus = fileSystem.listStatus(_path);
SortedSet<FileStatus> existing = new TreeSet<FileStatus>(Arrays.asList(listStatus));
long currentFile;
if (!existing.isEmpty()) {
FileStatus last = existing.last();
currentFile = Long.parseLong(last.getPath().getName());
} else {
currentFile = 0;
}
Path path = new Path(_path, buffer(currentFile + 1));
LOG.info("Creating new snapshot file [{0}]", path);
FSDataOutputStream outputStream = fileSystem.create(path, false);
Writer writer = SequenceFile.createWriter(_configuration, outputStream, Text.class, LongWritable.class,
CompressionType.NONE, null);
for (Entry<String, Long> e : _namesToGenerations.entrySet()) {
writer.append(new Text(e.getKey()), new LongWritable(e.getValue()));
}
writer.close();
outputStream.close();
cleanupOldFiles(fileSystem, existing);
}
示例7: testAppendRecordCompression
import org.apache.hadoop.io.SequenceFile.Writer; //導入方法依賴的package包/類
@Test(timeout = 30000)
public void testAppendRecordCompression() throws Exception {
GenericTestUtils.assumeInNativeProfile();
Path file = new Path(ROOT_PATH, "testseqappendblockcompr.seq");
fs.delete(file, true);
Option compressOption = Writer.compression(CompressionType.RECORD,
new GzipCodec());
Writer writer = SequenceFile.createWriter(conf,
SequenceFile.Writer.file(file),
SequenceFile.Writer.keyClass(Long.class),
SequenceFile.Writer.valueClass(String.class), compressOption);
writer.append(1L, "one");
writer.append(2L, "two");
writer.close();
verify2Values(file);
writer = SequenceFile.createWriter(conf, SequenceFile.Writer.file(file),
SequenceFile.Writer.keyClass(Long.class),
SequenceFile.Writer.valueClass(String.class),
SequenceFile.Writer.appendIfExists(true), compressOption);
writer.append(3L, "three");
writer.append(4L, "four");
writer.close();
verifyAll4Values(file);
fs.deleteOnExit(file);
}
示例8: writeOutput
import org.apache.hadoop.io.SequenceFile.Writer; //導入方法依賴的package包/類
private void writeOutput(RemoteIterator<? extends FileStatus> input) throws IOException {
Path outPath = new Path(output);
if (distribFs.exists(outPath)) {
throw new IllegalArgumentException("Output file already exists, Not overwriting it:" + output);
}
Writer writer = SequenceFile.createWriter(distribFs.getConf(),
Writer.file(outPath),
Writer.keyClass(Text.class),
Writer.valueClass(BytesWritable.class),
Writer.compression(SequenceFile.CompressionType.RECORD));
Text key = new Text();
BytesWritable value = new BytesWritable();
long skipped = 0;
long copied = 0;
while (input.hasNext()) {
FileStatus next = input.next();
if (filter(next)) {
key.set(next.getPath().toString());
FSDataInputStream stream = localFs.open(next.getPath());
//CAUTION : this could cause memory overflow
byte[] bytes = IOUtils.toByteArray(stream);
value.set(bytes, 0, bytes.length);
writer.append(key, value);
copied++;
} else {
skipped++;
}
}
writer.close();
System.out.println("Files copied ::" + copied);
System.out.println("Files skipped ::" + skipped);
}
示例9: testSequenceFileSync
import org.apache.hadoop.io.SequenceFile.Writer; //導入方法依賴的package包/類
/** Test hsync via SequenceFiles */
@Test
public void testSequenceFileSync() throws Exception {
Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
final FileSystem fs = cluster.getFileSystem();
final Path p = new Path("/testSequenceFileSync/foo");
final int len = 1 << 16;
FSDataOutputStream out = fs.create(p, FsPermission.getDefault(),
EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE, CreateFlag.SYNC_BLOCK),
4096, (short) 1, len, null);
Writer w = SequenceFile.createWriter(new Configuration(),
Writer.stream(out),
Writer.keyClass(RandomDatum.class),
Writer.valueClass(RandomDatum.class),
Writer.compression(CompressionType.NONE, new DefaultCodec()));
w.hflush();
checkSyncMetric(cluster, 0);
w.hsync();
checkSyncMetric(cluster, 1);
int seed = new Random().nextInt();
RandomDatum.Generator generator = new RandomDatum.Generator(seed);
generator.next();
w.append(generator.getKey(), generator.getValue());
w.hsync();
checkSyncMetric(cluster, 2);
w.close();
checkSyncMetric(cluster, 2);
out.close();
checkSyncMetric(cluster, 3);
cluster.shutdown();
}
示例10: run
import org.apache.hadoop.io.SequenceFile.Writer; //導入方法依賴的package包/類
public int run(String[] args) throws IOException {
if (args.length != 2) {
System.err.println("USAGE: hadoop fr.liglab.mining.AsciiToSequenceFile INPUT OUTPUT");
}
FileSystem fs = FileSystem.get(getConf());
Writer writer = new Writer(fs, getConf(), new Path(args[1]), NullWritable.class, TransactionWritable.class);
NullWritable keyW = NullWritable.get();
TransactionWritable valueW = new TransactionWritable();
FileReader reader = new FileReader(args[0]);
ItemsetsFactory factory = new ItemsetsFactory();
while(reader.hasNext()) {
TransactionReader source = reader.next();
while(source.hasNext()) {
factory.add(source.next());
}
valueW.set(factory.get());
writer.append(keyW, valueW);
}
writer.close();
reader.close();
return 0;
}
示例11: testSequenceFileSync
import org.apache.hadoop.io.SequenceFile.Writer; //導入方法依賴的package包/類
/**
* Test hsync via SequenceFiles
*/
@Test
public void testSequenceFileSync() throws Exception {
Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
final FileSystem fs = cluster.getFileSystem();
final Path p = new Path("/testSequenceFileSync/foo");
final int len = 1 << 16;
FSDataOutputStream out = fs.create(p, FsPermission.getDefault(), EnumSet
.of(CreateFlag.CREATE, CreateFlag.OVERWRITE, CreateFlag.SYNC_BLOCK),
4096, (short) 1, len, null);
Writer w = SequenceFile
.createWriter(new Configuration(), Writer.stream(out),
Writer.keyClass(RandomDatum.class),
Writer.valueClass(RandomDatum.class),
Writer.compression(CompressionType.NONE, new DefaultCodec()));
w.hflush();
checkSyncMetric(cluster, 0);
w.hsync();
checkSyncMetric(cluster, 1);
int seed = new Random().nextInt();
RandomDatum.Generator generator = new RandomDatum.Generator(seed);
generator.next();
w.append(generator.getKey(), generator.getValue());
w.hsync();
checkSyncMetric(cluster, 2);
w.close();
checkSyncMetric(cluster, 2);
out.close();
checkSyncMetric(cluster, 3);
cluster.shutdown();
}
示例12: testAppendSort
import org.apache.hadoop.io.SequenceFile.Writer; //導入方法依賴的package包/類
@Test(timeout = 30000)
public void testAppendSort() throws Exception {
GenericTestUtils.assumeInNativeProfile();
Path file = new Path(ROOT_PATH, "testseqappendSort.seq");
fs.delete(file, true);
Path sortedFile = new Path(ROOT_PATH, "testseqappendSort.seq.sort");
fs.delete(sortedFile, true);
SequenceFile.Sorter sorter = new SequenceFile.Sorter(fs,
new JavaSerializationComparator<Long>(), Long.class, String.class, conf);
Option compressOption = Writer.compression(CompressionType.BLOCK,
new GzipCodec());
Writer writer = SequenceFile.createWriter(conf,
SequenceFile.Writer.file(file),
SequenceFile.Writer.keyClass(Long.class),
SequenceFile.Writer.valueClass(String.class), compressOption);
writer.append(2L, "two");
writer.append(1L, "one");
writer.close();
writer = SequenceFile.createWriter(conf, SequenceFile.Writer.file(file),
SequenceFile.Writer.keyClass(Long.class),
SequenceFile.Writer.valueClass(String.class),
SequenceFile.Writer.appendIfExists(true), compressOption);
writer.append(4L, "four");
writer.append(3L, "three");
writer.close();
// Sort file after append
sorter.sort(file, sortedFile);
verifyAll4Values(sortedFile);
fs.deleteOnExit(file);
fs.deleteOnExit(sortedFile);
}
示例13: copyTo64MB
import org.apache.hadoop.io.SequenceFile.Writer; //導入方法依賴的package包/類
public static void copyTo64MB(String src, String dst) throws IOException {
Configuration hconf = new Configuration();
Path srcPath = new Path(src);
Path dstPath = new Path(dst);
FileSystem fs = FileSystem.get(hconf);
long srcSize = fs.getFileStatus(srcPath).getLen();
int copyTimes = (int) (67108864 / srcSize); // 64 MB
System.out.println("Copy " + copyTimes + " times");
Reader reader = new Reader(hconf, SequenceFile.Reader.file(srcPath));
Writable key = (Writable) ReflectionUtils.newInstance(reader.getKeyClass(), hconf);
Text value = new Text();
Writer writer = SequenceFile.createWriter(hconf, Writer.file(dstPath), Writer.keyClass(key.getClass()), Writer.valueClass(Text.class), Writer.compression(CompressionType.BLOCK, getLZOCodec(hconf)));
int count = 0;
while (reader.next(key, value)) {
for (int i = 0; i < copyTimes; i++) {
writer.append(key, value);
count++;
}
}
System.out.println("Len: " + writer.getLength());
System.out.println("Rows: " + count);
reader.close();
writer.close();
}
示例14: generateData
import org.apache.hadoop.io.SequenceFile.Writer; //導入方法依賴的package包/類
private void generateData(String mrIncWorkingPathStr, String rowId, String recordId, String value) throws IOException {
Path path = new Path(new Path(mrIncWorkingPathStr), "new");
Writer writer = new SequenceFile.Writer(miniCluster.getFileSystem(), conf, new Path(path, UUID.randomUUID()
.toString()), Text.class, BlurRecord.class);
BlurRecord blurRecord = new BlurRecord();
blurRecord.setRowId(rowId);
blurRecord.setRecordId(recordId);
blurRecord.setFamily("fam0");
blurRecord.addColumn("col0", value);
writer.append(new Text(rowId), blurRecord);
writer.close();
}
示例15: getMrWorkingPathWriter
import org.apache.hadoop.io.SequenceFile.Writer; //導入方法依賴的package包/類
private org.apache.hadoop.hive.ql.exec.FileSinkOperator.RecordWriter getMrWorkingPathWriter(
final Configuration configuration) throws IOException {
PrivilegedExceptionAction<org.apache.hadoop.hive.ql.exec.FileSinkOperator.RecordWriter> privilegedExceptionAction = new PrivilegedExceptionAction<org.apache.hadoop.hive.ql.exec.FileSinkOperator.RecordWriter>() {
@Override
public org.apache.hadoop.hive.ql.exec.FileSinkOperator.RecordWriter run() throws Exception {
String workingPathStr = configuration.get(BlurConstants.BLUR_BULK_UPDATE_WORKING_PATH);
Path workingPath = new Path(workingPathStr);
Path tmpDir = new Path(workingPath, "tmp");
FileSystem fileSystem = tmpDir.getFileSystem(configuration);
String loadId = configuration.get(BlurSerDe.BLUR_MR_LOAD_ID);
Path loadPath = new Path(tmpDir, loadId);
final Writer writer = new SequenceFile.Writer(fileSystem, configuration, new Path(loadPath, UUID.randomUUID()
.toString()), Text.class, BlurRecord.class);
return new org.apache.hadoop.hive.ql.exec.FileSinkOperator.RecordWriter() {
@Override
public void write(Writable w) throws IOException {
BlurRecord blurRecord = (BlurRecord) w;
String rowId = blurRecord.getRowId();
writer.append(new Text(rowId), blurRecord);
}
@Override
public void close(boolean abort) throws IOException {
writer.close();
}
};
}
};
UserGroupInformation userGroupInformation = getUGI(configuration);
try {
return userGroupInformation.doAs(privilegedExceptionAction);
} catch (InterruptedException e) {
throw new IOException(e);
}
}