-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-40488: [Swift] Add simple get swift example #41
base: main
Are you sure you want to change the base?
Conversation
Thanks for doing this @abandy!
Could you also please add me ( |
Oh, I see now that this might not be possible, as discussed at apache/arrow#38872. Is there any available workaround that allows us to remove the vendored package? I have a strong preference not to have vendored libraries in these examples if it is at all possible. |
@abandy Here's a workaround that I think is better than vendoring the full Swift package here: We can just provide instructions in a readme file for how to install it locally by running a few simple shell commands. Would that work OK? |
@ianmcook No problem, glad I can help! I have added you as a collaborator. The workaround makes sense. I will remove the vendor package and add a README with instructions. I hope to get these changes up by EOW. |
Just a couple of questions if I may:
Amazing to see some progress on the Swift side, thanks! |
Yes, ultimately the plan is to move the examples that are in the |
Hi @shaps80, Good questions!
|
24d8832
to
2ec7957
Compare
@abandy thanks for that. Nice to hear we don't need any 3rd party dependencies 👍 (URLSession should suffice for 99% of cases these days) I agree it'd be much better to move to an isolated repo as currently we can't integrate with SPM. I'm currently working on an app for Geo where we need to store vast amounts of graph data and be able to query etc locally. So I'm keen to try Arrow for our needs, but I really need to get a better grasp of the concepts and the example so I'm not in a place to commit any contributions atm. But if I can work it out and grasp the ideas, I'd be keen to help out in the future. My main question atm, and I've love to get an example of this together myself, is how I can integrate with Arrow while still having idiomatic types that integrate well with SwiftUI. I don't have time this week to explore but hopefully next week I can spend some time on this. Thanks again! |
Hi @shaps80, thank you! If you have any questions in regards to Apache Arrow Swift or need any assistance with using the API just let me know! If you have time to contribute that would be awesome and even getting feedback on any issues you might have when using the API would be very useful. There is an Arrow Encoder and Decoder included in the Swift arrow repo that converts to and from a Swift object (there are restrictions on data types). This might help with moving data between Arrow and the UI. I have written an open source native Swift Apache Arrow Query Engine if you are looking to run SQL from Swift. It doesn't contain the full set of SQL functionality but it might be useful. It can be found here: https://github.com/abandy/swiftqe. (I am hoping to add subqueries by end of December) |
@abandy could you please split this example into a separate server (in |
Hi @ianmcook, gotcha, will do. I will try to get this update in by EOW. |
c422e9a
to
e7fbbfc
Compare
switch arrowWriter.toStream(writerInfo) { | ||
case .success(let writeData): | ||
print("sending recordBatchs: \(recordBatchs.count)") | ||
return ByteBuffer(data: writeData) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sets the Content-Type
response header to the appropriate value.
return ByteBuffer(data: writeData) | |
return .init( | |
status: .ok, headers: [.contentType: "application/vnd.apache.arrow.stream"], | |
body: .init(byteBuffer: buffer)) |
} | ||
|
||
let router = Router() | ||
router.get("/") { request, _ -> ByteBuffer in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other suggested change requires this change also.
router.get("/") { request, _ -> ByteBuffer in | |
router.get("/") { request, _ -> Response in |
@abandy thanks for splitting up the client and server. I am able to get the Swift client running with the Swift server. But when I try to run the Swift client with any of the other server examples, I see this error:
Could you please test this with one of the other server examples here? Thanks |
It seems like the response that the Swift server is serving is not a valid Arrow IPC stream. Here's what I tried to do:
curl -o file.arrows http://127.0.0.1:8081
import pyarrow as pa
with open('file.arrows', 'rb') as f:
reader = pa.ipc.open_stream(f)
reader.schema
reader.read_next_batch()
reader.read_next_batch() When I do this, PyArrow raises the error:
Do you know what's causing this? Thanks |
Hi Ian, It looks like the reader is failing while trying to read the schema from the footer. I believe the footer should always have a schema (AFAIK). Maybe a flatbuffer issue (I know Swift Arrow currently targets a specific version of flatbuffers as the latest was causing an issue, could be related(?)). I will look into this. |
I know there was an issue with the latest version of flatbuffers and Swift Arrow. Swift Arrow is bound to a specific version. Could be this is causing the issue. I will look into it. |
@ianmcook I have opened a bug in the apache repo for tracking this bug (apache/arrow#44910). I think we should be able to merge this PR and then follow up with the inconsistent behavior issue with the bug? |
--> | ||
|
||
# HTTP GET Arrow Data: Simple Swift Client Example | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> [!CAUTION] | |
> This Swift client example is compatible _only_ with the Swift server example. It is incompatible with all the other server examples in the `get_simple` directory of this repository. This is because of a problem in how the Swift Arrow package implements the Arrow IPC stream format (https://github.com/apache/arrow/issues/44910). | |
--> | ||
|
||
# HTTP GET Arrow Data: Simple Swift Server Example | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> [!CAUTION] | |
> This Swift server example is compatible _only_ with the Swift client example. It is incompatible with all the other client examples in the `get_simple` directory of this repository. This is because of a problem in how the Swift Arrow package implements the Arrow IPC stream format (https://github.com/apache/arrow/issues/44910). | |
My preference is to keep this open while you develop a fix for the bug. If you'd really like it to be merged, I'm OK with that provided that we can include the warnings I've suggested in the README files. |
@ianmcook sounds good. I have implemented a fix and am testing it now. I need to do some refactoring and hope to have a PR out in a couple of days. Thank you! |
This example uses Hummingbird for the http server and a URLSessionDataTask to pull the record batch down from the server.