| 139 | } |
| 140 | |
| 141 | Result<Datum> ExpectedFromIfElse( |
| 142 | const Datum& cond, const Datum& left, const Datum& right, |
| 143 | std::shared_ptr<DataType> type, |
| 144 | const std::shared_ptr<Array>& expected_if_all_operands_are_arrays) { |
| 145 | if (cond.is_scalar() && left.is_scalar() && right.is_scalar()) { |
| 146 | const auto& scalar = cond.scalar_as<BooleanScalar>(); |
| 147 | Datum expected; |
| 148 | if (scalar.is_valid) { |
| 149 | expected = scalar.value ? left : right; |
| 150 | } else { |
| 151 | expected = MakeNullScalar(left.type()); |
| 152 | } |
| 153 | if (!left.type()->Equals(*right.type())) { |
| 154 | return Cast(expected, CastOptions::Safe(std::move(type))); |
| 155 | } |
| 156 | return expected; |
| 157 | } |
| 158 | if (cond.is_array() && left.is_array() && right.is_array()) { |
| 159 | return expected_if_all_operands_are_arrays; |
| 160 | } |
| 161 | // When at least one of the inputs is an array, we expect the output |
| 162 | // to be the same as if all the scalars were broadcast to arrays. |
| 163 | const auto expected_length = |
| 164 | std::max(cond.length(), std::max(left.length(), right.length())); |
| 165 | SCOPED_TRACE("IfElseAAACall"); |
| 166 | return IfElse(ArrayOrBroadcastScalar(cond, expected_length), |
| 167 | ArrayOrBroadcastScalar(left, expected_length), |
| 168 | ArrayOrBroadcastScalar(right, expected_length)); |
| 169 | } |
| 170 | |
| 171 | bool NextScalarOrWholeArray(const std::shared_ptr<Array>& array, int* index, Datum* out) { |
| 172 | if (*index <= array->length()) { |
nothing calls this directly
no test coverage detected