1mod export;
16pub mod export_v2;
17mod import;
18pub mod import_v2;
19pub(crate) mod path;
20pub(crate) mod progress;
21mod schema_export;
22pub mod snapshot_storage;
23pub(crate) mod sql;
24mod storage_export;
25
26use clap::Subcommand;
27use client::DEFAULT_CATALOG_NAME;
28use common_error::ext::BoxedError;
29use common_telemetry::error;
30
31use crate::Tool;
32use crate::data::export::ExportCommand;
33use crate::data::export_v2::ExportV2Command;
34use crate::data::import::ImportCommand;
35use crate::data::import_v2::ImportV2Command;
36use crate::error::Result;
37
38pub(crate) const COPY_PATH_PLACEHOLDER: &str = "<PATH/TO/FILES>";
39
40#[derive(Subcommand)]
42pub enum DataCommand {
43 Export(ExportCommand),
45 Import(ImportCommand),
47 #[clap(subcommand)]
49 ExportV2(ExportV2Command),
50 ImportV2(ImportV2Command),
52}
53
54impl DataCommand {
55 pub async fn build(&self) -> std::result::Result<Box<dyn Tool>, BoxedError> {
56 match self {
57 DataCommand::Export(cmd) => cmd.build().await,
58 DataCommand::Import(cmd) => cmd.build().await,
59 DataCommand::ExportV2(cmd) => cmd.build().await,
60 DataCommand::ImportV2(cmd) => cmd.build().await,
61 }
62 }
63}
64
65pub(crate) fn default_database() -> String {
66 format!("{DEFAULT_CATALOG_NAME}-*")
67}
68
69fn collect_schema_job_results(
70 catalog: &str,
71 schemas: &[String],
72 results: Vec<Result<()>>,
73 operation: &str,
74) -> Result<()> {
75 for (schema, result) in schemas.iter().zip(&results) {
76 if let Err(error) = result {
77 error!(error; "Failed to {operation} {catalog}.{schema}");
78 }
79 }
80 for result in results {
81 result?;
82 }
83 Ok(())
84}