Necesito cargar datos desde el archivo de texto a Map Reduce, estoy mirando desde hace muchos días pero no encontré ninguna solución correcta para mi trabajo. ¿Hay algún Método o Clase que lea un archivo de texto/csv de un sistema y almacene los datos en la Tabla de HBASE? Es realmente muy urgente para mí, ¿alguien me puede ayudar a saber MapReduce F/w.leer archivo de texto del sistema a Hbase MapReduce
5
A
Respuesta
2
Para leer el archivo de texto, antes que nada, el archivo de texto debe estar en hdfs. Es necesario especificar el formato de entrada y OutputFormat de trabajo
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
debe extiende código reductor org.apache.hadoop.hbase.mapreduce.TableReducer<Text, Text, Text>
Muestra
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);
}
}
}
clase Mapper Muestra
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);
}
}
}
Cuestiones relacionadas
- 1. Hbase mapreduce error
- 2. Hadoop mapreduce la transmisión desde HBase
- 3. ¿Cómo leer datos de Hbase?
- 4. Leer la última línea del archivo de texto
- 5. Leer texto del archivo de imagen en Java
- 6. Leer un archivo de texto con php
- 7. Leer archivo de texto en D
- 8. jquery - ¿Leer un archivo de texto?
- 9. Crear, guardar y leer archivo de texto
- 10. Leer archivo de texto en Delphi 2009
- 11. VB.NET Leer Cierto texto en un archivo de texto
- 12. Leer del archivo en Eclipse
- 13. Leer valores nulos del archivo
- 14. Leer del archivo o stdin
- 15. PHP: Leer línea específica del archivo
- 16. Leer del archivo, borrarlo, escribir en él
- 17. leer archivo del almacenamiento externo
- 18. Leer documento de texto dentro del proyecto de estudio visual
- 19. HP-UX - ¿Cómo puedo leer un archivo de texto del archivo tar sin extraerlo?
- 20. Cliente Hbase Error de ConnectionLoss para/hbase
- 21. Hbase: Cómo especificar el nombre de host para Hbase master
- 22. sonido del sistema de registro (stereomix) a un archivo
- 23. ¿Cómo leer un archivo de texto en crecimiento en C++?
- 24. cómo leer Variable de entorno del sistema en Spring applicationContext
- 25. python - Leer archivo desde y hacia líneas de texto específicas
- 26. Error al leer el archivo de texto en php
- 27. Importar datos de HDFS a HBase (cdh3u2)
- 28. leer el archivo de texto mediante programación usando Objective-C
- 29. Leer desde archivo de texto en el servidor usando jquery
- 30. ¿Es posible usar espuma python para leer un archivo wsdl del sistema de archivos?