I am trying to remove rows from HBase table using batch scan. When I am running this code as a class file, it's running fine. But when I run the code as a JAR, it's giving me below exception:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.hbase.client.Scan.setBatch(I)V
Here is my code:
public class Purge { public static void main(String[] args) throws IOException, InterruptedException {
if (args.length != 3 ) {
System.out.println("Incorrect number of arguments");
System.out.println("Correct Usage: java Purge <table> <column name> <value>");
System.out.println("Exiting .....");
System.exit(0);
}
String tablename = args[0];
String column = args[1];
String value = args[2];
Configuration conf = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(TableName.valueOf(tablename));
List<Delete> deleteList = new ArrayList<Delete>();
Scan scan = new Scan();
scan.setBatch(100);
scan.addColumn(Bytes.toBytes("cf1"),Bytes.toBytes(column));
Filter filter = new ValueFilter(CompareFilter.CompareOp.LESS_OR_EQUAL,new BinaryComparator(Bytes.toBytes(value)));
scan.setFilter(filter);
ResultScanner scanner=table.getScanner(scan);
for (Result rr : scanner) {
Delete d=new Delete(rr.getRow());
deleteList.add(d);
}
table.delete(deleteList);
}
}
I am using below command line:
HADOOP_CLASSPATH=hbase mapredcp hadoop jar purge.jar Purge "$table" "$column" "$timestamp"