Skip to content

Commit

Permalink
fix: file not purged when copy into table. (#13812)
Browse files Browse the repository at this point in the history
fix: file not purge when copy into table.
  • Loading branch information
youngsofun authored Nov 27, 2023
1 parent a0cb2f6 commit df815ca
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/query/storages/fuse/src/io/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ impl Files {

#[async_backtrace::framed]
async fn delete_files(op: Operator, locations: Vec<String>) -> Result<()> {
// temporary fix for https://github.com/datafuselabs/databend/issues/13804
let locations = locations
.into_iter()
.map(|loc| loc.trim_start_matches('/').to_owned())
.filter(|loc| !loc.is_empty())
.collect::<Vec<_>>();
info!("deleting files: {:?}", &locations);
op.remove(locations).await?;
Ok(())
Expand Down
19 changes: 19 additions & 0 deletions tests/suites/1_stateful/00_stage/00_0002_copy_purge.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
>>>> drop table if exists ii
>>>> create table ii(a int, b int)
>>>> drop stage if exists s_ii
>>>> create stage s_ii url='fs:///tmp/00_0002/';
>>>> copy into ii from @s_ii file_format = (type = CSV) purge = true
<<<<
>>>> list @s_ii
<<<<
>>>> select * from ii
1 1
2 2
>>>> truncate table ii
>>>> copy into ii from @s_ii file_format = (type = CSV) files = ('i1.csv') purge = true
<<<<
>>>> list @s_ii
<<<<
>>>> select * from ii
1 1
2 2
36 changes: 36 additions & 0 deletions tests/suites/1_stateful/00_stage/00_0002_copy_purge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. "$CURDIR"/../../../shell_env.sh

rm -rf /tmp/00_0002
mkdir -p /tmp/00_0002
cat << EOF > /tmp/00_0002/i0.csv
1,1
2,2
EOF

stmt "drop table if exists ii"
stmt "create table ii(a int, b int)"

stmt "drop stage if exists s_ii"
stmt "create stage s_ii url='fs:///tmp/00_0002/';"

query "copy into ii from @s_ii file_format = (type = CSV) purge = true"

query "list @s_ii"

stmt "select * from ii"

stmt "truncate table ii"

cat << EOF > /tmp/00_0002/i1.csv
1,1
2,2
EOF

query "copy into ii from @s_ii file_format = (type = CSV) files = ('i1.csv') purge = true"

query "list @s_ii"

stmt "select * from ii"

0 comments on commit df815ca

Please sign in to comment.