From 354c585e20150ffd563d7959d535ecd9929b6a4d Mon Sep 17 00:00:00 2001 From: CooooolFrog Date: Thu, 29 Dec 2022 20:39:27 +0800 Subject: [PATCH] fix: fix convert record batch (#521) --- server/src/handlers/sql.rs | 45 +++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/server/src/handlers/sql.rs b/server/src/handlers/sql.rs index e0ae05b86d..2845469386 100644 --- a/server/src/handlers/sql.rs +++ b/server/src/handlers/sql.rs @@ -208,32 +208,33 @@ fn convert_records(records: RecordBatchVec) -> ArrowResult { })); } - let record_batch = &records[0]; - let num_cols = record_batch.num_columns(); - let num_rows = record_batch.num_rows(); - let schema = record_batch.schema(); - - let mut column_names = Vec::with_capacity(num_cols); - let mut column_data = Vec::with_capacity(num_rows); - - for col_idx in 0..num_cols { - let column_schema = schema.column(col_idx).clone(); - column_names.push(ResponseColumn { - name: column_schema.name, - data_type: column_schema.data_type, - }); - } + let mut column_names = vec![]; + let mut column_data = vec![]; - for row_idx in 0..num_rows { - let mut row_data = Vec::with_capacity(num_cols); - for col_idx in 0..num_cols { - let column = record_batch.column(col_idx); - let column = column.datum(row_idx); + for record_batch in records { + let num_cols = record_batch.num_columns(); + let num_rows = record_batch.num_rows(); + let schema = record_batch.schema(); - row_data.push(column); + for col_idx in 0..num_cols { + let column_schema = schema.column(col_idx).clone(); + column_names.push(ResponseColumn { + name: column_schema.name, + data_type: column_schema.data_type, + }); } - column_data.push(row_data); + for row_idx in 0..num_rows { + let mut row_data = Vec::with_capacity(num_cols); + for col_idx in 0..num_cols { + let column = record_batch.column(col_idx); + let column = column.datum(row_idx); + + row_data.push(column); + } + + column_data.push(row_data); + } } Ok(Response::Rows(ResponseRows {