Skip to content

Commit 682039f

Browse files
authored
feat: disable specifying copy options when create stage. (#16925)
feat disable specifying copy options when create stage.
1 parent cf150d9 commit 682039f

File tree

31 files changed

+502
-524
lines changed

31 files changed

+502
-524
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/storage/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ arrow-schema = { workspace = true }
1515
async-backtrace = { workspace = true }
1616
chrono = { workspace = true }
1717
dashmap = { workspace = true, features = ["serde"] }
18+
databend-common-ast = { workspace = true }
1819
databend-common-auth = { workspace = true }
1920
databend-common-base = { workspace = true }
2021
databend-common-exception = { workspace = true }

src/common/storage/src/copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
use dashmap::mapref::entry::Entry;
1616
use dashmap::DashMap;
17+
use databend_common_ast::ast::OnErrorMode;
1718
use databend_common_exception::ErrorCode;
18-
use databend_common_meta_app::principal::OnErrorMode;
1919
use serde::Deserialize;
2020
use serde::Serialize;
2121
use thiserror::Error;

src/meta/app/src/principal/user_stage.rs

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,13 @@ use crate::storage::StorageParams;
3434
// internalStageParams
3535
// directoryTableParams
3636
// [ FILE_FORMAT = ( { FORMAT_NAME = '<file_format_name>' | TYPE = { CSV | JSON | AVRO | ORC | PARQUET | XML } [ formatTypeOptions ] ) } ]
37-
// [ COPY_OPTIONS = ( copyOptions ) ]
3837
// [ COMMENT = '<string_literal>' ]
3938
//
4039
// -- External stage
4140
// CREATE [ OR REPLACE ] [ TEMPORARY ] STAGE [ IF NOT EXISTS ] <external_stage_name>
4241
// externalStageParams
4342
// directoryTableParams
4443
// [ FILE_FORMAT = ( { FORMAT_NAME = '<file_format_name>' | TYPE = { CSV | JSON | AVRO | ORC | PARQUET | XML } [ formatTypeOptions ] ) } ]
45-
// [ COPY_OPTIONS = ( copyOptions ) ]
4644
// [ COMMENT = '<string_literal>' ]
4745
//
4846
//
@@ -52,7 +50,6 @@ use crate::storage::StorageParams;
5250
// 's3://<bucket>[/<path>/]'
5351
// [ { CREDENTIALS = ( { { AWS_KEY_ID = '<string>' AWS_SECRET_KEY = '<string>' [ AWS_TOKEN = '<string>' ] } | AWS_ROLE = '<string>' } ) ) } ]
5452
//
55-
// copyOptions ::=
5653
// ON_ERROR = { CONTINUE | SKIP_FILE | SKIP_FILE_<num> | SKIP_FILE_<num>% | ABORT_STATEMENT }
5754
// SIZE_LIMIT = <num>
5855

@@ -403,7 +400,7 @@ pub struct StageParams {
403400
pub storage: StorageParams,
404401
}
405402

406-
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Eq, PartialEq)]
403+
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Eq, PartialEq, Copy)]
407404
pub enum OnErrorMode {
408405
Continue,
409406
SkipFileNum(u64),
@@ -509,92 +506,6 @@ pub struct CopyOptions {
509506
pub detailed_output: bool,
510507
}
511508

512-
impl CopyOptions {
513-
pub fn apply(&mut self, opts: &BTreeMap<String, String>, ignore_unknown: bool) -> Result<()> {
514-
if opts.is_empty() {
515-
return Ok(());
516-
}
517-
for (k, v) in opts.iter() {
518-
match k.as_str() {
519-
"on_error" => {
520-
let on_error = OnErrorMode::from_str(v)?;
521-
self.on_error = on_error;
522-
}
523-
"size_limit" => {
524-
let size_limit = usize::from_str(v)?;
525-
self.size_limit = size_limit;
526-
}
527-
"max_files" => {
528-
let max_files = usize::from_str(v)?;
529-
self.max_files = max_files;
530-
}
531-
"split_size" => {
532-
let split_size = usize::from_str(v)?;
533-
self.split_size = split_size;
534-
}
535-
"purge" => {
536-
let purge = bool::from_str(v).map_err(|_| {
537-
ErrorCode::StrParseError(format!("Cannot parse purge: {} as bool", v))
538-
})?;
539-
self.purge = purge;
540-
}
541-
"single" => {
542-
let single = bool::from_str(v).map_err(|_| {
543-
ErrorCode::StrParseError(format!("Cannot parse single: {} as bool", v))
544-
})?;
545-
self.single = single;
546-
}
547-
"max_file_size" => {
548-
let max_file_size = usize::from_str(v)?;
549-
self.max_file_size = max_file_size;
550-
}
551-
"disable_variant_check" => {
552-
let disable_variant_check = bool::from_str(v).map_err(|_| {
553-
ErrorCode::StrParseError(format!(
554-
"Cannot parse disable_variant_check: {} as bool",
555-
v
556-
))
557-
})?;
558-
self.disable_variant_check = disable_variant_check;
559-
}
560-
"return_failed_only" => {
561-
let return_failed_only = bool::from_str(v).map_err(|_| {
562-
ErrorCode::StrParseError(format!(
563-
"Cannot parse return_failed_only: {} as bool",
564-
v
565-
))
566-
})?;
567-
self.return_failed_only = return_failed_only;
568-
}
569-
_ => {
570-
if !ignore_unknown {
571-
return Err(ErrorCode::BadArguments(format!(
572-
"Unknown stage copy option {}",
573-
k
574-
)));
575-
}
576-
}
577-
}
578-
}
579-
Ok(())
580-
}
581-
}
582-
583-
impl Display for CopyOptions {
584-
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
585-
write!(f, "OnErrorMode {}", self.on_error)?;
586-
write!(f, "SizeLimit {}", self.size_limit)?;
587-
write!(f, "MaxFiles {}", self.max_files)?;
588-
write!(f, "SplitSize {}", self.split_size)?;
589-
write!(f, "Purge {}", self.purge)?;
590-
write!(f, "DisableVariantCheck {}", self.disable_variant_check)?;
591-
write!(f, "ReturnFailedOnly {}", self.return_failed_only)?;
592-
write!(f, "MaxFileSize {}", self.max_file_size)?;
593-
write!(f, "Single {}", self.single)?;
594-
write!(f, "DetailedOutput {}", self.detailed_output)
595-
}
596-
}
597-
598509
#[derive(serde::Serialize, serde::Deserialize, Default, Clone, Debug, Eq, PartialEq)]
599510
#[serde(default)]
600511
pub struct StageInfo {

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,36 +188,39 @@ pub(crate) fn pretty_copy_into_table(copy_stmt: CopyIntoTableStmt) -> RcDoc<'sta
188188
} else {
189189
RcDoc::nil()
190190
})
191-
.append(if !copy_stmt.validation_mode.is_empty() {
191+
.append(if !copy_stmt.options.validation_mode.is_empty() {
192192
RcDoc::line()
193193
.append(RcDoc::text("VALIDATION_MODE = "))
194-
.append(RcDoc::text(copy_stmt.validation_mode))
194+
.append(RcDoc::text(copy_stmt.options.validation_mode))
195195
} else {
196196
RcDoc::nil()
197197
})
198-
.append(if copy_stmt.size_limit != 0 {
198+
.append(if copy_stmt.options.size_limit != 0 {
199199
RcDoc::line()
200200
.append(RcDoc::text("SIZE_LIMIT = "))
201-
.append(RcDoc::text(format!("{}", copy_stmt.size_limit)))
201+
.append(RcDoc::text(format!("{}", copy_stmt.options.size_limit)))
202202
} else {
203203
RcDoc::nil()
204204
})
205-
.append(if copy_stmt.max_files != 0 {
205+
.append(if copy_stmt.options.max_files != 0 {
206206
RcDoc::line()
207207
.append(RcDoc::text("MAX_FILES = "))
208-
.append(RcDoc::text(format!("{}", copy_stmt.max_files)))
208+
.append(RcDoc::text(format!("{}", copy_stmt.options.max_files)))
209209
} else {
210210
RcDoc::nil()
211211
})
212212
.append(
213213
RcDoc::line()
214214
.append(RcDoc::text("PURGE = "))
215-
.append(RcDoc::text(format!("{}", copy_stmt.purge))),
215+
.append(RcDoc::text(format!("{}", copy_stmt.options.purge))),
216216
)
217217
.append(
218218
RcDoc::line()
219219
.append(RcDoc::text("DISABLE_VARIANT_CHECK = "))
220-
.append(RcDoc::text(format!("{}", copy_stmt.disable_variant_check))),
220+
.append(RcDoc::text(format!(
221+
"{}",
222+
copy_stmt.options.disable_variant_check
223+
))),
221224
)
222225
}
223226

0 commit comments

Comments
 (0)