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

Function ExpectedFromIfElse

cpp/src/arrow/compute/kernels/scalar_if_else_test.cc:141–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139}
140
141Result<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
171bool NextScalarOrWholeArray(const std::shared_ptr<Array>& array, int* index, Datum* out) {
172 if (*index <= array->length()) {

Callers

nothing calls this directly

Calls 10

MakeNullScalarFunction · 0.85
CastFunction · 0.85
SafeFunction · 0.85
IfElseFunction · 0.85
ArrayOrBroadcastScalarFunction · 0.85
is_scalarMethod · 0.80
is_arrayMethod · 0.80
typeMethod · 0.45
EqualsMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected