Skip to content

Commit f2f3311

Browse files
committed
feat: add drop table
Signed-off-by: callum-ryan <[email protected]>
1 parent 2ba06fe commit f2f3311

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

crates/catalog/sql/src/catalog.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use async_trait::async_trait;
1919
use sqlx::{
2020
any::{install_default_drivers, AnyPoolOptions, AnyRow},
21-
Any, AnyPool, Column, Execute, Row, TypeInfo,
21+
AnyPool, Row,
2222
};
2323
use std::borrow::Cow;
2424
use std::collections::HashMap;
@@ -235,15 +235,13 @@ fn query_map(row: &AnyRow) -> std::result::Result<TableRef, sqlx::Error> {
235235
}
236236

237237
#[derive(Debug)]
238-
struct NamespaceRef {
239-
namespace_name: String,
238+
struct NamespacePropRef {
240239
namespace_prop_key: String,
241240
namespace_prop_value: String,
242241
}
243242

244-
fn query_map_namespace(row: &AnyRow) -> std::result::Result<NamespaceRef, sqlx::Error> {
245-
Ok(NamespaceRef {
246-
namespace_name: row.try_get(0)?,
243+
fn query_map_namespace(row: &AnyRow) -> std::result::Result<NamespacePropRef, sqlx::Error> {
244+
Ok(NamespacePropRef {
247245
namespace_prop_key: row.try_get(1)?,
248246
namespace_prop_value: row.try_get(2)?,
249247
})
@@ -484,8 +482,21 @@ impl Catalog for SqlCatalog {
484482
Ok(iter.next().is_some())
485483
}
486484

487-
async fn drop_table(&self, _identifier: &TableIdent) -> Result<()> {
488-
todo!()
485+
async fn drop_table(&self, identifier: &TableIdent) -> Result<()> {
486+
let catalog_name = self.name.clone();
487+
let namespace = identifier.namespace().encode_in_url();
488+
let name = identifier.name.to_string();
489+
490+
self.execute_statement(
491+
&format!(
492+
"delete from {} where {} = ? and {} = ? and {} = ?",
493+
CATALOG_TABLE_VIEW_NAME, CATALOG_NAME, TABLE_NAMESPACE, TABLE_NAME
494+
),
495+
vec![Some(&catalog_name), Some(&namespace), Some(&name)],
496+
)
497+
.await?;
498+
499+
Ok(())
489500
}
490501

491502
async fn load_table(&self, identifier: &TableIdent) -> Result<Table> {
@@ -654,6 +665,10 @@ impl Catalog for SqlCatalog {
654665

655666
async fn update_table(&self, _commit: TableCommit) -> Result<Table> {
656667
todo!()
668+
// let table_ident = commit.identifier();
669+
// let requirements = commit.take_requirements();
670+
// let updates = commit.take_updates();
671+
// let table = self.load_table(table_ident).await?;
657672
}
658673
}
659674

0 commit comments

Comments
 (0)