| 488 | } |
| 489 | |
| 490 | fn execute(&mut self, op: CatalogOperation) -> CatalogResult<CatalogResponse> { |
| 491 | match op { |
| 492 | CatalogOperation::Create { |
| 493 | entity_type, |
| 494 | name, |
| 495 | params, |
| 496 | } => { |
| 497 | match entity_type { |
| 498 | EntityType::Schema => { |
| 499 | // Check if schema already exists and handle IF NOT EXISTS |
| 500 | let if_not_exists = params |
| 501 | .get("if_not_exists") |
| 502 | .and_then(|v| v.as_bool()) |
| 503 | .unwrap_or(false); |
| 504 | |
| 505 | if self.schemas.contains_key(&name) { |
| 506 | if if_not_exists { |
| 507 | // Schema exists but IF NOT EXISTS was specified, so succeed silently |
| 508 | Ok(CatalogResponse::Success { |
| 509 | data: Some( |
| 510 | json!({ "message": format!("Schema '{}' already exists", name) }), |
| 511 | ), |
| 512 | }) |
| 513 | } else { |
| 514 | // Schema exists and no IF NOT EXISTS, return error |
| 515 | Err(CatalogError::DuplicateEntry(format!( |
| 516 | "Schema '{}' already exists", |
| 517 | name |
| 518 | ))) |
| 519 | } |
| 520 | } else { |
| 521 | // Schema doesn't exist, create it |
| 522 | let schema = Schema::from_params(name.clone(), ¶ms); |
| 523 | self.add_schema(schema)?; |
| 524 | Ok(CatalogResponse::Success { |
| 525 | data: Some( |
| 526 | json!({ "message": format!("Schema '{}' created", name) }), |
| 527 | ), |
| 528 | }) |
| 529 | } |
| 530 | } |
| 531 | _ => Ok(CatalogResponse::NotSupported), |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | CatalogOperation::Drop { |
| 536 | entity_type, |
| 537 | name, |
| 538 | cascade, |
| 539 | } => match entity_type { |
| 540 | EntityType::Schema => { |
| 541 | let removed = self.remove_schema(&name, cascade)?; |
| 542 | Ok(CatalogResponse::Success { |
| 543 | data: Some(serde_json::to_value(removed)?), |
| 544 | }) |
| 545 | } |
| 546 | _ => Ok(CatalogResponse::NotSupported), |
| 547 | }, |