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

Function ASSERT_OK_AND_ASSIGN

cpp/src/arrow/compute/expression_test.cc:1142–1226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1140 ASSERT_OK_AND_ASSIGN(Datum actual, ExecuteScalarExpression(simplify_expr, input));
1141 compute::ExecContext* exec_context = default_exec_context();
1142 ASSERT_OK_AND_ASSIGN(auto function,
1143 exec_context->func_registry()->GetFunction("random"));
1144 ASSERT_OK_AND_ASSIGN(Datum expected,
1145 function->Execute(input, &random_options, exec_context));
1146 AssertDatumsEqual(actual, expected, /*verbose=*/true);
1147
1148 EXPECT_EQ(actual.length(), kCount);
1149}
1150
1151TEST(Expression, ExecuteChunkedArray) {
1152 // GH-41923: compute should generate the right result if input
1153 // ExecBatch is `chunked_array`.
1154 auto input_schema = struct_({field("a", struct_({
1155 field("a", float64()),
1156 field("b", float64()),
1157 }))});
1158
1159 auto chunked_array_input = ChunkedArrayFromJSON(input_schema, {R"([
1160 {"a": {"a": 6.125, "b": 3.375}},
1161 {"a": {"a": 0.0, "b": 1}}
1162 ])",
1163 R"([
1164 {"a": {"a": -1, "b": 4.75}}
1165 ])"});
1166
1167 ASSERT_OK_AND_ASSIGN(auto table_input,
1168 Table::FromChunkedStructArray(chunked_array_input));
1169
1170 auto expr = add(field_ref(FieldRef("a", "a")), field_ref(FieldRef("a", "b")));
1171
1172 ASSERT_OK_AND_ASSIGN(expr, expr.Bind(input_schema));
1173 std::vector<Datum> inputs{table_input->column(0)};
1174 ExecBatch batch{inputs, 3};
1175
1176 ASSERT_OK_AND_ASSIGN(Datum res, ExecuteScalarExpression(expr, batch));
1177 ASSERT_TRUE(res.is_chunked_array());
1178
1179 AssertDatumsEqual(res, ChunkedArrayFromJSON(float64(), {R"([
1180 9.5,
1181 1,
1182 3.75
1183 ])"}));
1184}
1185
1186TEST(Expression, ExecuteDictionaryTransparent) {
1187 ExpectExecute(
1188 equal(field_ref("a"), field_ref("b")),
1189 ArrayFromJSON(
1190 struct_({field("a", dictionary(int32(), utf8())), field("b", utf8())}), R"([
1191 {"a": "hi", "b": "hi"},
1192 {"a": "", "b": ""},
1193 {"a": "hi", "b": "hello"}
1194 ])"));
1195
1196 ASSERT_OK_AND_ASSIGN(
1197 auto expr, project({field_ref("i32"), field_ref("dict_str")}, {"i32", "dict_str"})
1198 .Bind(*kBoringSchema));
1199

Callers 6

TESTFunction · 0.70
ExpectBindsToFunction · 0.70
ExpectExecuteFunction · 0.70
expression_test.ccFile · 0.70
operator()Function · 0.70
ExpectRemovesRefsToFunction · 0.70

Calls 15

struct_Function · 0.85
ChunkedArrayFromJSONFunction · 0.85
field_refFunction · 0.85
ExecuteScalarExpressionFunction · 0.85
AssertDatumsEqualFunction · 0.85
ExpectExecuteFunction · 0.85
equalFunction · 0.85
ArrayFromJSONFunction · 0.85
projectFunction · 0.85
SimplifyWithGuaranteeFunction · 0.85
addFunction · 0.70
TESTFunction · 0.70

Tested by

no test coverage detected