MCPcopy Create free account
hub / github.com/apache/arrow / ASSERT_OK_AND_ASSIGN

Function ASSERT_OK_AND_ASSIGN

cpp/src/arrow/record_batch_test.cc:429–655  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

427 AssertBatchesEqual(*new_batch, *batch2);
428
429 ASSERT_OK_AND_ASSIGN(auto new_batch2, batch.AddColumn(1, "f3", array3));
430 AssertBatchesEqual(*new_batch2, *new_batch);
431
432 ASSERT_TRUE(new_batch2->schema()->field(1)->nullable());
433}
434
435TEST_F(TestRecordBatch, SetColumn) {
436 const int length = 10;
437
438 auto field1 = field("f1", int32());
439 auto field2 = field("f2", uint8());
440 auto field3 = field("f3", int16());
441
442 auto schema1 = ::arrow::schema({field1, field2});
443 auto schema2 = ::arrow::schema({field1, field3});
444 auto schema3 = ::arrow::schema({field3, field2});
445
446 random::RandomArrayGenerator gen(42);
447
448 auto array1 = gen.ArrayOf(int32(), length);
449 auto array2 = gen.ArrayOf(uint8(), length);
450 auto array3 = gen.ArrayOf(int16(), length);
451
452 auto batch1 = RecordBatch::Make(schema1, length, {array1, array2});
453 auto batch2 = RecordBatch::Make(schema2, length, {array1, array3});
454 auto batch3 = RecordBatch::Make(schema3, length, {array3, array2});
455
456 const RecordBatch& batch = *batch1;
457
458 // Negative tests with invalid index
459 ASSERT_RAISES(Invalid, batch.SetColumn(5, field1, array1));
460 ASSERT_RAISES(Invalid, batch.SetColumn(-1, field1, array1));
461
462 // Negative test with wrong length
463 auto longer_col = gen.ArrayOf(int32(), length + 1);
464 ASSERT_RAISES(Invalid, batch.SetColumn(0, field1, longer_col));
465
466 // Negative test with mismatch type
467 ASSERT_RAISES(TypeError, batch.SetColumn(0, field1, array2));
468
469 ASSERT_OK_AND_ASSIGN(auto new_batch, batch.SetColumn(1, field3, array3));
470 AssertBatchesEqual(*new_batch, *batch2);
471
472 ASSERT_OK_AND_ASSIGN(new_batch, batch.SetColumn(0, field3, array3));
473 AssertBatchesEqual(*new_batch, *batch3);
474}
475
476TEST_F(TestRecordBatch, RemoveColumn) {
477 const int length = 10;
478
479 auto field1 = field("f1", int32());
480 auto field2 = field("f2", uint8());
481 auto field3 = field("f3", int16());
482
483 auto schema1 = ::arrow::schema({field1, field2, field3});
484 auto schema2 = ::arrow::schema({field2, field3});
485 auto schema3 = ::arrow::schema({field1, field3});
486 auto schema4 = ::arrow::schema({field1, field2});

Callers 3

TEST_FFunction · 0.70
MakeBatchesAndReaderMethod · 0.70

Calls 15

genFunction · 0.85
AssertBatchesEqualFunction · 0.85
forFunction · 0.85
ArrayFromJSONFunction · 0.85
struct_Function · 0.85
columnsMethod · 0.80
emplace_backMethod · 0.80
push_backMethod · 0.80
fieldFunction · 0.70
schemaFunction · 0.70
MakeFunction · 0.70
TEST_FFunction · 0.70

Tested by

no test coverage detected