Skip to content

Commit 0200768

Browse files
authored
Merge pull request #7518 from sundy-li/copy-purge
feat(query): support purge option in copy into table
2 parents 18a6be8 + 49f91bc commit 0200768

File tree

23 files changed

+119
-45
lines changed

23 files changed

+119
-45
lines changed

docs/doc/30-reference/30-sql/00-ddl/40-stage/01-ddl-create-stage.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ CREATE STAGE [ IF NOT EXISTS ] <internal_stage_name>
1212
[ FILE_FORMAT = ( { TYPE = { CSV | PARQUET } [ formatTypeOptions ] ) } ]
1313
[ COPY_OPTIONS = ( copyOptions ) ]
1414
[ COMMENT = '<string_literal>' ]
15-
15+
1616
-- External stage
1717
CREATE STAGE [ IF NOT EXISTS ] <external_stage_name>
1818
externalStageParams
@@ -70,8 +70,8 @@ externalStageParams ::=
7070
### formatTypeOptions
7171
```
7272
formatTypeOptions ::=
73-
RECORD_DELIMITER = '<character>'
74-
FIELD_DELIMITER = '<character>'
73+
RECORD_DELIMITER = '<character>'
74+
FIELD_DELIMITER = '<character>'
7575
SKIP_HEADER = <integer>
7676
```
7777

@@ -85,11 +85,13 @@ formatTypeOptions ::=
8585
```
8686
copyOptions ::=
8787
[ SIZE_LIMIT = <num> ]
88+
[ PURGE = <bool> ]
8889
```
8990

9091
| Parameters | Description | Required |
9192
| ----------- | ----------- | --- |
9293
| `SIZE_LIMIT = <num>` | Number (> 0) that specifies the maximum rows of data to be loaded for a given COPY statement. Default `0` | Optional |
94+
| `PURGE = <bool>` | True specifies that the command will purge the files in the stage if they are loaded successfully into table. Default `false` | Optional |
9395

9496

9597
## Examples

docs/doc/30-reference/30-sql/10-dml/dml-copy-into-location.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ externalLocation (for Amazon S3) ::=
5656
### formatTypeOptions
5757
```
5858
formatTypeOptions ::=
59-
RECORD_DELIMITER = '<character>'
60-
FIELD_DELIMITER = '<character>'
59+
RECORD_DELIMITER = '<character>'
60+
FIELD_DELIMITER = '<character>'
6161
SKIP_HEADER = <integer>
6262
```
6363

docs/doc/30-reference/30-sql/10-dml/dml-copy-into-table.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ A regular expression pattern string, enclosed in single quotes, specifying the f
9797

9898
```
9999
formatTypeOptions ::=
100-
RECORD_DELIMITER = '<character>'
101-
FIELD_DELIMITER = '<character>'
100+
RECORD_DELIMITER = '<character>'
101+
FIELD_DELIMITER = '<character>'
102102
SKIP_HEADER = <integer>
103103
COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | NONE
104104
```
@@ -129,7 +129,7 @@ Default: `NONE`
129129

130130
Values:
131131

132-
| Values | Notes |
132+
| Values | Notes |
133133
|---------------|-----------------------------------------------------------------|
134134
| `AUTO` | Auto detect compression via file extensions |
135135
| `GZIP` | |
@@ -145,11 +145,13 @@ Values:
145145
```
146146
copyOptions ::=
147147
[ SIZE_LIMIT = <num> ]
148+
[ PURGE = <bool> ]
148149
```
149150

150151
| Parameters | Description | Required |
151152
| ----------- | ----------- | --- |
152153
| `SIZE_LIMIT = <num>` | Number (> 0) that specifies the maximum rows of data to be loaded for a given COPY statement. Default `0` | Optional |
154+
| `PURGE = <bool>` | True that specifies the command will purge the files in the stage if they are loaded successfully into table. Default `false` | Optional |
153155

154156
## Examples
155157

src/meta/proto-conv/src/user_from_to_protobuf_impl.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ impl FromToProto for mt::CopyOptions {
571571
Ok(mt::CopyOptions {
572572
on_error,
573573
size_limit,
574+
purge: p.purge,
574575
})
575576
}
576577

@@ -582,6 +583,7 @@ impl FromToProto for mt::CopyOptions {
582583
Ok(pb::user_stage_info::CopyOptions {
583584
on_error: Some(on_error),
584585
size_limit,
586+
purge: self.purge,
585587
})
586588
}
587589
}

src/meta/proto-conv/tests/it/user_proto_conv.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ fn test_fs_stage_info() -> mt::UserStageInfo {
8181
copy_options: mt::CopyOptions {
8282
on_error: mt::OnErrorMode::SkipFileNum(666),
8383
size_limit: 1038,
84+
purge: false,
8485
},
8586
comment: "test".to_string(),
8687
..Default::default()
@@ -111,6 +112,7 @@ fn test_s3_stage_info() -> mt::UserStageInfo {
111112
copy_options: mt::CopyOptions {
112113
on_error: mt::OnErrorMode::SkipFileNum(666),
113114
size_limit: 1038,
115+
purge: false,
114116
},
115117
comment: "test".to_string(),
116118
..Default::default()
@@ -140,6 +142,7 @@ fn test_gcs_stage_info() -> mt::UserStageInfo {
140142
copy_options: mt::CopyOptions {
141143
on_error: mt::OnErrorMode::SkipFileNum(666),
142144
size_limit: 1038,
145+
purge: false,
143146
},
144147
comment: "test".to_string(),
145148
..Default::default()

src/meta/protos/proto/user.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ message UserStageInfo {
193193
message CopyOptions {
194194
OnErrorMode on_error = 1;
195195
uint64 size_limit = 2;
196+
bool purge = 3;
196197
}
197198

198199
string stage_name = 1;

src/meta/types/src/user_stage.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ impl FromStr for OnErrorMode {
221221
pub struct CopyOptions {
222222
pub on_error: OnErrorMode,
223223
pub size_limit: usize,
224+
pub purge: bool,
224225
}
225226

226227
#[derive(serde::Serialize, serde::Deserialize, Default, Clone, Debug, Eq, PartialEq)]

src/query/ast/src/ast/format/ast_format.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,11 @@ impl<'ast> Visitor<'ast> for AstFormatVisitor {
784784
let size_limit_node = FormatTreeNode::new(size_limit_format_ctx);
785785
children.push(size_limit_node);
786786

787+
let purge_name = format!("Purge {}", copy.purge);
788+
let purge_name_ctx = AstFormatContext::new(purge_name);
789+
let purge_name_node = FormatTreeNode::new(purge_name_ctx);
790+
children.push(purge_name_node);
791+
787792
let name = "Copy".to_string();
788793
let format_ctx = AstFormatContext::with_children(name, children.len());
789794
let node = FormatTreeNode::with_children(format_ctx, children);

src/query/ast/src/ast/format/syntax/dml.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ pub(crate) fn pretty_copy(copy_stmt: CopyStmt) -> RcDoc {
163163
} else {
164164
RcDoc::nil()
165165
})
166+
.append(
167+
RcDoc::line()
168+
.append(RcDoc::text("PURGE = "))
169+
.append(RcDoc::text(format!("{}", copy_stmt.purge))),
170+
)
166171
}
167172

168173
fn pretty_copy_unit(copy_unit: CopyUnit) -> RcDoc {

src/query/ast/src/ast/statements/copy.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub struct CopyStmt<'a> {
3838
/// TODO(xuanwo): parse into validation_mode directly.
3939
pub validation_mode: String,
4040
pub size_limit: usize,
41+
pub purge: bool,
4142
}
4243

4344
impl Display for CopyStmt<'_> {
@@ -72,6 +73,7 @@ impl Display for CopyStmt<'_> {
7273
write!(f, " SIZE_LIMIT = {}", self.size_limit)?;
7374
}
7475

76+
write!(f, " PURGE = {}", self.purge)?;
7577
Ok(())
7678
}
7779
}

0 commit comments

Comments
 (0)