Skip to content

Commit

Permalink
GH-44757: [GLib] Add garrow_array_validate()
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroyuki-sato committed Jan 22, 2025
1 parent c3f8b74 commit 9aa3eca
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 32 deletions.
32 changes: 16 additions & 16 deletions c_glib/arrow-glib/basic-array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions c_glib/arrow-glib/basic-array.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
29 changes: 17 additions & 12 deletions c_glib/test/test-array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down Expand Up @@ -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

0 comments on commit 9aa3eca

Please sign in to comment.