| 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 | |
| 1151 | TEST(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 | |
| 1186 | TEST(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 |
no test coverage detected