Skip to content

Commit

Permalink
GH-44758: [GLib] Add garrow_array_validate_full() (#45342)
Browse files Browse the repository at this point in the history
### Rationale for this change

[Array::ValidateFull](https://arrow.apache.org/docs/cpp/api/array.html#_CPPv4NK5arrow5Array12ValidateFullEv) 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: #44758

Authored-by: Hiroyuki Sato <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
  • Loading branch information
hiroyuki-sato authored Jan 24, 2025
1 parent f4a63d4 commit c6b6bfb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
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 @@ -1033,6 +1033,22 @@ garrow_array_validate(GArrowArray *array, GError **error)
return garrow::check(error, arrow_array->Validate(), "[array][validate]");
}

/**
* garrow_array_validate_full:
* @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_full(GArrowArray *array, GError **error)
{
const auto arrow_array = garrow_array_get_raw(array);
return garrow::check(error, arrow_array->ValidateFull(), "[array][validate_full]");
}

G_DEFINE_TYPE(GArrowNullArray, garrow_null_array, GARROW_TYPE_ARRAY)

static void
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 @@ -130,6 +130,10 @@ GARROW_AVAILABLE_IN_20_0
gboolean
garrow_array_validate(GArrowArray *array, GError **error);

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

#define GARROW_TYPE_NULL_ARRAY (garrow_null_array_get_type())
GARROW_AVAILABLE_IN_ALL
G_DECLARE_DERIVABLE_TYPE(
Expand Down
26 changes: 26 additions & 0 deletions c_glib/test/test-array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,30 @@ def test_invalid
end
end
end

sub_test_case("#validate_full") do
def test_valid
array = build_int32_array([1, 2, 3, 4, 5])
assert do
array.validate_full
end
end

def test_invalid
message = "[array][validate_full]: Invalid: Invalid UTF8 sequence at string index 0"

# U+3042 HIRAGANA LETTER A, U+3044 HIRAGANA LETTER I
data = "\u3042\u3044".b[0..-2]
value_offsets = Arrow::Buffer.new([0, data.size].pack("l*"))
array = Arrow::StringArray.new(1,
value_offsets,
Arrow::Buffer.new(data),
Arrow::Buffer.new([0b01].pack("C*")),
-1)

assert_raise(Arrow::Error::Invalid.new(message)) do
array.validate_full
end
end
end
end

0 comments on commit c6b6bfb

Please sign in to comment.