How to know which Kind of Sequence file it is? - java

I am new to Hadoop and came across few Sequence files. As I read Sequence File there are 3 ways to create a sequence file. Now I have a sequence file , how do I know which what kind of sequence file it is. How do i read Meta information about that. I need this because, I have got a sequence file and it is expected I create a similar sequence file.
Is there any hadoop command I can use to check this information?

SequenceFile is a flat file consisting of binary key/value pairs.
The SequenceFile.Reader acts as a bridge and can read any of the
SequenceFile formats.
You don't need to mention the SequenceFile format to the SequenceFile.Reader, by default the reader instance will get these details and decompresses the file according to the codec found in the file format.
Check out examples here:
Reading and Writing Sequencefile using Hadoop 2.0 Apis
Reading and Writing SequenceFile Example

Related

Reading PDF/text/word file efficiently with Spark

I am doing NLP (Natural Language Processing) processing on my data. The data is in form of files that can be of type PDF/Text/Word/HTML. These files are stored in a nested directory structure on local disk.
My stand alone Java based NLP parser can read input files, extract text from these and do the NLP processing on the extracted text.
I am converting my Java based NLP parser to execute it on my Spark cluster. I know that Spark can read multiple text files from a directory and convert into RDDs for further processing. My input data is not only in text files, but in a multitude of different file formats.
My question is: How can I efficiently read the input files (PDF/Text/Word/HTML) in my Java based Spark program for processing these files in Spark cluster.
Files can be read by
sparkContext.binaryFiles()
And then can be processed by parser.

How to convert csv file to avro file format using avro-tools jar?

I want to convert CSV file to Avro. Currently I am converting my CSV to json and then creating Avro file out of it. Below is the sample CSV data,
name,favorite_number,favorite_color
Rick,26,Red
Mathew,22,Blue
Is there a direct way to convert CSV file to Avro using avro-tools?
can fromtext do the job?
d:\app>java -jar avro-tools-1.7.7.jar fromtext
Expected 2 args: from_file to_file (local filenames, Hadoop URI's, or '-' for st
din/stdout
Option Description
------ -----------
--codec Compression codec (default: null)
--level <Integer> Compression level (only applies to
deflate and xz) (default: -1)
I have read the solutions achieved using hive. Please note - I'm not using Hadoop.
Avro Tools' fromtext will convert the file so that each record corresponds to a whole line, which is not what you want. Csv2avro seems to be the tool you are looking for. This blog post mentions two similar tools, but they seem to be less mature.

multiple file output in hadoop mapreduce streaming

Im using hadoop map and reduce program . And i need to read a multiple file and output it into multiple files
Example
Input \ one.txt
two.txt
three.txt
Output \
one_out.txt
two_out.txt
I need to get some thing like this. How can i achieve this.
Kindly help me
Thanks
If the file size is small, you can simply use FileInputFormat, and hadoop will internally spawn a separate mapper task for every file, which will eventually generate output file for corresponding input file (if there are no reducers involved).
If the file is huge, you need to write a custominput format, and specify isSplittable(false). It will ensure that hadoop does not split your file across mappers and will not generate multiple output files per input file

How to read pig output in separate Java program

I have some pig output files and want to read them on another machine(without hadoop installation). I just want to read a tab-seperated plain text line and parse it into a java object. I am guessing we should be able to use pig.jar as dependency and be able to read it. I could not find relevant documentation. I think this class could be used? How can we provide the schema also.
I suggest you to store data in Avro serialization format. It is Pig-independent and it allows to handle complex data structures like you described (so you don't need to write your own parser). See this article for examples.
Your pig output files are just text files, right? Then you don't need any pig or hadoop jars.
Last time i worked with Pig was on amazon's EMR platform, and the output files were stashed in an s3 bucket. They were just text files and standard java can read the file in.
That class you referenced is for reading into pig from some text format.
Are you asking for a library to parse the pig data model into java objects? I.e. the text representation of tuples & bags, etc? If so then its probably easier to write it yourself. It's a VERY simple data model with only 3 -ish datatypes..

Sentiment analysis on JSON tweets in Hadoop HDFS

I've used Apache Flume to pipe a large amount of tweets into the HDFS of Hadoop. I was trying to do sentiment analysis on this data - just something simple to begin with, like positive v negative word comparison.
My problem is that all the guides I find showing me how to do it have a text file of positive and negative words and then a huge text file with every tweet.
As I used Flume, all my data is already in Hadoop. When I access it using localhost:50070 I can see the data, in separate files according to month/day/hour, with each file containing three or four tweets. I have maybe 50 of these files for every hour. Although it doesn't say anywhere, I'm assuming they are in JSON format.
Bearing this in mind, how can I perform my analysis on them? In all the examples I've seen where the Mapper and Reducer have been written, there has been a single file this has been performed on, not a large collection of small JSON files. What should my next step be?
This example should get you started
https://github.com/cloudera/cdh-twitter-example
Basically use hive external table to map your json data and query using hiveql
When you want to process all the files in a directory, you can just specify the path of the directory as your input file to your hadoop job so that it will consider all the files in that directory as its input.
For example if your small files are in the directory /user/flume/tweets/.... then in your hadoop job you can just specify /user/flume/tweets/ as your input file.
If you want to automate the analysis for every one hour you need to write one oozie workflow.
You can refer to the below link for sentiment analysis in hive
https://acadgild.com/blog/sentiment-analysis-on-tweets-with-apache-hive-using-afinn-dictionary/

Categories

Resources