0
votes

I am trying to run the following Jython code to scan a hbase table:

    import java.lang
    from org.apache.hadoop.hbase import TableName, HBaseConfiguration
    from org.apache.hadoop.hbase.client import Connection, ConnectionFactory,         
    Result, ResultScanner, Table, Admin
    from org.apache.hadoop.conf import Configuration
    conf = HBaseConfiguration.create()
    connection = ConnectionFactory.createConnection(conf)
    admin = connection.getAdmin()
    tableName = TableName.valueOf('station')
    table = connection.getTable(tableName)
    cf = "stn"
    attr = "name"
    scanner = table.getScanner(cf)
    while 1:
         result = scanner.next()
         if not result:
            break
         print java.lang.String(result.row),   
         java.lang.String(result.getValue(cf, attr))

I am using the following command to try to run it:

jython test1.py

But I get the following error:

Traceback (most recent call last):
  File "test1.py", line 2, in <module>
    from org.apache.hadoop.hbase import TableName, HBaseConfiguration
ImportError: No module named apache

How do I resolve this? I have installed hbase in standalone mode and it is working fine(created a few sample tables using hbase shell).

UPDATE: As suggested in the comments, I tried the following command to run it:

jython -Dpython.path=./hbase-1.4.8/lib/hbase-common-1.4.8.jar test1.py

I am now getting the following error message:

Traceback (most recent call last): File "test1.py", line 2, in from org.apache.hadoop.hbase import TableName, HBaseConfiguration java.lang.NoClassDefFoundError: org/apache/hadoop/io/RawComparator at org.apache.hadoop.hbase.NamespaceDescriptor.(NamespaceDescriptor.java:45) at org.apache.hadoop.hbase.TableName.(TableName.java:82) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at org.python.core.Py.loadAndInitClass(Py.java:991) at org.python.core.Py.findClassInternal(Py.java:926) at org.python.core.Py.findClassEx(Py.java:977) at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:133) at org.python.core.packagecache.PackageManager.findClass(PackageManager.java:33) at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:122) at org.python.core.PyJavaPackage.findattr_ex(PyJavaPackage.java:134) at org.python.core.PyObject.findattr(PyObject.java:946) at org.python.core.imp.importFromAs(imp.java:1160) at org.python.core.imp.importFrom(imp.java:1132) at org.python.pycode._pyx0.f$0(test1.py:13) at org.python.pycode._pyx0.call_function(test1.py) at org.python.core.PyTableCode.call(PyTableCode.java:167) at org.python.core.PyCode.call(PyCode.java:18) at org.python.core.Py.runCode(Py.java:1386) at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:296) at org.python.util.jython.run(jython.java:362) at org.python.util.jython.main(jython.java:142) Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.io.RawComparator at org.python.core.SyspathJavaLoader.findClass(SyspathJavaLoader.java:131) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 22 more

java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: org/apache/hadoop/io/RawComparator

How do I resolve this?

1

1 Answers

1
votes

It seems the library is missing from the classpath. By default jython.jar includes only the default python mobules present in the lib directory. Any third party module needs to be added in the classpath.

You need to add reference of hbase jar in the library modules as following:

jython -Dpython.path=/<location of jar>/hbase.jar test1.py

Another option is :

java -cp /<location of jar>/hbase.jar;jython.jar org.python.util.jython test1.py

Jython Classpath should include HBASE classpath to include all dependencies.

For more details, please refer : https://hbase.apache.org/book.html#jython