@SuppressWarnings("deprecation") private void writeMetadataTest(FileSystem fs, int count, int seed, Path file, CompressionType compressionType, CompressionCodec codec, SequenceFile.Metadata metadata) throws IOException { fs.delete(file, true); LOG.info("creating " + count + " records with metadata and with " + compressionType + " compression"); SequenceFile.Writer writer = SequenceFile.createWriter(fs, conf, file, RandomDatum.class, RandomDatum.class, compressionType, codec, null, metadata); RandomDatum.Generator generator = new RandomDatum.Generator(seed); for (int i = 0; i < count; i++) { generator.next(); RandomDatum key = generator.getKey(); RandomDatum value = generator.getValue(); writer.append(key, value); } writer.close(); }
@SuppressWarnings("deprecation") @Test public void testRecursiveSeqFileCreate() throws IOException { FileSystem fs = FileSystem.getLocal(conf); Path name = new Path(new Path(System.getProperty("test.build.data","."), "recursiveCreateDir") , "file"); boolean createParent = false; try { SequenceFile.createWriter(fs, conf, name, RandomDatum.class, RandomDatum.class, 512, (short) 1, 4096, createParent, CompressionType.NONE, null, new Metadata()); fail("Expected an IOException due to missing parent"); } catch (IOException ioe) { // Expected } createParent = true; SequenceFile.createWriter(fs, conf, name, RandomDatum.class, RandomDatum.class, 512, (short) 1, 4096, createParent, CompressionType.NONE, null, new Metadata()); // should succeed, fails if exception thrown }
private void writeMetadataTest(FileSystem fs, int count, int seed, Path file, CompressionType compressionType, CompressionCodec codec, SequenceFile.Metadata metadata) throws IOException { fs.delete(file, true); LOG.info("creating " + count + " records with metadata and with " + compressionType + " compression"); SequenceFile.Writer writer = SequenceFile.createWriter(fs, conf, file, RandomDatum.class, RandomDatum.class, compressionType, codec, null, metadata); RandomDatum.Generator generator = new RandomDatum.Generator(seed); for (int i = 0; i < count; i++) { generator.next(); RandomDatum key = generator.getKey(); RandomDatum value = generator.getValue(); writer.append(key, value); } writer.close(); }
public void testRecursiveSeqFileCreate() throws IOException { FileSystem fs = FileSystem.getLocal(conf); Path name = new Path(new Path(System.getProperty("test.build.data","."), "recursiveCreateDir") , "file"); boolean createParent = false; try { SequenceFile.createWriter(fs, conf, name, RandomDatum.class, RandomDatum.class, 512, (short) 1, 4096, createParent, CompressionType.NONE, null, new Metadata()); fail("Expected an IOException due to missing parent"); } catch (IOException ioe) { // Expected } createParent = true; SequenceFile.createWriter(fs, conf, name, RandomDatum.class, RandomDatum.class, 512, (short) 1, 4096, createParent, CompressionType.NONE, null, new Metadata()); // should succeed, fails if exception thrown }
@SuppressWarnings("deprecation") @Test public void testRecursiveSeqFileCreate() throws IOException { FileSystem fs = FileSystem.getLocal(conf); Path name = new Path(new Path(GenericTestUtils.getTempPath( "recursiveCreateDir")), "file"); boolean createParent = false; try { SequenceFile.createWriter(fs, conf, name, RandomDatum.class, RandomDatum.class, 512, (short) 1, 4096, createParent, CompressionType.NONE, null, new Metadata()); fail("Expected an IOException due to missing parent"); } catch (IOException ioe) { // Expected } createParent = true; SequenceFile.createWriter(fs, conf, name, RandomDatum.class, RandomDatum.class, 512, (short) 1, 4096, createParent, CompressionType.NONE, null, new Metadata()); // should succeed, fails if exception thrown }
@SuppressWarnings("unchecked") private Writer createWriter(Map<String, String> metadata) throws IOException { final Metadata md = new Metadata(); for (final Entry<String, String> e : metadata.entrySet()) { md.set(new Text(e.getKey()), new Text(e.getValue())); } final Class<K> keyClass = (Class<K>) ((ParameterizedType) getClass().getGenericSuperclass()) .getActualTypeArguments()[0]; final Class<V> valueClass = (Class<V>) ((ParameterizedType) getClass().getGenericSuperclass()) .getActualTypeArguments()[1]; return SequenceFile.createWriter(fileSystem, config, sequenceFilePath, keyClass, valueClass, compressionType, new DefaultCodec(), null, md); }
/** * Read any metadata stored in the {@link Configuration}. * * @param conf * the configuration * @return the metadata map */ public static Metadata getMetadata(Configuration conf) { final Metadata metadata = new Metadata(); final String[] keys = conf.getStrings(META_KEYS); if (keys != null) { for (final String key : keys) { final String value = conf.get(META_PREFIX + key); if (value != null) metadata.set(new Text(key), new Text(value)); } } return metadata; }
@SuppressWarnings("deprecation") private SequenceFile.Metadata readMetadata(FileSystem fs, Path file) throws IOException { LOG.info("reading file: " + file.toString()); SequenceFile.Reader reader = new SequenceFile.Reader(fs, file, conf); SequenceFile.Metadata meta = reader.getMetadata(); reader.close(); return meta; }
private void sortMetadataTest(FileSystem fs, Path unsortedFile, Path sortedFile, SequenceFile.Metadata metadata) throws IOException { fs.delete(sortedFile, true); LOG.info("sorting: " + unsortedFile + " to: " + sortedFile); final WritableComparator comparator = WritableComparator.get(RandomDatum.class); SequenceFile.Sorter sorter = new SequenceFile.Sorter(fs, comparator, RandomDatum.class, RandomDatum.class, conf, metadata); sorter.sort(new Path[] { unsortedFile }, sortedFile, false); }
/** * Test that makes sure createWriter succeeds on a file that was * already created * @throws IOException */ @SuppressWarnings("deprecation") @Test public void testCreateWriterOnExistingFile() throws IOException { Configuration conf = new Configuration(); FileSystem fs = FileSystem.getLocal(conf); Path name = new Path(new Path(System.getProperty("test.build.data","."), "createWriterOnExistingFile") , "file"); fs.create(name); SequenceFile.createWriter(fs, conf, name, RandomDatum.class, RandomDatum.class, 512, (short) 1, 4096, false, CompressionType.NONE, null, new Metadata()); }
private SequenceFile.Metadata readMetadata(FileSystem fs, Path file) throws IOException { LOG.info("reading file: " + file.toString()); SequenceFile.Reader reader = new SequenceFile.Reader(fs, file, conf); SequenceFile.Metadata meta = reader.getMetadata(); reader.close(); return meta; }
/** * Test that makes sure createWriter succeeds on a file that was * already created * @throws IOException */ public void testCreateWriterOnExistingFile() throws IOException { Configuration conf = new Configuration(); FileSystem fs = FileSystem.getLocal(conf); Path name = new Path(new Path(System.getProperty("test.build.data","."), "createWriterOnExistingFile") , "file"); fs.create(name); SequenceFile.createWriter(fs, conf, name, RandomDatum.class, RandomDatum.class, 512, (short) 1, 4096, false, CompressionType.NONE, null, new Metadata()); }
/** * Call this method after init() has been executed * @return whether WAL compression is enabled */ static boolean isWALCompressionEnabled(final Metadata metadata) { // Check version is >= VERSION? Text txt = metadata.get(WAL_VERSION_KEY); if (txt == null || Integer.parseInt(txt.toString()) < COMPRESSION_VERSION) { return false; } // Now check that compression type is present. Currently only one value. txt = metadata.get(WAL_COMPRESSION_TYPE_KEY); return txt != null && txt.equals(DICTIONARY_COMPRESSION_TYPE); }
/** * Create sequence file Metadata for our WAL file with version and compression * type (if any). * @param conf * @param compress * @return Metadata instance. */ private static Metadata createMetadata(final Configuration conf, final boolean compress) { TreeMap<Text, Text> metaMap = new TreeMap<Text, Text>(); metaMap.put(WAL_VERSION_KEY, new Text("1")); if (compress) { // Currently we only do one compression type. metaMap.put(WAL_COMPRESSION_TYPE_KEY, DICTIONARY_COMPRESSION_TYPE); } return new Metadata(metaMap); }
/** * Create sequence file Metadata for our WAL file with version and compression * type (if any). * @param conf * @param compress * @return Metadata instance. */ private static Metadata createMetadata(final Configuration conf, final boolean compress) { TreeMap<Text, Text> metaMap = new TreeMap<Text, Text>(); metaMap.put(WAL_VERSION_KEY, WAL_VERSION); if (compress) { // Currently we only do one compression type. metaMap.put(WAL_COMPRESSION_TYPE_KEY, DICTIONARY_COMPRESSION_TYPE); } return new Metadata(metaMap); }
/** * Call this method after init() has been executed * * @return whether WAL compression is enabled */ static boolean isWALCompressionEnabled(final Metadata metadata) { // Check version is >= VERSION? Text txt = metadata.get(WAL_VERSION_KEY); if (txt == null || Integer.parseInt(txt.toString()) < COMPRESSION_VERSION) { return false; } // Now check that compression type is present. Currently only one value. txt = metadata.get(WAL_COMPRESSION_TYPE_KEY); return txt != null && txt.equals(DICTIONARY_COMPRESSION_TYPE); }