diff --git a/http/get_simple/ruby/client/.gitignore b/http/get_simple/ruby/client/.gitignore new file mode 100644 index 0000000..f07a468 --- /dev/null +++ b/http/get_simple/ruby/client/.gitignore @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +/Gemfile.lock diff --git a/http/get_simple/ruby/client/Gemfile b/http/get_simple/ruby/client/Gemfile new file mode 100644 index 0000000..3b8f9e6 --- /dev/null +++ b/http/get_simple/ruby/client/Gemfile @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +source "https://rubygems.org" + +gem "red-arrow" diff --git a/http/get_simple/ruby/client/README.md b/http/get_simple/ruby/client/README.md new file mode 100644 index 0000000..5ae8d30 --- /dev/null +++ b/http/get_simple/ruby/client/README.md @@ -0,0 +1,35 @@ + + +# HTTP GET Arrow Data: Simple Ruby Client Example + +This directory contains a minimal example of an HTTP client implemented in Ruby. + +The client: + +1. Sends an HTTP GET request to a server. +2. Receives an HTTP 200 response from the server, with the response body containing an Arrow IPC stream of record batches. +3. Creates an Arrow table from the record batches. + +To run this example, first start one of the server examples in the parent directory, then: + +```sh +bundle install +bundle exec ruby client.rb +``` diff --git a/http/get_simple/ruby/client/client.rb b/http/get_simple/ruby/client/client.rb new file mode 100644 index 0000000..a608bb5 --- /dev/null +++ b/http/get_simple/ruby/client/client.rb @@ -0,0 +1,33 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require "net/http" +require "arrow" + +uri = URI("http://localhost:8008") + +start = Time.now +arrows_data = Net::HTTP.get(uri) +input = Arrow::BufferInputStream.new(arrows_data) +reader = Arrow::RecordBatchStreamReader.new(input) +schema = reader.schema +table = reader.read_all +elapsed_time = Time.now - start + +n_received_record_batches = table[0].data.n_chunks +puts("#{n_received_record_batches} record batches received") +puts("%.2f seconds elapsed" % elapsed_time)