From 0543cba6ebf5bd54a2b66721e025b9bf83472459 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Tue, 4 Oct 2022 11:48:08 +0200 Subject: [PATCH] Implement the IndexCreate batch operation --- index-scheduler/src/batch.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/index-scheduler/src/batch.rs b/index-scheduler/src/batch.rs index 473919857..a597f4161 100644 --- a/index-scheduler/src/batch.rs +++ b/index-scheduler/src/batch.rs @@ -407,7 +407,26 @@ impl IndexScheduler { index_uid, primary_key, task, - } => todo!(), + } => { + let mut wtxn = self.env.write_txn()?; + let index = self.index_mapper.create_index(&mut wtxn, &index_uid)?; + + if let Some(primary_key) = primary_key { + let mut index_wtxn = index.write_txn()?; + let mut builder = milli::update::Settings::new( + &mut index_wtxn, + &index, + self.index_mapper.indexer_config(), + ); + builder.set_primary_key(primary_key); + builder.execute(|_| ())?; + index_wtxn.commit()?; + } + + wtxn.commit()?; + + Ok(vec![task]) + } Batch::IndexUpdate { index_uid, primary_key, @@ -450,6 +469,7 @@ impl IndexScheduler { mut tasks, } => { let indexer_config = self.index_mapper.indexer_config(); + // TODO use the code from the IndexCreate operation if let Some(primary_key) = primary_key { if index.primary_key(index_wtxn)?.is_none() { let mut builder =