Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-44757: [GLib] Add garrow_array_validate() #45328

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions c_glib/arrow-glib/basic-array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3316,6 +3316,22 @@ garrow_decimal256_array_get_value(GArrowDecimal256Array *array, gint64 i)
return garrow_decimal256_new_raw(&arrow_decimal256);
}

/**
* garrow_array_validate:
* @array: A #GArrowArray.
* @error: (nullable): Return location for a #GError or %NULL.
*
* Returns: %TRUE on success, %FALSE on error.
*
* Since: 20.0.0
*/
gboolean
garrow_array_validate(GArrowArray *array, GError **error)
{
const auto arrow_array = garrow_array_get_raw(array);
return garrow::check(error, arrow_array->Validate(), "[array][validate]");
}

typedef struct GArrowExtensionArrayPrivate_
{
GArrowArray *storage;
Expand Down
4 changes: 4 additions & 0 deletions c_glib/arrow-glib/basic-array.h
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,10 @@ GARROW_AVAILABLE_IN_ALL
GArrowDecimal256 *
garrow_decimal256_array_get_value(GArrowDecimal256Array *array, gint64 i);

GARROW_AVAILABLE_IN_20_0
gboolean
garrow_array_validate(GArrowArray *array, GError **error);

GARROW_AVAILABLE_IN_3_0
GArrowArray *
garrow_extension_array_get_storage(GArrowExtensionArray *array);
Expand Down
12 changes: 12 additions & 0 deletions c_glib/test/test-array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ def test_to_s
CONTENT
end

def test_validation_success
array = build_int32_array([1, 2, 3, 4, 5])
assert_equal(true, array.validate)
end

def test_validation_fail
array = Arrow::Int8Array.new(-1, Arrow::Buffer.new(""), Arrow::Buffer.new(""), -1)
assert_raise(Arrow::Error::Invalid) do
array.validate
end
end

sub_test_case("#view") do
def test_valid
assert_equal(build_float_array([0.0, 1.5, -2.5, nil]),
Expand Down
Loading