| 140 | } |
| 141 | |
| 142 | Result<Datum> DropNullTable(const std::shared_ptr<Table>& table, ExecContext* ctx) { |
| 143 | if (table->num_rows() == 0) { |
| 144 | return table; |
| 145 | } |
| 146 | // Compute an upper bound of the final null count |
| 147 | int64_t null_count = 0; |
| 148 | for (const auto& col : table->columns()) { |
| 149 | for (const auto& column_chunk : col->chunks()) { |
| 150 | null_count += column_chunk->null_count(); |
| 151 | } |
| 152 | } |
| 153 | if (null_count == 0) { |
| 154 | return table; |
| 155 | } |
| 156 | |
| 157 | arrow::RecordBatchVector filtered_batches; |
| 158 | TableBatchReader batch_iter(*table); |
| 159 | while (true) { |
| 160 | ARROW_ASSIGN_OR_RAISE(auto batch, batch_iter.Next()); |
| 161 | if (batch == nullptr) { |
| 162 | break; |
| 163 | } |
| 164 | ARROW_ASSIGN_OR_RAISE(auto filtered_datum, DropNullRecordBatch(batch, ctx)) |
| 165 | if (filtered_datum.length() > 0) { |
| 166 | filtered_batches.push_back(filtered_datum.record_batch()); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | return Table::FromRecordBatches(table->schema(), filtered_batches); |
| 171 | } |
| 172 | const FunctionDoc drop_null_doc( |
| 173 | "Drop nulls from the input", |
| 174 | ("The output is populated with values from the input (Array, ChunkedArray,\n" |
no test coverage detected