diff --git a/c_glib/arrow-glib/basic-array.cpp b/c_glib/arrow-glib/basic-array.cpp index 43b2737b6f09b..3a7bdfa2760ca 100644 --- a/c_glib/arrow-glib/basic-array.cpp +++ b/c_glib/arrow-glib/basic-array.cpp @@ -1017,6 +1017,22 @@ garrow_array_concatenate(GArrowArray *array, GList *other_arrays, GError **error } } +/** + * 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]"); +} + G_DEFINE_TYPE(GArrowNullArray, garrow_null_array, GARROW_TYPE_ARRAY) static void @@ -3316,22 +3332,6 @@ 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; diff --git a/c_glib/arrow-glib/basic-array.h b/c_glib/arrow-glib/basic-array.h index a661c3f5f89ef..0f068a0bee9e4 100644 --- a/c_glib/arrow-glib/basic-array.h +++ b/c_glib/arrow-glib/basic-array.h @@ -126,6 +126,10 @@ GARROW_AVAILABLE_IN_4_0 GArrowArray * garrow_array_concatenate(GArrowArray *array, GList *other_arrays, GError **error); +GARROW_AVAILABLE_IN_20_0 +gboolean +garrow_array_validate(GArrowArray *array, GError **error); + #define GARROW_TYPE_NULL_ARRAY (garrow_null_array_get_type()) GARROW_AVAILABLE_IN_ALL G_DECLARE_DERIVABLE_TYPE( @@ -890,10 +894,6 @@ 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); diff --git a/c_glib/test/test-array.rb b/c_glib/test/test-array.rb index 03ddd593fc427..107730a1aa645 100644 --- a/c_glib/test/test-array.rb +++ b/c_glib/test/test-array.rb @@ -116,18 +116,6 @@ 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]), @@ -197,4 +185,21 @@ def test_mixed_type end end end + + sub_test_case("#validate") do + def test_valid + array = build_int32_array([1, 2, 3, 4, 5]) + assert do + array.validate + end + end + + def test_invalid + message = "[array][validate]: Invalid: Array length is negative" + array = Arrow::Int8Array.new(-1, Arrow::Buffer.new(""), Arrow::Buffer.new(""), -1) + assert_raise(Arrow::Error::Invalid.new(message)) do + array.validate + end + end + end end