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

Function TEST

cpp/src/arrow/dataset/scanner_test.cc:74–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74TEST(BasicEvolution, MissingColumn) {
75 std::unique_ptr<DatasetEvolutionStrategy> strategy =
76 MakeBasicDatasetEvolutionStrategy();
77
78 std::shared_ptr<Schema> dataset_schema =
79 schema({field("A", int32()), field("B", int16()), field("C", int64())});
80 std::unique_ptr<Dataset> dataset = MakeDatasetFromSchema(dataset_schema);
81 std::unique_ptr<Fragment> fragment = MakeSomeFragment(std::move(dataset_schema));
82
83 InspectedFragment inspected{{"A", "B"}};
84 std::unique_ptr<FragmentEvolutionStrategy> fragment_strategy =
85 strategy->GetStrategy(*dataset, *fragment, inspected);
86
87 compute::Expression filter = equal(field_ref("C"), literal(INT64_C(7)));
88 // If, after simplification, a filter somehow still references a missing field
89 // then it is an error.
90 ASSERT_RAISES(Invalid, fragment_strategy->DevolveFilter(filter));
91 std::vector<FieldPath> selection{FieldPath({0}), FieldPath({2})};
92 // Basic strategy should provide is_null guarantee for missing fields
93 compute::Expression expected_guarantee = is_null(field_ref(2));
94 ASSERT_OK_AND_ASSIGN(compute::Expression guarantee,
95 fragment_strategy->GetGuarantee(selection));
96 ASSERT_EQ(expected_guarantee, guarantee);
97
98 // Basic strategy should drop missing fields from selection
99 ASSERT_OK_AND_ASSIGN(std::unique_ptr<FragmentSelection> devolved_selection,
100 fragment_strategy->DevolveSelection(selection));
101 ASSERT_EQ(1, devolved_selection->columns().size());
102 ASSERT_EQ(FieldPath({0}), devolved_selection->columns()[0].path);
103 ASSERT_EQ(*int32(), *devolved_selection->columns()[0].requested_type);
104
105 // Basic strategy should append null column to batches for missing column
106 std::shared_ptr<RecordBatch> devolved_batch =
107 RecordBatchFromJSON(schema({field("A", int32())}), R"([[1], [2], [3]])");
108 ASSERT_OK_AND_ASSIGN(
109 compute::ExecBatch evolved_batch,
110 fragment_strategy->EvolveBatch(devolved_batch, selection, *devolved_selection));
111 ASSERT_EQ(2, evolved_batch.values.size());
112 AssertArraysEqual(*devolved_batch->column(0), *evolved_batch[0].make_array());
113 ASSERT_EQ(*MakeNullScalar(int64()), *evolved_batch.values[1].scalar());
114}
115
116TEST(BasicEvolution, ReorderedColumns) {
117 std::unique_ptr<DatasetEvolutionStrategy> strategy =

Callers

nothing calls this directly

Calls 15

MakeDatasetFromSchemaFunction · 0.85
MakeSomeFragmentFunction · 0.85
equalFunction · 0.85
field_refFunction · 0.85
FieldPathFunction · 0.85
RecordBatchFromJSONFunction · 0.85
AssertArraysEqualFunction · 0.85
MakeNullScalarFunction · 0.85
MakeTestDatasetFunction · 0.85
CheckScannerBackpressureFunction · 0.85
GetCpuThreadPoolFunction · 0.85

Tested by

no test coverage detected