summaryrefslogtreecommitdiffstats
path: root/src/arrow/ruby/red-arrow-dataset/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/arrow/ruby/red-arrow-dataset/test')
-rw-r--r--src/arrow/ruby/red-arrow-dataset/test/helper.rb22
-rwxr-xr-xsrc/arrow/ruby/red-arrow-dataset/test/run-test.rb50
-rw-r--r--src/arrow/ruby/red-arrow-dataset/test/test-arrow-table.rb80
-rw-r--r--src/arrow/ruby/red-arrow-dataset/test/test-file-system-dataset.rb38
4 files changed, 190 insertions, 0 deletions
diff --git a/src/arrow/ruby/red-arrow-dataset/test/helper.rb b/src/arrow/ruby/red-arrow-dataset/test/helper.rb
new file mode 100644
index 000000000..7231eb1cb
--- /dev/null
+++ b/src/arrow/ruby/red-arrow-dataset/test/helper.rb
@@ -0,0 +1,22 @@
+# 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 "arrow-dataset"
+
+require "tmpdir"
+
+require "test-unit"
diff --git a/src/arrow/ruby/red-arrow-dataset/test/run-test.rb b/src/arrow/ruby/red-arrow-dataset/test/run-test.rb
new file mode 100755
index 000000000..48d2c49e1
--- /dev/null
+++ b/src/arrow/ruby/red-arrow-dataset/test/run-test.rb
@@ -0,0 +1,50 @@
+#!/usr/bin/env ruby
+#
+# 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.
+
+$VERBOSE = true
+
+require "pathname"
+
+(ENV["ARROW_DLL_PATH"] || "").split(File::PATH_SEPARATOR).each do |path|
+ RubyInstaller::Runtime.add_dll_directory(path)
+end
+
+base_dir = Pathname.new(__dir__).parent.expand_path
+arrow_base_dir = base_dir.parent + "red-arrow"
+
+lib_dir = base_dir + "lib"
+test_dir = base_dir + "test"
+
+arrow_lib_dir = arrow_base_dir + "lib"
+arrow_ext_dir = arrow_base_dir + "ext" + "arrow"
+
+build_dir = ENV["BUILD_DIR"]
+if build_dir
+ arrow_build_dir = Pathname.new(build_dir) + "red-arrow"
+else
+ arrow_build_dir = arrow_ext_dir
+end
+
+$LOAD_PATH.unshift(arrow_build_dir.to_s)
+$LOAD_PATH.unshift(arrow_lib_dir.to_s)
+$LOAD_PATH.unshift(lib_dir.to_s)
+
+require_relative "helper"
+
+exit(Test::Unit::AutoRunner.run(true, test_dir.to_s))
diff --git a/src/arrow/ruby/red-arrow-dataset/test/test-arrow-table.rb b/src/arrow/ruby/red-arrow-dataset/test/test-arrow-table.rb
new file mode 100644
index 000000000..191306374
--- /dev/null
+++ b/src/arrow/ruby/red-arrow-dataset/test/test-arrow-table.rb
@@ -0,0 +1,80 @@
+# 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.
+
+class TestArrowTable < Test::Unit::TestCase
+ def setup
+ Dir.mktmpdir do |tmpdir|
+ @dir = tmpdir
+ @path1 = File.join(@dir, "data", "table1.arrow")
+ @table1 = Arrow::Table.new(visible: [true, false, true],
+ point: [1, 2, 3])
+ @path2 = File.join(@dir, "data", "table2.arrow")
+ @table2 = Arrow::Table.new(visible: [true],
+ point: [10])
+ yield
+ end
+ end
+
+ def build_file_uri(path)
+ absolute_path = File.expand_path(path)
+ if absolute_path.start_with?("/")
+ URI("file://#{absolute_path}")
+ else
+ URI("file:///#{absolute_path}")
+ end
+ end
+
+ sub_test_case("load") do
+ def test_no_scheme
+ Dir.chdir(@dir) do
+ uri = URI(File.basename(@path1))
+ @table1.save(uri)
+ assert_equal(@table1, Arrow::Table.load(uri))
+ end
+ end
+
+ def test_file
+ uri = build_file_uri(@path1)
+ @table1.save(uri)
+ assert_equal(@table1, Arrow::Table.load(uri))
+ end
+
+ def test_directory_uri
+ uri = build_file_uri(@dir)
+ @table1.save(build_file_uri(@path1))
+ @table2.save(build_file_uri(@path2))
+ assert_equal(@table1.concatenate([@table2]),
+ Arrow::Table.load(uri))
+ end
+
+ def test_directory_path
+ @table1.save(build_file_uri(@path1))
+ @table2.save(build_file_uri(@path2))
+ assert_equal(@table1.concatenate([@table2]),
+ Arrow::Table.load(@dir))
+ end
+
+ def test_filter
+ @table1.save(build_file_uri(@path1))
+ @table2.save(build_file_uri(@path2))
+ assert_equal(Arrow::Table.new(visible: [true, true, true],
+ point: [1, 3, 10]),
+ Arrow::Table.load(@dir,
+ filter: ["equal", :visible, true]))
+ end
+ end
+end
diff --git a/src/arrow/ruby/red-arrow-dataset/test/test-file-system-dataset.rb b/src/arrow/ruby/red-arrow-dataset/test/test-file-system-dataset.rb
new file mode 100644
index 000000000..17cbcb88d
--- /dev/null
+++ b/src/arrow/ruby/red-arrow-dataset/test/test-file-system-dataset.rb
@@ -0,0 +1,38 @@
+# 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.
+
+class TestFileSystemDataset < Test::Unit::TestCase
+ def setup
+ Dir.mktmpdir do |tmpdir|
+ @dir = tmpdir
+ @path = File.join(@dir, "table.arrow")
+ @table = Arrow::Table.new(visible: [true, false, true],
+ point: [1, 2, 3])
+ @table.save(@path)
+ @format = ArrowDataset::IPCFileFormat.new
+ yield
+ end
+ end
+
+ test(".build") do
+ dataset = ArrowDataset::FileSystemDataset.build(@format) do |factory|
+ factory.file_system = Arrow::LocalFileSystem.new
+ factory.add_path(File.expand_path(@path))
+ end
+ assert_equal(@table, dataset.to_table)
+ end
+end