|
39 | 39 | #include "runtime/types.h" |
40 | 40 | #include "util/arrow/block_convertor.h" |
41 | 41 | #include "vec/core/block.h" |
| 42 | +#include "vec/exprs/vexpr.h" |
| 43 | +#include "vec/exprs/vexpr_context.h" |
42 | 44 |
|
43 | 45 | namespace doris { |
44 | 46 |
|
@@ -163,6 +165,22 @@ Status convert_to_arrow_schema(const RowDescriptor& row_desc, |
163 | 165 | return Status::OK(); |
164 | 166 | } |
165 | 167 |
|
| 168 | +Status convert_expr_ctxs_arrow_schema(const vectorized::VExprContextSPtrs& output_vexpr_ctxs, |
| 169 | + std::shared_ptr<arrow::Schema>* result) { |
| 170 | + std::vector<std::shared_ptr<arrow::Field>> fields; |
| 171 | + for (auto expr_ctx : output_vexpr_ctxs) { |
| 172 | + std::shared_ptr<arrow::DataType> arrow_type; |
| 173 | + auto root_expr = expr_ctx->root(); |
| 174 | + RETURN_IF_ERROR(convert_to_arrow_type(root_expr->type(), &arrow_type)); |
| 175 | + auto field_name = root_expr->is_slot_ref() ? root_expr->expr_name() |
| 176 | + : root_expr->data_type()->get_name(); |
| 177 | + fields.push_back( |
| 178 | + std::make_shared<arrow::Field>(field_name, arrow_type, root_expr->is_nullable())); |
| 179 | + } |
| 180 | + *result = arrow::schema(std::move(fields)); |
| 181 | + return Status::OK(); |
| 182 | +} |
| 183 | + |
166 | 184 | Status serialize_record_batch(const arrow::RecordBatch& record_batch, std::string* result) { |
167 | 185 | // create sink memory buffer outputstream with the computed capacity |
168 | 186 | int64_t capacity; |
@@ -206,15 +224,13 @@ Status serialize_record_batch(const arrow::RecordBatch& record_batch, std::strin |
206 | 224 | return Status::OK(); |
207 | 225 | } |
208 | 226 |
|
209 | | -Status serialize_arrow_schema(RowDescriptor row_desc, std::shared_ptr<arrow::Schema>* schema, |
210 | | - std::string* result) { |
211 | | - std::vector<SlotDescriptor*> slots; |
212 | | - for (auto tuple_desc : row_desc.tuple_descriptors()) { |
213 | | - slots.insert(slots.end(), tuple_desc->slots().begin(), tuple_desc->slots().end()); |
| 227 | +Status serialize_arrow_schema(std::shared_ptr<arrow::Schema>* schema, std::string* result) { |
| 228 | + auto make_empty_result = arrow::RecordBatch::MakeEmpty(*schema); |
| 229 | + if (!make_empty_result.ok()) { |
| 230 | + return Status::InternalError("serialize_arrow_schema failed, reason: {}", |
| 231 | + make_empty_result.status().ToString()); |
214 | 232 | } |
215 | | - auto block = vectorized::Block(slots, 0); |
216 | | - std::shared_ptr<arrow::RecordBatch> batch; |
217 | | - RETURN_IF_ERROR(convert_to_arrow_batch(block, *schema, arrow::default_memory_pool(), &batch)); |
| 233 | + auto batch = make_empty_result.ValueOrDie(); |
218 | 234 | return serialize_record_batch(*batch, result); |
219 | 235 | } |
220 | 236 |
|
|
0 commit comments