Skip to content

Commit

Permalink
chore: use BufWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
shuiyisong committed Nov 6, 2023
1 parent 6986f57 commit 0cd5392
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/cmd/src/cli/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use datatypes::scalars::ScalarVector;
use datatypes::vectors::{StringVector, Vector};
use snafu::{OptionExt, ResultExt};
use tokio::fs::File;
use tokio::io::AsyncWriteExt;
use tokio::io::{AsyncWriteExt, BufWriter};
use tokio::sync::Semaphore;

use crate::cli::{Instance, Tool};
Expand Down Expand Up @@ -346,7 +346,8 @@ impl Export {

let copy_from_file =
Path::new(&self.output_dir).join(format!("{catalog}-{schema}_copy_from.sql"));
let mut file = File::create(copy_from_file).await.context(FileIoSnafu)?;
let mut writer =
BufWriter::new(File::create(copy_from_file).await.context(FileIoSnafu)?);

for table_file in dir_filenames {
let table_file = table_file.unwrap();
Expand All @@ -356,18 +357,19 @@ impl Export {
.unwrap()
.replace(".parquet", "");

file.write(
format!(
"copy {} from '{}' with (format='parquet');\n",
table_name,
table_file.path().to_str().unwrap()
writer
.write(
format!(
"copy {} from '{}' with (format='parquet');\n",
table_name,
table_file.path().to_str().unwrap()
)
.as_bytes(),
)
.as_bytes(),
)
.await
.context(FileIoSnafu)?;
.await
.context(FileIoSnafu)?;
}
file.flush().await.context(FileIoSnafu)?;
writer.flush().await.context(FileIoSnafu)?;

info!("finished exporting {catalog}.{schema} copy_from.sql");

Expand Down

0 comments on commit 0cd5392

Please sign in to comment.