Skip to content

Commit 3a3f2ec

Browse files
GH-44757: [GLib] Add garrow_array_validate() (#45328)
### Rationale for this change [Array::Validate](https://arrow.apache.org/docs/cpp/api/array.html#_CPPv4NK5arrow5Array8ValidateEv) available in the C++ API. But, GLib doesn't support that method yet. ### What changes are included in this PR? This PR adds a validation method in the array class. ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes. * GitHub Issue: #44757 Authored-by: Hiroyuki Sato <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent f8f17a5 commit 3a3f2ec

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

c_glib/arrow-glib/basic-array.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,22 @@ garrow_array_concatenate(GArrowArray *array, GList *other_arrays, GError **error
10171017
}
10181018
}
10191019

1020+
/**
1021+
* garrow_array_validate:
1022+
* @array: A #GArrowArray.
1023+
* @error: (nullable): Return location for a #GError or %NULL.
1024+
*
1025+
* Returns: %TRUE on success, %FALSE on error.
1026+
*
1027+
* Since: 20.0.0
1028+
*/
1029+
gboolean
1030+
garrow_array_validate(GArrowArray *array, GError **error)
1031+
{
1032+
const auto arrow_array = garrow_array_get_raw(array);
1033+
return garrow::check(error, arrow_array->Validate(), "[array][validate]");
1034+
}
1035+
10201036
G_DEFINE_TYPE(GArrowNullArray, garrow_null_array, GARROW_TYPE_ARRAY)
10211037

10221038
static void

c_glib/arrow-glib/basic-array.h

+4
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ GARROW_AVAILABLE_IN_4_0
126126
GArrowArray *
127127
garrow_array_concatenate(GArrowArray *array, GList *other_arrays, GError **error);
128128

129+
GARROW_AVAILABLE_IN_20_0
130+
gboolean
131+
garrow_array_validate(GArrowArray *array, GError **error);
132+
129133
#define GARROW_TYPE_NULL_ARRAY (garrow_null_array_get_type())
130134
GARROW_AVAILABLE_IN_ALL
131135
G_DECLARE_DERIVABLE_TYPE(

c_glib/test/test-array.rb

+17
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,21 @@ def test_mixed_type
185185
end
186186
end
187187
end
188+
189+
sub_test_case("#validate") do
190+
def test_valid
191+
array = build_int32_array([1, 2, 3, 4, 5])
192+
assert do
193+
array.validate
194+
end
195+
end
196+
197+
def test_invalid
198+
message = "[array][validate]: Invalid: Array length is negative"
199+
array = Arrow::Int8Array.new(-1, Arrow::Buffer.new(""), Arrow::Buffer.new(""), -1)
200+
assert_raise(Arrow::Error::Invalid.new(message)) do
201+
array.validate
202+
end
203+
end
204+
end
188205
end

0 commit comments

Comments
 (0)