• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..01-Jun-2020-

dependency-check/H01-Jun-2020-4439

lib/H01-Jun-2020-807392

test/H01-Jun-2020-248117

.gitignoreH A D01-Jun-2020792 1917

GemfileH A D01-Jun-2020882 2521

README.mdH A D01-Jun-20202.7 KiB6933

RakefileH A D01-Jun-20201.2 KiB4235

red-gandiva.gemspecH A D01-Jun-20201.9 KiB5044

README.md

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# Red Gandiva - Gandiva Ruby
21
22Red Gandiva is the Ruby bindings of Gandiva. Red Gandiva is based on GObject Introspection.
23
24Gandiva is a toolset for compiling and evaluating expressions on Arrow data.
25
26[GObject Introspection](https://wiki.gnome.org/action/show/Projects/GObjectIntrospection) is a middleware for language bindings of C library. GObject Introspection can generate language bindings automatically at runtime.
27
28Red Gandiva uses [Gandiva GLib](https://github.com/apache/arrow/tree/master/c_glib/gandiva-glib) and [gobject-introspection gem](https://rubygems.org/gems/gobject-introspection) to generate Ruby bindings of Gandiva.
29
30Gandiva GLib is a C wrapper for [Gandiva C++](https://github.com/apache/arrow/tree/master/cpp/gandiva). GObject Introspection can't use Gandiva C++ directly. Gandiva GLib is a bridge between Gandiva C++ and GObject Introspection.
31
32gobject-introspection gem is a Ruby bindings of GObject Introspection. Red Gandiva uses GObject Introspection via gobject-introspection gem.
33
34## Install
35
36Install Gandiva GLib before install Red Gandiva. See [Apache Arrow install document](https://arrow.apache.org/install/) for details.
37
38Install Red Gandiva after you install Gandiva GLib:
39
40```text
41% gem install red-gandiva
42```
43
44## Usage
45
46```ruby
47require "gandiva"
48
49table = Arrow::Table.new(:field1 => Arrow::Int32Array.new([1, 2, 3, 4]),
50                         :field2 => Arrow::Int32Array.new([11, 13, 15, 17]))
51schema = table.schema
52
53expression1 = schema.build_expression do |record|
54  record.field1 + record.field2
55end
56
57expression2 = schema.build_expression do |record, context|
58  context.if(record.field1 > record.field2)
59    .then(record.field1 / record.field2)
60    .else(record.field1)
61end
62
63projector = Gandiva::Projector.new(schema, [expression1, expression2])
64table.each_record_batch do |record_batch|
65  outputs = projector.evaluate(record_batch)
66  puts outputs.collect(&:values))
67end
68```
69