1

I get some data from cassandra's jmx. one element is defined like this. https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java#L358

The returned type in Java is int[];

import xml.etree.ElementTree as xml
text = requests.get('http://:8081/mbean?objectname=org.apache.cassandra.db:type=xxx,keyspace=x,columnfamily=x&template=identity').text
x = xml.fromstring(text)
>>> for i in x:
...     if i.get('name') == 'SSTableCountPerLevel':
...             p=i

>>> p.items()
[('description', 'Attribute exposed for management'), ('aggregation', 'array'), ('value', '[I@48a6ea00'), ('isnull', 'false'), ('strinit', 'false'), ('type', '[I'), ('availability', 'RO'), ('name', 'SSTableCountPerLevel')]
>>> p.get('value')
'[I@48a6ea00'

So How can I convert this [I@48a6ea00 to a list of int in python?

@update 1:

Seems JPY is here for this purpose, but since the lack of document, I will try this and give a update soon.

https://github.com/bcdev/jpy

>>> import jpyutil
>>> jpyutil.init_jvm(jvm_maxmem='512M')
>>> import jpy
>>> b = jpy.array('int', [1,2,3])
>>> b.toString()
'[I@3f2a09d5'
>>> b
[I(objectRef=0x7fa66340dfe8)
>>> b[0]
1L
>>> b[2]
3L
>>> dir(b)
['__class__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__jinit__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'equals', 'getClass', 'hashCode', 'notify', 'notifyAll', 'toString', 'wait']

But I still can't convert string to Python List, which is I want.

@ conclusion:

Decode Java int array in python code should be possible if the python knows the content of java int array, but in the above case, [I@48a6ea00 is not the content of java int array, it is a memory reference to the java int array, so it is impossible.

I got this string via MX4J, I will check MX4J document to see how MX4j handle array.

@ update 2:

After checked the MX4J doucment, it is clearly stated with

Obviously it has some limitations, like not being able to manipulate data which cannot be obtained from Strings

At last, I used JYTHON, it resolves my issue perfectly.

3
  • 2
    [I@48a6ea00 is just a String Commented Jan 6, 2015 at 9:44
  • That looks like (though might not be) the internal representation of the array by the JVM. docs.oracle.com/javase/specs/jvms/se7/jvms7.pdf (Section 4.3) might shed some light on it. Though if I'm reading it right that just says: Single Dimension Array of Integers at address 0x48a6ea00... so you might not be able to get the actual contents from that string... So as others have mentioned, you might be dealing with bad data in the first place... Commented Jan 6, 2015 at 10:29
  • @LexyStardust, actually I get this data via MX4J (cassandra used this Java library to support some remote call), Do you mean [I@48a6ea00 just a address of the real array? if so, MX4J should be very bad designed here, I prefer to not believe that. Thank you very much for the pdf and a new direction. Commented Jan 7, 2015 at 0:54

2 Answers 2

1

Looks like somewhere the value is transform incorrectly to the reference to the array ( int[] ). Could you print the original response? i.e. text , and the xml, i.e. x to check which step goes wrong.

So the problem is the original response only return the internal descriptor of the array, '[I@48a6ea00' is the reference of that int array , it's a type@address format,only makes sense inside a particular JVM, it didn't carry the actual value information. i.e, no way to get the value as it is already lost in the response.

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

2 Comments

why do you think this value is incorrectly? I have no idea who to judge. Here is the raw text. <Attribute aggregation="array" availability="RO" description="Attribute exposed for management" isnull="false" name="SSTableCountPerLevel" strinit="false" type="[I" value="[I@78a1aae0"></Attribute>. (whole message is too long to be placed here)
So the problem is there, the original response only return the internal descriptor of the array, '[I@48a6ea00' is the reference of that int array , it's a type@address format, it only makes sense inside a particular JVM, it didn't carry the actually value information. i.e, no way to get the value as it is already lost in the response.
1

If you get the string '[I@48a6ea00' as response, then the one, who has written this int[] datatype into the database, has done something wrong. So it's too late for python or cassandra, to rescue the original numbers.

2 Comments

do you mean it is impossible to convert string into Python List or it is impossible to convert THIS string '[I@48a6ea00' to python List?
no one write this data to database. I got this string via MX4J (cassandra used this Java library to support some remote call to know the state for cassandra running)

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.