Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: copy database from #3164

Merged
merged 10 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/frontend/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ use session::context::QueryContextRef;
use snafu::prelude::*;
use sql::dialect::Dialect;
use sql::parser::{ParseOptions, ParserContext};
use sql::statements::copy::CopyTable;
use sql::statements::copy::{CopyDatabase, CopyTable};
use sql::statements::statement::Statement;
use sqlparser::ast::ObjectName;
pub use standalone::StandaloneDatanodeManager;
Expand Down Expand Up @@ -487,8 +487,11 @@ pub fn check_permission(
validate_param(&copy_table_from.table_name, query_ctx)?
}
},
Statement::Copy(sql::statements::copy::Copy::CopyDatabase(stmt)) => {
validate_param(&stmt.database_name, query_ctx)?
Statement::Copy(sql::statements::copy::Copy::CopyDatabase(copy_database)) => {
match copy_database {
CopyDatabase::To(stmt) => validate_param(&stmt.database_name, query_ctx)?,
CopyDatabase::From(stmt) => validate_param(&stmt.database_name, query_ctx)?,
}
}
Statement::TruncateTable(stmt) => {
validate_param(stmt.table_name(), query_ctx)?;
Expand Down
3 changes: 3 additions & 0 deletions src/operator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ substrait.workspace = true
table.workspace = true
tokio.workspace = true
tonic.workspace = true

[dev-dependencies]
common-test-util.workspace = true
7 changes: 6 additions & 1 deletion src/operator/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ pub enum Error {
location: Location,
},

#[snafu(display("Invalid COPY DATABASE location, must end with '/': {}", value))]
InvalidCopyDatabasePath { value: String, location: Location },

#[snafu(display("Table metadata manager error"))]
TableMetadataManager {
source: common_meta::error::Error,
Expand Down Expand Up @@ -596,7 +599,9 @@ impl ErrorExt for Error {
| Error::BuildBackend { source, .. } => source.status_code(),

Error::ExecuteDdl { source, .. } => source.status_code(),
Error::InvalidCopyParameter { .. } => StatusCode::InvalidArguments,
Error::InvalidCopyParameter { .. } | Error::InvalidCopyDatabasePath { .. } => {
StatusCode::InvalidArguments
}

Error::ReadRecordBatch { source, .. } | Error::BuildColumnVectors { source, .. } => {
source.status_code()
Expand Down
26 changes: 20 additions & 6 deletions src/operator/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

mod backup;
mod copy_database;
mod copy_table_from;
mod copy_table_to;
mod ddl;
Expand Down Expand Up @@ -41,7 +41,7 @@ use query::plan::LogicalPlan;
use query::QueryEngineRef;
use session::context::QueryContextRef;
use snafu::{OptionExt, ResultExt};
use sql::statements::copy::{CopyDatabaseArgument, CopyTable, CopyTableArgument};
use sql::statements::copy::{CopyDatabase, CopyDatabaseArgument, CopyTable, CopyTableArgument};
use sql::statements::statement::Statement;
use sql::statements::OptionMap;
use sql::util::format_raw_object_name;
Expand All @@ -55,7 +55,7 @@ use crate::error::{
PlanStatementSnafu, Result, TableNotFoundSnafu,
};
use crate::insert::InserterRef;
use crate::statement::backup::{COPY_DATABASE_TIME_END_KEY, COPY_DATABASE_TIME_START_KEY};
use crate::statement::copy_database::{COPY_DATABASE_TIME_END_KEY, COPY_DATABASE_TIME_START_KEY};
use crate::table::table_idents_to_full_name;

#[derive(Clone)]
Expand Down Expand Up @@ -131,9 +131,23 @@ impl StatementExecutor {
}
}

Statement::Copy(sql::statements::copy::Copy::CopyDatabase(arg)) => {
self.copy_database(to_copy_database_request(arg, &query_ctx)?)
.await
Statement::Copy(sql::statements::copy::Copy::CopyDatabase(copy_database)) => {
match copy_database {
CopyDatabase::To(arg) => {
self.copy_database_to(
to_copy_database_request(arg, &query_ctx)?,
query_ctx.clone(),
)
.await
}
CopyDatabase::From(arg) => {
self.copy_database_from(
to_copy_database_request(arg, &query_ctx)?,
query_ctx,
)
.await
}
}
}

Statement::CreateTable(stmt) => {
Expand Down
89 changes: 0 additions & 89 deletions src/operator/src/statement/backup.rs

This file was deleted.

Loading
Loading