| 43 | static constexpr int32_t kMaxNumberOfElements = 2147483632; |
| 44 | |
| 45 | FOLLY_ALWAYS_INLINE bool call( |
| 46 | out_type<Array<Generic<T1>>>& out, |
| 47 | const arg_type<Array<Array<Generic<T1>>>>& arrays) { |
| 48 | int64_t elementCount = 0; |
| 49 | for (const auto& array : arrays) { |
| 50 | if (array.has_value()) { |
| 51 | elementCount += array.value().size(); |
| 52 | } else { |
| 53 | // Return NULL if any of the nested arrays is NULL. |
| 54 | return false; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | BOLT_USER_CHECK_LE( |
| 59 | elementCount, |
| 60 | kMaxNumberOfElements, |
| 61 | "array flatten result exceeds the max array size limit {}", |
| 62 | kMaxNumberOfElements); |
| 63 | |
| 64 | out.reserve(elementCount); |
| 65 | for (const auto& array : arrays) { |
| 66 | out.add_items(array.value()); |
| 67 | }; |
| 68 | return true; |
| 69 | } |
| 70 | }; |
| 71 | } // namespace bytedance::bolt::functions::sparksql |