zeroshade commented on pull request #11037:
URL: https://github.com/apache/arrow/pull/11037#issuecomment-911915670
@pitrou I'm rather happy with myself at the moment since I've managed to
actually pull your suggestion off, though i'm not sure the best way to actually
incorporate such a test into the current build system. For posterity, here's
some snippets showing what I did:
Created a go file with the following:
```go
package main
import (
"fmt"
"unsafe"
"github.com/apache/arrow/go/arrow/cdata"
)
// #include <stdint.h>
import "C"
//export importSchema
func importSchema(ptr C.uintptr_t) {
sc := (*cdata.CArrowSchema)(unsafe.Pointer(uintptr(ptr)))
fmt.Println(cdata.ImportCArrowSchema(sc))
}
func main() {}
```
In order to build a c-shared library it apparently needs to be a main
package. Anyway, the above file will export a function "importSchema" which
takes a uintptr_t which is a pointer to an `struct ArrowSchema`. Running the
command `go build -buildmode=c-shared -o gotest.dll .` if on windows or using
`gotest.so` for linux. Then in python I did the following:
```python
>>> import pyarrow as pa
>>> from pyarrow.cffi import ffi
>>> c_schema = ffi.new("struct ArrowSchema*")
>>> ptr_schema = int(ffi.cast("uintptr_t", c_schema))
>>> pa.schema([('ints', pa.list_(pa.int32()))], metadata={b'key1':
b'value1'})._export_to_c(ptr_schema)
>>> from ctypes import *
>>> gotest = cdll.LoadLibrary('gotest.dll') # or gotest.so
>>> gotest.importSchema(c_ulonglong(ptr_schema))
schema:
fields: 1
- ints: type=list<item: int32>, nullable
metadata: ["key1": "value1"]
0
```
So all in all, really cool. But I don't know where in the tests would make
sense for how I should incorporate such a test where I build the go dynamic lib
and then run the a python script with pyarrow to call the function. Any ideas?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]