Skip to content

Commit

Permalink
GH-44760: [GLib] Add garrow_record_batch_validate_full()
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroyuki-sato committed Jan 30, 2025
1 parent 4408e2b commit 26eecda
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
18 changes: 18 additions & 0 deletions c_glib/arrow-glib/record-batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,24 @@ garrow_record_batch_validate(GArrowRecordBatch *record_batch, GError **error)
return garrow::check(error, arrow_record_batch->Validate(), "[record-batch][validate]");
}

/**
* garrow_record_batch_validate_full
* @record_batch: A #GArrowRecordBatch
* @error: (nullable): Return location for a #GError or %NULL.
*
* Returns: %TRUE on success, %FALSE on error.
*
* Since: 20.0.0
*/
gboolean
garrow_record_batch_validate_full(GArrowRecordBatch *record_batch, GError **error)
{
const auto arrow_record_batch = garrow_record_batch_get_raw(record_batch);
return garrow::check(error,
arrow_record_batch->ValidateFull(),
"[record-batch][validate_full]");
}

typedef struct GArrowRecordBatchIteratorPrivate_
{
arrow::RecordBatchIterator iterator;
Expand Down
4 changes: 4 additions & 0 deletions c_glib/arrow-glib/record-batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ GARROW_AVAILABLE_IN_20_0
gboolean
garrow_record_batch_validate(GArrowRecordBatch *record_batch, GError **error);

GARROW_AVAILABLE_IN_20_0
gboolean
garrow_record_batch_validate_full(GArrowRecordBatch *record_batch, GError **error);

#define GARROW_TYPE_RECORD_BATCH_ITERATOR (garrow_record_batch_iterator_get_type())
GARROW_AVAILABLE_IN_0_17
G_DECLARE_DERIVABLE_TYPE(GArrowRecordBatchIterator,
Expand Down
39 changes: 39 additions & 0 deletions c_glib/test/test-record-batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,44 @@ def test_invalid
end
end
end

sub_test_case("#validate_full") do
def setup
@id_field = Arrow::Field.new("uint8", Arrow::UInt8DataType.new)
@name_field = Arrow::Field.new("string", Arrow::StringDataType.new)
@schema = Arrow::Schema.new([@id_field, @name_field])

@uint8_value = build_uint_array([1])
@valid_name_value = build_string_array(["abc"])
@n_rows = @uint8_value.length

# 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*"))
@invalid_name_value = Arrow::StringArray.new(1,
value_offsets,
Arrow::Buffer.new(data),
nil,
-1)
end

def test_valid
record_batch = Arrow::RecordBatch.new(@schema, @n_rows, [@uint8_value, @valid_name_value])

assert do
record_batch.validate_full
end
end

def test_invalid
message = "[record-batch][validate_full]: Invalid: " +
"In column 1: Invalid: Invalid UTF8 sequence at string index 0"
record_batch = Arrow::RecordBatch.new(@schema, @n_rows, [@uint8_value, @invalid_name_value])

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

0 comments on commit 26eecda

Please sign in to comment.