| 1592 | |
| 1593 | template <typename BatchesMaker> |
| 1594 | void TestSchemaResolution(BatchesMaker maker, int num_batches, int batch_size) { |
| 1595 | // GH-39803: The key hasher needs to resolve the types of key columns. All other |
| 1596 | // tests use int32 for all columns, but this test converts the key columns to |
| 1597 | // strings via a projection node to test that the column is correctly resolved |
| 1598 | // to string. |
| 1599 | auto l_schema = |
| 1600 | schema({field("time", int32()), field("key", int32()), field("l_value", int32())}); |
| 1601 | auto r_schema = |
| 1602 | schema({field("time", int32()), field("key", int32()), field("r0_value", int32())}); |
| 1603 | |
| 1604 | auto make_shift = [&maker, num_batches, batch_size]( |
| 1605 | const std::shared_ptr<Schema>& schema, int shift) { |
| 1606 | return maker({[](int row) -> int64_t { return row; }, |
| 1607 | [num_batches](int row) -> int64_t { return row / num_batches; }, |
| 1608 | [shift](int row) -> int64_t { return row * 10 + shift; }}, |
| 1609 | schema, num_batches, batch_size); |
| 1610 | }; |
| 1611 | ASSERT_OK_AND_ASSIGN(auto l_batches, make_shift(l_schema, 0)); |
| 1612 | ASSERT_OK_AND_ASSIGN(auto r_batches, make_shift(r_schema, 1)); |
| 1613 | |
| 1614 | Declaration l_src = {"source", |
| 1615 | SourceNodeOptions(l_schema, l_batches.gen(false, false))}; |
| 1616 | Declaration r_src = {"source", |
| 1617 | SourceNodeOptions(r_schema, r_batches.gen(false, false))}; |
| 1618 | Declaration l_project = { |
| 1619 | "project", |
| 1620 | {std::move(l_src)}, |
| 1621 | ProjectNodeOptions({compute::field_ref("time"), |
| 1622 | compute::call("cast", {compute::field_ref("key")}, |
| 1623 | compute::CastOptions::Safe(utf8())), |
| 1624 | compute::field_ref("l_value")}, |
| 1625 | {"time", "key", "l_value"})}; |
| 1626 | Declaration r_project = { |
| 1627 | "project", |
| 1628 | {std::move(r_src)}, |
| 1629 | ProjectNodeOptions({compute::call("cast", {compute::field_ref("key")}, |
| 1630 | compute::CastOptions::Safe(utf8())), |
| 1631 | compute::field_ref("r0_value"), compute::field_ref("time")}, |
| 1632 | {"key", "r0_value", "time"})}; |
| 1633 | |
| 1634 | Declaration asofjoin = { |
| 1635 | "asofjoin", {l_project, r_project}, GetRepeatedOptions(2, "time", {"key"}, 1000)}; |
| 1636 | |
| 1637 | QueryOptions query_options; |
| 1638 | query_options.use_threads = false; |
| 1639 | ASSERT_OK_AND_ASSIGN(auto table, DeclarationToTable(asofjoin, query_options)); |
| 1640 | |
| 1641 | Int32Builder expected_r0_b; |
| 1642 | for (int i = 1; i <= 91; i += 10) { |
| 1643 | ASSERT_OK(expected_r0_b.Append(i)); |
| 1644 | } |
| 1645 | ASSERT_OK_AND_ASSIGN(auto expected_r0, expected_r0_b.Finish()); |
| 1646 | |
| 1647 | auto actual_r0 = table->GetColumnByName("r0_value"); |
| 1648 | std::vector<std::shared_ptr<arrow::Array>> chunks = {expected_r0}; |
| 1649 | auto expected_r0_chunked = std::make_shared<arrow::ChunkedArray>(chunks); |
| 1650 | ASSERT_TRUE(actual_r0->Equals(expected_r0_chunked)); |
| 1651 | } |
no test coverage detected