|
29 | 29 | #include "arrow/array/data.h" |
30 | 30 | #include "arrow/array/util.h" |
31 | 31 | #include "arrow/chunked_array.h" |
| 32 | +#include "arrow/compute/cast.h" |
32 | 33 | #include "arrow/record_batch.h" |
33 | 34 | #include "arrow/status.h" |
34 | 35 | #include "arrow/testing/gtest_util.h" |
@@ -418,16 +419,17 @@ TEST_F(TestPromoteTableToSchema, IncompatibleTypes) { |
418 | 419 | auto table = MakeTableWithOneNullFilledColumn("field", int32(), length); |
419 | 420 |
|
420 | 421 | // Invalid promotion: int32 to null. |
421 | | - ASSERT_RAISES(Invalid, PromoteTableToSchema(table, schema({field("field", null())}))); |
| 422 | + ASSERT_RAISES(TypeError, PromoteTableToSchema(table, schema({field("field", null())}))); |
422 | 423 |
|
423 | | - // Invalid promotion: int32 to uint32. |
424 | | - ASSERT_RAISES(Invalid, PromoteTableToSchema(table, schema({field("field", uint32())}))); |
| 424 | + // Invalid promotion: int32 to list. |
| 425 | + ASSERT_RAISES(TypeError, |
| 426 | + PromoteTableToSchema(table, schema({field("field", list(int32()))}))); |
425 | 427 | } |
426 | 428 |
|
427 | 429 | TEST_F(TestPromoteTableToSchema, IncompatibleNullity) { |
428 | 430 | const int length = 10; |
429 | 431 | auto table = MakeTableWithOneNullFilledColumn("field", int32(), length); |
430 | | - ASSERT_RAISES(Invalid, |
| 432 | + ASSERT_RAISES(TypeError, |
431 | 433 | PromoteTableToSchema( |
432 | 434 | table, schema({field("field", uint32())->WithNullable(false)}))); |
433 | 435 | } |
@@ -520,6 +522,36 @@ TEST_F(ConcatenateTablesWithPromotionTest, Simple) { |
520 | 522 | AssertTablesEqualUnorderedFields(*expected, *result); |
521 | 523 | } |
522 | 524 |
|
| 525 | +TEST_F(ConcatenateTablesWithPromotionTest, Unify) { |
| 526 | + auto t_i32 = TableFromJSON(schema({field("f0", int32())}), {"[[0], [1]]"}); |
| 527 | + auto t_i64 = TableFromJSON(schema({field("f0", int64())}), {"[[2], [3]]"}); |
| 528 | + auto t_null = TableFromJSON(schema({field("f0", null())}), {"[[null], [null]]"}); |
| 529 | + |
| 530 | + auto expected_int64 = |
| 531 | + TableFromJSON(schema({field("f0", int64())}), {"[[0], [1], [2], [3]]"}); |
| 532 | + auto expected_null = |
| 533 | + TableFromJSON(schema({field("f0", int32())}), {"[[0], [1], [null], [null]]"}); |
| 534 | + |
| 535 | + ConcatenateTablesOptions options; |
| 536 | + EXPECT_RAISES_WITH_MESSAGE_THAT(Invalid, |
| 537 | + ::testing::HasSubstr("Schema at index 1 was different"), |
| 538 | + ConcatenateTables({t_i32, t_i64}, options)); |
| 539 | + EXPECT_RAISES_WITH_MESSAGE_THAT(Invalid, |
| 540 | + ::testing::HasSubstr("Schema at index 1 was different"), |
| 541 | + ConcatenateTables({t_i32, t_null}, options)); |
| 542 | + |
| 543 | + options.unify_schemas = true; |
| 544 | + EXPECT_RAISES_WITH_MESSAGE_THAT(TypeError, |
| 545 | + ::testing::HasSubstr("Field f0 has incompatible types"), |
| 546 | + ConcatenateTables({t_i64, t_i32}, options)); |
| 547 | + ASSERT_OK_AND_ASSIGN(auto actual, ConcatenateTables({t_i32, t_null}, options)); |
| 548 | + AssertTablesEqual(*expected_null, *actual, /*same_chunk_layout=*/false); |
| 549 | + |
| 550 | + options.field_merge_options.promote_numeric_width = true; |
| 551 | + ASSERT_OK_AND_ASSIGN(actual, ConcatenateTables({t_i32, t_i64}, options)); |
| 552 | + AssertTablesEqual(*expected_int64, *actual, /*same_chunk_layout=*/false); |
| 553 | +} |
| 554 | + |
523 | 555 | TEST_F(TestTable, Slice) { |
524 | 556 | const int64_t length = 10; |
525 | 557 |
|
|
0 commit comments