U ŸDx`y%ć@sndZddlZGdd„dƒZdd„Zdd„Zd d „Zd d „Zd d„Zdd„Z dd„Z dd„Z dd„Z dd„Z dS)a‹ Functions to interact with Arrow memory allocated by Arrow Java. These functions convert the objects holding the metadata, the actual data is not copied at all. This will only work with a JVM running in the same process such as provided through jpype. Modules that talk to a remote JVM like py4j will not work as the memory addresses reported by them are not reachable in the python process. éNc@s$eZdZdZdZdd„Zdd„ZdS)Ś_JvmBufferNannyz` An object that keeps a org.apache.arrow.memory.ArrowBuf's underlying memory alive. NcCs| ”}| ”||_dS©N)ZgetReferenceManagerZretainŚ ref_manager)ŚselfŚjvm_bufr©rś2/tmp/pip-target-oguziej0/lib/python/pyarrow/jvm.pyŚ__init__&sz_JvmBufferNanny.__init__cCs|jdk r|j ”dSr)rŚrelease)rrrrŚ__del__.s z_JvmBufferNanny.__del__)Ś__name__Ś __module__Ś __qualname__Ś__doc__rr r rrrrrsrcCs(t|ƒ}| ”}| ”}tj|||dS)a) Construct an Arrow buffer from org.apache.arrow.memory.ArrowBuf Parameters ---------- jvm_buf: org.apache.arrow.memory.ArrowBuf Arrow Buffer representation on the JVM. Returns ------- pyarrow.Buffer Python Buffer that references the JVM memory. )Śbase)rZ memoryAddressŚcapacityŚpaZforeign_buffer)rZnannyŚaddressŚsizerrrŚ jvm_buffer3srcCs–| ”}| ”rR|dkr t ”S|dkr0t ”S|dkr@t ”S|dkr’t ”Sn@|dkrbt ”S|dkrrt ”S|dkr‚t  ”S|dkr’t  ”SdS)zĶ Convert a JVM int type to its Python equivalent. Parameters ---------- jvm_type : org.apache.arrow.vector.types.pojo.ArrowType$Int Returns ------- typ : pyarrow.DataType ééé é@N) Ś getBitWidthZ getIsSignedrZint8Śint16Śint32Śint64Zuint8Zuint16Zuint32Zuint64)Śjvm_typeZ bit_widthrrrŚ_from_jvm_int_typeHs$  rcCs@| ” ”}|dkrt ”S|dkr,t ”S|dkržs’ zfield..)r3ŚgetNameŚgetTypeŚ isComplexZ getTypeIDr!rŚnullrr%ŚstringŚbinaryZ getByteWidthZbool_r1r6r7Z decimal128r ZgetScaleŚNotImplementedErrorŚformatZ isNullableZ getMetadataŚisEmptyŚentrySetŚfield)Z jvm_fieldŚnamerŚtypZtype_strZnullableŚ jvm_metadataŚmetadatarrrrLĒsR             ’’ ’rLcCsJ| ”}dd„|Dƒ}| ”}| ”r,d}ndd„| ”Dƒ}t ||”S)zą Construct a Schema from a org.apache.arrow.vector.types.pojo.Schema instance. Parameters ---------- jvm_schema: org.apache.arrow.vector.types.pojo.Schema Returns ------- pyarrow.Schema cSsg|] }t|ƒ‘qSr)rL)r?ŚfrrrŚ szschema..NcSs"i|]}t| ”ƒt| ”ƒ“qSrr<r>rrrrAs’ zschema..)Z getFieldsZgetCustomMetadatarJrKrŚschema)Z jvm_schemaŚfieldsrOrPrrrrSs ’rScCsŒ| ” ” ”r*| ” ”}td |”ƒ‚t| ”ƒj}dd„t |  d”ƒDƒ}t |ƒdkrjt j g|dS| ”}| ”}t j ||||”S)z¼ Construct an (Python) Array from its JVM equivalent. Parameters ---------- jvm_array : org.apache.arrow.vector.ValueVector Returns ------- array : Array zMCannot convert JVM Arrow array of type {}, complex types not yet implemented.cSsg|] }t|ƒ‘qSr)r)r?ŚbufrrrrR-s’zarray..Fr)Śtype)ZgetFieldrCrDZ getMinorTyper!rHrIrLrVŚlistZ getBuffersŚlenrŚarrayZ getValueCountZ getNullCountŚArrayZ from_buffers)Z jvm_arrayZminor_type_strZdtypeŚbuffersŚlengthZ null_countrrrrYs  ’’ ’ rYcCsFt| ”ƒ}g}|jD]}| t| |”ƒ”qtjj||j|j dS)zź Construct a (Python) RecordBatch from a JVM VectorSchemaRoot Parameters ---------- jvm_vector_schema_root : org.apache.arrow.vector.VectorSchemaRoot Returns ------- record_batch: pyarrow.RecordBatch )rP) rSZ getSchemaŚnamesŚappendrYZ getVectorrZ RecordBatchZ from_arraysrP)Zjvm_vector_schema_rootZ pa_schemaZarraysrMrrrŚ record_batch9s  żr_)rZpyarrowrrrrr%r1r6r7rLrSrYr_rrrrŚs "<