1

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"

2 Answers 2

0

What does it mean "when I use as class" ? Anyway, this exception usually come when some lib are missing: lib that probably were visible during the compilation (so the compilation is successfull), but not when launching the compiled jar, because the enviroment is probably different.

Probably, it works when launched from an IDE (like eclipse) because the libraries are managed by the eclipse classpath, when you put the .jar outside from the classpath where it was compiled, it do not work because there's some jar missing. Try to find the missing lib and then put them in the classpath.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry for the confusion. What I meant to say is that when I am running it like this, it's working fine - java Purge "$table" "$column" "$timestamp". But when I am running as a Jar, it's giving me error.
0

You should try to set the scan properties using the ScanBuilder API:

http://hbase.apache.org/1.1/apidocs/org/apache/hadoop/hbase/protobuf/generated/ClientProtos.Scan.Builder.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.