This is an automated email from the ASF dual-hosted git repository.
ianmcook pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-experiments.git
The following commit(s) were added to refs/heads/main by this push:
new 9ba7081 Add simple Ruby client example (#19)
9ba7081 is described below
commit 9ba708141ea0c3583d4f4e677c2edf470fe904ee
Author: Bryce Mecum <[email protected]>
AuthorDate: Thu Mar 14 15:12:06 2024 -0800
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]>
---
http/get_simple/ruby/client/.gitignore | 18 +++++++++++++++++
http/get_simple/ruby/client/Gemfile | 20 +++++++++++++++++++
http/get_simple/ruby/client/README.md | 35 ++++++++++++++++++++++++++++++++++
http/get_simple/ruby/client/client.rb | 33 ++++++++++++++++++++++++++++++++
4 files changed, 106 insertions(+)
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 @@
+<!---
+ 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.
+-->
+
+# 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)