我正在考虑如何使用Spark的HBase ColumnRangeFilter 我查看org.apache.hadoop.hbase.mapreduce.TableInputFormat,但此API不包含ColumnRangeFilter 所以我不知道Spark如何做ColumnRangeFilter。
我想使用以“20170225”开头并以“20170305”结尾的ColumnRangeFilter。
我可以在代码下扫描Row。
val conf = HBaseConfiguration.create()
conf.set(TableInputFormat.INPUT_TABLE, "like_count")
val startRow = "001"
val endRow = "100"
conf.set(TableInputFormat.SCAN_ROW_START, startRow)
conf.set(TableInputFormat.SCAN_ROW_STOP, endRow)
sc.newAPIHadoopRDD(conf, classOf[TableInputFormat], classOf[ImmutableBytesWritable], classOf[Result])
我需要添加哪些代码? 如果有人有建议,请告诉我。
答案 0 :(得分:0)
使用scan对象设置起始行和结束行,并在Hbase配置中设置该扫描对象,然后将该配置对象传递给tableInputFormat https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/Scan.html
Scan scan = new Scan(startRow, endRow);
scan.setMaxVersions(MAX_VERSIONS);
//This can also be done if not specified in scan object constructor
scan.setFilter(new ColumnRangeFilter(startrow,true,endrow,true));
HBaseConfiguration.merge(conf, HBaseConfiguration.create(conf));
conf.set(TableInputFormat.INPUT_TABLE, username + ":" + path);
conf.set(TableInputFormat.SCAN, convertScanToString(scan));
tableInputFormat.setConf(conf);