Skip to content

Commit e32f56b

Browse files
hiroyuki-satokou
andauthored
GH-44762: [GLib] Add garrow_table_validate_full() (#45468)
### Rationale for this change [Table::ValidateFull](https://arrow.apache.org/docs/cpp/api/table.html#_CPPv4NK5arrow5Table12ValidateFullEv) available in the C++ API. But, GLib doesn't support that method yet. ### What changes are included in this PR? This PR adds a full validation method to the table class. ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes. * GitHub Issue: #44762 Lead-authored-by: Hiroyuki Sato <hiroysato@gmail.com> Co-authored-by: Sutou Kouhei <kou@cozmixng.org> Signed-off-by: Sutou Kouhei <kou@clear-code.com>
1 parent d77e559 commit e32f56b

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

c_glib/arrow-glib/table.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,24 @@ garrow_table_validate(GArrowTable *table, GError **error)
754754
return garrow::check(error, arrow_table->Validate(), "[table][validate]");
755755
}
756756

757+
/**
758+
* garrow_table_validate_full
759+
* @table: A #GArrowTable
760+
* @error: (nullable): Return location for a #GError or %NULL.
761+
*
762+
* Validate the given table. This is an extensive validation.
763+
*
764+
* Returns: %TRUE on success, %FALSE on error.
765+
*
766+
* Since: 20.0.0
767+
*/
768+
gboolean
769+
garrow_table_validate_full(GArrowTable *table, GError **error)
770+
{
771+
const auto arrow_table = garrow_table_get_raw(table);
772+
return garrow::check(error, arrow_table->ValidateFull(), "[table][validate-full]");
773+
}
774+
757775
typedef struct GArrowFeatherWritePropertiesPrivate_
758776
{
759777
arrow::ipc::feather::WriteProperties properties;

c_glib/arrow-glib/table.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ GARROW_AVAILABLE_IN_20_0
146146
gboolean
147147
garrow_table_validate(GArrowTable *table, GError **error);
148148

149+
GARROW_AVAILABLE_IN_20_0
150+
gboolean
151+
garrow_table_validate_full(GArrowTable *table, GError **error);
152+
149153
#define GARROW_TYPE_FEATHER_WRITE_PROPERTIES (garrow_feather_write_properties_get_type())
150154
GARROW_AVAILABLE_IN_0_17
151155
G_DECLARE_DERIVABLE_TYPE(GArrowFeatherWriteProperties,

c_glib/test/test-table.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,46 @@ def test_invalid
274274
end
275275
end
276276

277+
sub_test_case("#validate_full") do
278+
def setup
279+
@id_field = Arrow::Field.new("uint8", Arrow::UInt8DataType.new)
280+
@name_field = Arrow::Field.new("string", Arrow::StringDataType.new)
281+
@schema = Arrow::Schema.new([@id_field, @name_field])
282+
283+
@id_values = build_uint_array([1])
284+
@valid_name_values = build_string_array(["abc"])
285+
286+
# U+3042 HIRAGANA LETTER A, U+3044 HIRAGANA LETTER I
287+
data = "\u3042\u3044".b[0..-2]
288+
value_offsets = Arrow::Buffer.new([0, data.size].pack("l*"))
289+
@invalid_name_values = Arrow::StringArray.new(1,
290+
value_offsets,
291+
Arrow::Buffer.new(data),
292+
nil,
293+
-1)
294+
end
295+
296+
def test_valid
297+
columns = [@id_values, @valid_name_values]
298+
table = Arrow::Table.new(@schema, columns)
299+
300+
assert do
301+
table.validate_full
302+
end
303+
end
304+
305+
def test_invalid
306+
message = "[table][validate-full]: Invalid: " +
307+
"Column 1: In chunk 0: Invalid: Invalid UTF8 sequence at string index 0"
308+
columns = [@id_values, @invalid_name_values]
309+
table = Arrow::Table.new(@schema, columns)
310+
311+
assert_raise(Arrow::Error::Invalid.new(message)) do
312+
table.validate_full
313+
end
314+
end
315+
end
316+
277317
sub_test_case("#write_as_feather") do
278318
def setup
279319
super

0 commit comments

Comments
 (0)