Skip to content

Commit 2cea084

Browse files
committed
feat(search): make --catalog required and use default_catalog for vector queries
- Add `default_catalog` field to `Database` struct (returned by API) - Make `--catalog` required on `search` and `indexes create` commands instead of falling back to the active database config - Use `db.default_catalog` as the vector table prefix so the query resolves against the correct catalog alias, not the resolved name
1 parent 6204fb1 commit 2cea084

3 files changed

Lines changed: 9 additions & 30 deletions

File tree

src/command.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ pub enum Commands {
173173
#[arg(long, value_parser = ["vector", "bm25"])]
174174
r#type: Option<String>,
175175

176-
/// Catalog (database name) to search in. Defaults to the current database.
176+
/// Catalog (database id or name) to search in.
177177
#[arg(long)]
178-
catalog: Option<String>,
178+
catalog: String,
179179

180180
/// Schema to search in (default: public)
181181
#[arg(long)]
@@ -337,8 +337,8 @@ pub enum IndexesCommands {
337337

338338
/// Create an index on a table
339339
Create {
340-
/// Catalog (database name) for the table to index. Defaults to the current database.
341-
#[arg(long, conflicts_with = "dataset_id")]
340+
/// Catalog (database id or name) for the table to index.
341+
#[arg(long, conflicts_with = "dataset_id", required_unless_present = "dataset_id")]
342342
catalog: Option<String>,
343343

344344
/// Schema for the table to index (default: public)

src/databases.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct Database {
2525
#[serde(default)]
2626
pub name: Option<String>,
2727
pub default_connection_id: String,
28+
pub default_catalog: String,
2829
#[serde(default)]
2930
attachments: Vec<DatabaseAttachment>,
3031
}
@@ -891,7 +892,7 @@ mod tests {
891892

892893
fn full_detail(id: &str, name: &str, conn_id: &str) -> String {
893894
format!(
894-
r#"{{"id":"{id}","name":"{name}","default_connection_id":"{conn_id}","attachments":[]}}"#
895+
r#"{{"id":"{id}","name":"{name}","default_connection_id":"{conn_id}","default_catalog":"default","attachments":[]}}"#
895896
)
896897
}
897898

src/main.rs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -709,19 +709,7 @@ fn main() {
709709
std::process::exit(1);
710710
});
711711
let sch = schema.unwrap_or_else(|| "public".to_string());
712-
let cat = catalog
713-
.or_else(|| {
714-
crate::config::load_current_database(
715-
"default",
716-
&workspace_id,
717-
)
718-
})
719-
.unwrap_or_else(|| {
720-
eprintln!(
721-
"error: --catalog is required (or set a current database with 'hotdata databases set')"
722-
);
723-
std::process::exit(1);
724-
});
712+
let cat = catalog.unwrap();
725713
let db = databases::resolve_database(&api, &cat);
726714
let conn_id = db.default_connection_id;
727715
let auto =
@@ -851,17 +839,7 @@ fn main() {
851839
let workspace_id = resolve_workspace(workspace_id);
852840

853841
let api = api::ApiClient::new(Some(&workspace_id));
854-
let cat = catalog
855-
.or_else(|| {
856-
crate::config::load_current_database("default", &workspace_id)
857-
})
858-
.unwrap_or_else(|| {
859-
eprintln!(
860-
"error: --catalog is required (or set a current database with 'hotdata databases set')"
861-
);
862-
std::process::exit(1);
863-
});
864-
let db = databases::resolve_database(&api, &cat);
842+
let db = databases::resolve_database(&api, &catalog);
865843
let resolved_schema = schema.unwrap_or_else(|| "public".to_string());
866844
let db_id = db.id.clone();
867845
let conn_id = db.default_connection_id;
@@ -871,7 +849,7 @@ fn main() {
871849
// arguments. Use the connection ID as the catalog prefix so it resolves directly.
872850
let bm25_table = format!("{}.{}.{}", conn_id, resolved_schema, table);
873851
// vector queries run as standard SQL with X-Database-Id, so the catalog alias works.
874-
let vector_table = format!("{}.{}.{}", cat, resolved_schema, table);
852+
let vector_table = format!("{}.{}.{}", db.default_catalog, resolved_schema, table);
875853

876854
// Infer --type and --column from the table's indexes when either is omitted.
877855
let (resolved_type, resolved_column) =

0 commit comments

Comments
 (0)