Returns ranges for the non-null rows of an array or map. 'rows' gives the rows. nulls is the nulls of the array/map or nullptr if no nulls. 'offsets' and 'sizes' are the offsets and sizes of the array/map.Returns the number of index ranges. Obtains the ranges from 'rangesHolder'. If 'sizesPtr' is non-null, gets returns the sizes for the inner ranges in 'sizesHolder'. If 'stream' is non-null, wri
| 2097 | // 'stream' is non-null, writes the lengths and nulls for the array/map into |
| 2098 | // 'stream'. |
| 2099 | int32_t rowsToRanges( |
| 2100 | folly::Range<const vector_size_t*> rows, |
| 2101 | const uint64_t* rawNulls, |
| 2102 | const vector_size_t* offsets, |
| 2103 | const vector_size_t* sizes, |
| 2104 | vector_size_t** sizesPtr, |
| 2105 | ScratchPtr<IndexRange>& rangesHolder, |
| 2106 | ScratchPtr<vector_size_t*>* sizesHolder, |
| 2107 | VectorStream* stream, |
| 2108 | Scratch& scratch) { |
| 2109 | auto numRows = rows.size(); |
| 2110 | auto* innerRows = rows.data(); |
| 2111 | auto* nonNullRows = innerRows; |
| 2112 | int32_t numInner = rows.size(); |
| 2113 | ScratchPtr<vector_size_t, 64> nonNullHolder(scratch); |
| 2114 | ScratchPtr<vector_size_t, 64> innerRowsHolder(scratch); |
| 2115 | if (rawNulls) { |
| 2116 | ScratchPtr<uint64_t, 4> nullsHolder(scratch); |
| 2117 | auto* nulls = |
| 2118 | nullsHolder.get(bits::nwords(static_cast<uint64_t>(rows.size()))); |
| 2119 | simd::gatherBits(rawNulls, rows, nulls); |
| 2120 | auto* mutableNonNullRows = nonNullHolder.get(numRows); |
| 2121 | auto* mutableInnerRows = innerRowsHolder.get(numRows); |
| 2122 | numInner = simd::indicesOfSetBits(nulls, 0, numRows, mutableNonNullRows); |
| 2123 | if (stream) { |
| 2124 | stream->appendLengths( |
| 2125 | nulls, rows, numInner, [&](auto row) { return sizes[row]; }); |
| 2126 | } |
| 2127 | simd::transpose( |
| 2128 | rows.data(), |
| 2129 | folly::Range<const vector_size_t*>(mutableNonNullRows, numInner), |
| 2130 | mutableInnerRows); |
| 2131 | nonNullRows = mutableNonNullRows; |
| 2132 | innerRows = mutableInnerRows; |
| 2133 | } else if (stream) { |
| 2134 | stream->appendNonNull(rows.size()); |
| 2135 | for (auto i = 0; i < rows.size(); ++i) { |
| 2136 | stream->appendLength(sizes[rows[i]]); |
| 2137 | } |
| 2138 | } |
| 2139 | vector_size_t** sizesOut = nullptr; |
| 2140 | if (sizesPtr) { |
| 2141 | sizesOut = sizesHolder->get(numInner); |
| 2142 | } |
| 2143 | auto ranges = rangesHolder.get(numInner); |
| 2144 | int32_t fill = 0; |
| 2145 | for (auto i = 0; i < numInner; ++i) { |
| 2146 | if (sizes[innerRows[i]] == 0) { |
| 2147 | continue; |
| 2148 | } |
| 2149 | if (sizesOut) { |
| 2150 | sizesOut[fill] = sizesPtr[rawNulls ? nonNullRows[i] : i]; |
| 2151 | } |
| 2152 | ranges[fill].begin = offsets[innerRows[i]]; |
| 2153 | ranges[fill].size = sizes[innerRows[i]]; |
| 2154 | ++fill; |
| 2155 | } |
| 2156 | return fill; |
no test coverage detected