Skip to content

Commit 604085e

Browse files
authored
fix(cubesql): Reduce memory usage while converting to DataFrame (#8598)
1 parent e137630 commit 604085e

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

packages/cubejs-backend-native/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn bind_method<'a>(
2727

2828
pub fn batch_to_rows(batch: RecordBatch) -> Result<(Value, Vec<Value>), CubeError> {
2929
let schema = batch.schema();
30-
let data_frame = dataframe::batch_to_dataframe(&schema, &vec![batch])?;
30+
let data_frame = dataframe::batches_to_dataframe(&schema, vec![batch])?;
3131

3232
let columns = serde_json::to_value(data_frame.get_columns())?;
3333
let rows = data_frame

rust/cubesql/cubesql/src/compile/test/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
},
1717
config::{ConfigObj, ConfigObjImpl},
1818
sql::{
19-
compiler_cache::CompilerCacheImpl, dataframe::batch_to_dataframe, AuthContextRef,
19+
compiler_cache::CompilerCacheImpl, dataframe::batches_to_dataframe, AuthContextRef,
2020
AuthenticateResponse, HttpAuthContext, ServerManager, Session, SessionManager,
2121
SqlAuthService,
2222
},
@@ -839,7 +839,7 @@ impl TestContext {
839839
QueryPlan::DataFusionSelect(flags, plan, ctx) => {
840840
let df = DFDataFrame::new(ctx.state, &plan);
841841
let batches = df.collect().await?;
842-
let frame = batch_to_dataframe(&df.schema().into(), &batches)?;
842+
let frame = batches_to_dataframe(&df.schema().into(), batches)?;
843843

844844
output.push(frame.print());
845845
output_flags = flags;

rust/cubesql/cubesql/src/sql/dataframe.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,9 @@ pub fn arrow_to_column_type(arrow_type: DataType) -> Result<ColumnType, CubeErro
422422
}
423423
}
424424

425-
pub fn batch_to_dataframe(
425+
pub fn batches_to_dataframe(
426426
schema: &Schema,
427-
batches: &Vec<RecordBatch>,
427+
batches: Vec<RecordBatch>,
428428
) -> Result<DataFrame, CubeError> {
429429
let mut cols = Vec::with_capacity(schema.fields().len());
430430
let mut all_rows = vec![];
@@ -437,7 +437,7 @@ pub fn batch_to_dataframe(
437437
));
438438
}
439439

440-
for batch in batches.iter() {
440+
for batch in batches.into_iter() {
441441
if batch.num_rows() == 0 {
442442
continue;
443443
}

rust/cubesql/cubesql/src/sql/postgres/extended.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
compile::QueryPlan,
33
sql::{
4-
dataframe::{batch_to_dataframe, DataFrame, TableValue},
4+
dataframe::{batches_to_dataframe, DataFrame, TableValue},
55
statement::PostgresStatementParamsBinder,
66
temp_tables::TempTable,
77
writer::BatchWriter,
@@ -390,7 +390,7 @@ impl Portal {
390390
}
391391
};
392392

393-
let frame = batch_to_dataframe(batch_for_write.schema().as_ref(), &vec![batch_for_write])?;
393+
let frame = batches_to_dataframe(batch_for_write.schema().as_ref(), vec![batch_for_write])?;
394394

395395
Ok((unused, self.dataframe_to_writer(frame)?))
396396
}

0 commit comments

Comments
 (0)