\brief Infer the ExecBatch length from values. \return the inferred length of the batch. If there are no values in the batch then kEmptyInput (-1) is returned. If the values in the batch have different lengths then kInvalidValues (-2) is returned.
| 172 | /// batch then kEmptyInput (-1) is returned. If the values in the batch have |
| 173 | /// different lengths then kInvalidValues (-2) is returned. |
| 174 | int64_t DoInferLength(const std::vector<Datum>& values) { |
| 175 | if (values.empty()) { |
| 176 | return kEmptyInput; |
| 177 | } |
| 178 | |
| 179 | int64_t length = -1; |
| 180 | for (const auto& value : values) { |
| 181 | if (value.is_scalar()) { |
| 182 | continue; |
| 183 | } |
| 184 | |
| 185 | if (length == -1) { |
| 186 | length = value.length(); |
| 187 | continue; |
| 188 | } |
| 189 | |
| 190 | if (length != value.length()) { |
| 191 | // all the arrays should have the same length |
| 192 | return kInvalidValues; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | return length == -1 ? 1 : length; |
| 197 | } |
| 198 | |
| 199 | } // namespace |
| 200 |
no test coverage detected