- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
read a AVRO file stored in HDFS
- Labels:
-
Apache Hadoop
Created ‎02-05-2016 11:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I want to read a metadata from avro file stored in HDFS using AVRO api ( https://avro.apache.org/docs/1.4.1/api/java/org/apache/avro/file/DataFileReader.html )
The avro DataFileReader accepts only File objects. Is it somehow possible to read data from file stored on hdfs instead of data stored on local fs?
Thank you
Created ‎02-05-2016 02:17 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I created sample code, it works FINE.
BufferedInputStream inStream = null; String inputF = "hdfs://CustomerData-20160128-1501807.avro"; org.apache.hadoop.fs.Path inPath = new org.apache.hadoop.fs.Path(inputF); try { Configuration conf = new Configuration(); conf.set("fs.defaultFS", "hdfs://sandbox.hortonworks.com:8020"); FileSystem fs = FileSystem.get(URI.create(inputF), conf); inStream = new BufferedInputStream(fs.open(inPath)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } DataFileStream reader = new DataFileStream(inStream, new GenericDatumReader()); Schema schema = reader.getSchema(); System.out.println(schema.toString());
Created ‎02-05-2016 03:13 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@John Smith use "code" button to paste code
Created ‎02-05-2016 03:15 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@John Smith I edited the answer to format the code.

- « Previous
-
- 1
- 2
- Next »