Thank you, Jim, that worked.

-liam


On Thu, Apr 24, 2014 at 2:57 PM, Jim Baker <jbaker@zyasoft.com> wrote:
You will want to construct this Pair directly. The signature of the constructor is
 
FuzzyRowFilter(List<Pair<byte[],byte[]>> fuzzyKeysData)

As you saw, Jython doesn't know how to directly convert a Python tuple to an org.apache.hadoop.hbase.util.Pair, although it can convert a Python list to a Java List. But you can readily construct this Pair with one extra step. Also I prefer using the standard Python array module instead of the Jython specific jarray, unless you need jarray.zeros; both actually construct standard Java arrays. With that in mind, something like the following should work:

from array import array
from org.apache.hadoop.hbase.filter import FuzzyRowFilter
from org.apache.hadoop.hbase.util import Pair

filter = FuzzyRowFilter([
    Pair(array('b', "\\x00BC\\x00\\x00FG"),
         array('b', [1, 0, 0, 1, 1, 0, 0]))])

Note this also means you don't have to use Bytes.toBytes - you're just using standard portable Python up to the point of constructing the specific HBase object.

- Jim


On Thu, Apr 24, 2014 at 2:49 PM, Liam Slusser <lslusser@gmail.com> wrote:
Alan -

Thank you!  That got me closer.  I believe a lot of that code I can skip since   Here is what I have so far...

>>> fuzzyKeysData = ArrayList()
>>> scan = Scan()
>>> fuzzyKeysData.add((Bytes.toBytes("\\x00BC\\x00\\x00FG"), array([1, 0, 0, 1, 1, 0, 0],'b') ))
True
>>> fuzzyKeysData
[(array('b', [92, 120, 48, 48, 66, 67, 92, 120, 48, 48, 92, 120, 48, 48, 70, 71]), array('b', [1, 0, 0, 1, 1, 0, 0]))]
>>> filter = FuzzyRowFilter(fuzzyKeysData)
>>> scan.setFilter(filter)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
java.lang.ClassCastException: org.python.core.PyTuple cannot be cast to org.apache.hadoop.hbase.util.Pair
at org.apache.hadoop.hbase.filter.FuzzyRowFilter.toString(FuzzyRowFilter.java:158)
at org.apache.hadoop.hbase.client.Scan.toMap(Scan.java:600)
at org.apache.hadoop.hbase.client.Operation.toJSON(Operation.java:67)
at org.apache.hadoop.hbase.client.Operation.toString(Operation.java:93)
at org.apache.hadoop.hbase.client.Operation.toString(Operation.java:107)
at org.python.core.PyJavaType$7.__call__(PyJavaType.java:596)
at org.python.core.PyObjectDerived.__repr__(PyObjectDerived.java:63)
at org.python.core.PySystemState.displayhook(PySystemState.java:1284)
at org.python.core.PySystemStateFunctions.__call__(PySystemState.java:1478)
at org.python.core.PyObject.invoke(PyObject.java:3638)
at org.python.core.Py.printResult(Py.java:1841)
at org.python.pycode._pyx189.f$0(<stdin>:1)
at org.python.pycode._pyx189.call_function(<stdin>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1302)
at org.python.core.Py.exec(Py.java:1346)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:215)
at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:89)
at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:70)
at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:46)
at org.python.util.InteractiveConsole.push(InteractiveConsole.java:110)
at org.python.util.InteractiveConsole.interact(InteractiveConsole.java:90)
at org.python.util.jython.run(jython.java:378)
at org.python.util.jython.main(jython.java:137)

java.lang.ClassCastException: java.lang.ClassCastException: org.python.core.PyTuple cannot be cast to org.apache.hadoop.hbase.util.Pair


I think I can ignore the List<Pair<byte[], byte[]>> part as jython does it automatically for me (right?). Thoughts?

thanks!
liam




On Thu, Apr 24, 2014 at 12:39 PM, Alan Kennedy <jython-dev@xhaus.com> wrote:
To create such a byte[] in jython, for passing to java, use the jarray module.

http://www.jython.org/jythonbook/en/1.0/DataTypes.html#jython-specific-collections

Alan.


On Thu, Apr 24, 2014 at 8:32 PM, Liam Slusser <lslusser@gmail.com> wrote:

Hey All -

I've been working with jython and hbase for awhile but I'm having a problem converting this function into jython.

java example code:

Scan scan = new Scan();
List<Pair<byte[], byte[]>> fuzzyKeysData = new ArrayList<Pair<byte[],byte[]>>();
// search for "?BC??FG"
fuzzyKeysData.add(new Pair<byte[],byte[]>(Bytes.toBytes("\\x00BC\\x00\\x00FG"), new byte[]{1, 0, 0, 1, 1, 0, 0}));
FuzzyRowFilter filter = new FuzzyRowFilter(fuzzyKeysData);
scan.setFilter(filter);

I've figured out much of it, but i'm unable to get byte[] to work. Reading the jython docs byte[] should be treated as a string but i'm not exactly sure how to do that.

Could anybody help me out?

thanks!
liam

------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users




------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users