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

Function TestSchemaResolution

cpp/src/arrow/acero/asof_join_node_test.cc:1594–1651  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1592
1593template <typename BatchesMaker>
1594void 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}

Callers 1

TESTFunction · 0.85

Calls 11

SourceNodeOptionsClass · 0.85
field_refFunction · 0.85
SafeFunction · 0.85
GetColumnByNameMethod · 0.80
GetRepeatedOptionsFunction · 0.70
schemaFunction · 0.50
fieldFunction · 0.50
callFunction · 0.50
genMethod · 0.45
AppendMethod · 0.45
EqualsMethod · 0.45

Tested by

no test coverage detected