Skip to content

Commit 9ba7081

Browse files
amoebakouianmcook
authored
Add simple Ruby client example (#19)
* Add Ruby client example * Update http/get_simple/ruby/client/README.md * Fix streaming example * Delete Gemfile.lock * Create .gitignore * Update http/get_simple/ruby/client/client.rb Co-authored-by: Sutou Kouhei <[email protected]> * Update http/get_simple/ruby/client/client.rb Co-authored-by: Sutou Kouhei <[email protected]> * Update http/get_simple/ruby/client/client.rb Co-authored-by: Sutou Kouhei <[email protected]> * Update http/get_simple/ruby/client/.gitignore Co-authored-by: Sutou Kouhei <[email protected]> * Update http/get_simple/ruby/client/client.rb Co-authored-by: Sutou Kouhei <[email protected]> * Clean up client example * Update http/get_simple/ruby/client/README.md Co-authored-by: Ian Cook <[email protected]> --------- Co-authored-by: Sutou Kouhei <[email protected]> Co-authored-by: Ian Cook <[email protected]>
1 parent d3ef5dc commit 9ba7081

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
/Gemfile.lock

http/get_simple/ruby/client/Gemfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
source "https://rubygems.org"
19+
20+
gem "red-arrow"

http/get_simple/ruby/client/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!---
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# HTTP GET Arrow Data: Simple Ruby Client Example
21+
22+
This directory contains a minimal example of an HTTP client implemented in Ruby.
23+
24+
The client:
25+
26+
1. Sends an HTTP GET request to a server.
27+
2. Receives an HTTP 200 response from the server, with the response body containing an Arrow IPC stream of record batches.
28+
3. Creates an Arrow table from the record batches.
29+
30+
To run this example, first start one of the server examples in the parent directory, then:
31+
32+
```sh
33+
bundle install
34+
bundle exec ruby client.rb
35+
```

http/get_simple/ruby/client/client.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require "net/http"
19+
require "arrow"
20+
21+
uri = URI("http://localhost:8008")
22+
23+
start = Time.now
24+
arrows_data = Net::HTTP.get(uri)
25+
input = Arrow::BufferInputStream.new(arrows_data)
26+
reader = Arrow::RecordBatchStreamReader.new(input)
27+
schema = reader.schema
28+
table = reader.read_all
29+
elapsed_time = Time.now - start
30+
31+
n_received_record_batches = table[0].data.n_chunks
32+
puts("#{n_received_record_batches} record batches received")
33+
puts("%.2f seconds elapsed" % elapsed_time)

0 commit comments

Comments
 (0)