Ho bisogno di caricare i dati dal file di testo su Map Reduce, sto provando da molti giorni ma non ho trovato nessuna soluzione giusta per il mio lavoro. Esiste un metodo o una classe che legge un file text/csv da un sistema e memorizza i dati nella tabella HBASE. È davvero molto urgente per me, per favore qualcuno può aiutarmi a conoscere MapReduce F/w.legge il file di testo da System a Hbase MapReduce
5
A
risposta
2
Per la lettura dal file di testo, innanzitutto il file di testo deve essere in hdf. È necessario specificare il formato di input e OutputFormat per lavoro
Job job = new Job(conf, "example");
FileInputFormat.addInputPath(job, new Path("PATH to text file"));
job.setInputFormatClass(TextInputFormat.class);
job.setMapperClass(YourMapper.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
TableMapReduceUtil.initTableReducerJob("hbase_table_name", YourReducer.class, job);
job.waitForCompletion(true);
YourReducer
dovrebbe estende org.apache.hadoop.hbase.mapreduce.TableReducer<Text, Text, Text>
Esempio codice riduttore
public class YourReducer extends TableReducer<Text, Text, Text> {
private byte[] rawUpdateColumnFamily = Bytes.toBytes("colName");
/**
* Called once at the beginning of the task.
*/
@Override
protected void setup(Context context) throws IOException, InterruptedException {
// something that need to be done at start of reducer
}
@Override
public void reduce(Text keyin, Iterable<Text> values, Context context) throws IOException, InterruptedException {
// aggregate counts
int valuesCount = 0;
for (Text val : values) {
valuesCount += 1;
// put date in table
Put put = new Put(keyin.toString().getBytes());
long explicitTimeInMs = new Date().getTime();
put.add(rawUpdateColumnFamily, Bytes.toBytes("colName"), explicitTimeInMs,val.toString().getBytes());
context.write(keyin, put);
}
}
}
classe Sample mapper
public static class YourMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
context.write(word, one);
}
}
}
Problemi correlati
- 1. Legge solo le prime righe di testo da un file
- 2. Python non legge tutto il file di testo
- 3. Perl: legge il file di testo web e lo "apre"
- 4. legge il testo da una particolare pagina usando PDFBox
- 5. Importa dati da HDFS a HBase (cdh3u2)
- 6. Hadoop MapReduce legge il set di dati una volta per più lavori
- 7. Hbase: Come specificare il nome host per il master Hbase
- 8. VB.NET Legge alcuni testi in un file di testo
- 9. Introduzione a MapReduce/Hadoop
- 10. legge l'input da un file e sincronizza di conseguenza
- 11. Può Python rimuovere le virgolette doppie da una stringa, quando si legge nel file di testo?
- 12. Connessione rifiutata in Hbase Shell durante il collegamento di HBase a HDFS
- 13. Haskell legge righe di file
- 14. Fortran legge il file nell'array - dimensioni trasposte
- 15. Caricamento di dati CSV in Hbase
- 16. Inserimento di file system Android
- 17. Legge il file XML nella struct
- 18. Hadoop MapReduce I file di input multiple
- 19. Conversione da byte a stringa di shell HBase
- 20. Il valore restituito da system() è uguale a "$?"?
- 21. Copia il testo da file word a una nuova parola
- 22. Archivia il file su System uri?
- 23. E 'possibile creare un VectorDrawable da File System (* .xml File)
- 24. Legge il file XML come DataSet
- 25. Epplus non legge il file excel
- 26. legge il file db SQLite usando java
- 27. Node.js - File System ottiene il tipo di file
- 28. Il miglior sistema di file per servire file da 1 GB usando nginx, in scrittura moderata, legge le prestazioni?
- 29. Quale file di impostazioni legge/scrive PreferenceFragment?
- 30. Ignora il mapreduce di hadoop.fileoutputcommitter.marksuccessfuljobs in oozie