繁体   English   中英

Spark到Hbase表未显示完整的数据记录

[英]Spark to Hbase Table is not showing complete data records

我有一个3万条记录的日志文件,该文件是我从Kafka发布的,并通过spark将其持久保存到HBase中。 在30K条记录中,我只能在HBase表中看到4K条记录。

  1. 我尝试将流保存在MySQL中,并且将所有记录正确保存在MySql中。
  2. 但是在HBase中,如果我在Kafka主题中发布100条记录的文件,它将在HBase表中保存36条记录,如果我发布30K条记录,Hbase仅显示4k条记录。
  3. 此外,HBase中的记录(行)的顺序不像1..3..10..17th。 final Job newAPIJobConfiguration1 = Job.getInstance(config); newAPIJobConfiguration1.getConfiguration().set(TableOutputFormat.OUTPUT_TABLE, "logs"); newAPIJobConfiguration1.setOutputFormatClass(org.apache.hadoop.hbase.mapreduce.TableOutputFormat.class); HTable hTable = new HTable(config, "country"); lines.foreachRDD((rdd,time)-> { // Get the singleton instance of SparkSession SparkSession spark = SparkSession.builder().config(rdd.context().getConf()).getOrCreate(); // Convert RDD[String] to RDD[case class] to DataFrame JavaRDD rowRDD = rdd.map(line -> { String[] logLine = line.split(" +"); Log record = new Log(); record.setTime((logLine[0])); record.setTime_taken((logLine[1])); record.setIp(logLine[2]); return record; }); saveToHBase(rowRDD, newAPIJobConfiguration1.getConfiguration()); }); ssc.start(); ssc.awaitTermination(); } //6. saveToHBase method - insert data into HBase public static void saveToHBase(JavaRDD rowRDD, Configuration conf) throws IOException { // create Key, Value pair to store in HBase JavaPairRDD hbasePuts = rowRDD.mapToPair( new PairFunction() { private static final long serialVersionUID = 1L; @Override public Tuple2 call(Log row) throws Exception { Put put = new Put(Bytes.toBytes(System.currentTimeMillis())); //put.addColumn(Bytes.toBytes("sparkaf"), Bytes.toBytes("message"), Bytes.toBytes(row.getMessage())); put.addImmutable(Bytes.toBytes("time"), Bytes.toBytes("col1"), Bytes.toBytes(row.getTime())); put.addImmutable(Bytes.toBytes("time_taken"), Bytes.toBytes("col2"), Bytes.toBytes(row.getTime_taken())); put.addImmutable(Bytes.toBytes("ip"), Bytes.toBytes("col3"), Bytes.toBytes(row.getIp())); return new Tuple2(new ImmutableBytesWritable(), put); } }); // save to HBase- Spark built-in API method //hbasePuts.saveAsNewAPIHadoopDataset(conf); hbasePuts.saveAsNewAPIHadoopDataset(conf);

由于HBase通过行键唯一存储记录,因此很有可能覆盖记录。

您正在使用currentTime(以毫秒为单位)作为行键,并且使用同一行键创建的任何记录都将覆盖旧的行键。

Put put = new Put(Bytes.toBytes(System.currentTimeMillis()));

因此,如果在1毫秒内创建了100个看跌期权,那么由于同一行被覆盖了99次,因此HBase中只会显示100个看跌期权。

HBase中的4k行键很可能是加载数据所需的4k唯一毫秒(4秒)。

我建议使用其他行键设计。 另外,作为一个旁注,在HBase中使用单调递增的行键通常是一个坏主意: 更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM