MCPcopy Create free account
hub / github.com/apache/paimon-rust / register_temp_table

Method register_temp_table

crates/integrations/datafusion/src/catalog.rs:207–247  ·  view source on GitHub ↗

Registers a temporary table or view in the specified database. Creates the database if it does not exist. Returns an error if a temp table with the same name already exists in the same database. Logs a warning if the name shadows a real Paimon table.

(
        &self,
        database: &str,
        table_name: &str,
        table: Arc<dyn TableProvider>,
    )

Source from the content-addressed store, hash-verified

205 /// Returns an error if a temp table with the same name already exists in
206 /// the same database. Logs a warning if the name shadows a real Paimon table.
207 pub fn register_temp_table(
208 &self,
209 database: &str,
210 table_name: &str,
211 table: Arc<dyn TableProvider>,
212 ) -> DFResult<()> {
213 // Warn if this shadows a real Paimon table (outside the lock — not critical)
214 let catalog = Arc::clone(&self.catalog);
215 let db = database.to_string();
216 let tbl = table_name.to_string();
217 let identifier = Identifier::new(db, tbl);
218 if let Ok(true) = block_on_with_runtime(
219 async move {
220 match catalog.get_table(&identifier).await {
221 Ok(_) => Ok::<bool, paimon::Error>(true),
222 Err(paimon::Error::TableNotExist { .. }) => Ok(false),
223 Err(_) => Ok(false),
224 }
225 },
226 "paimon catalog access thread panicked",
227 ) {
228 log::warn!(
229 "Temporary table '{database}.{table_name}' shadows an existing Paimon table"
230 );
231 }
232
233 // Atomically check-then-register under a single write lock to avoid TOCTOU
234 let mut databases = self.temp_tables.write().unwrap_or_else(|e| e.into_inner());
235 let mem_database = databases
236 .entry(database.to_string())
237 .or_insert_with(|| Arc::new(MemorySchemaProvider::new()));
238
239 // register_table returns Ok(Some(old_table)) if the name already existed
240 let old = mem_database.register_table(table_name.to_string(), table)?;
241 if old.is_some() {
242 return Err(plan_datafusion_err!(
243 "Temporary table '{database}.{table_name}' already exists"
244 ));
245 }
246 Ok(())
247 }
248
249 /// Deregisters a temporary table or view from the specified database.
250 pub fn deregister_temp_table(

Calls 5

block_on_with_runtimeFunction · 0.85
entryMethod · 0.80
register_tableMethod · 0.80
get_tableMethod · 0.45
writeMethod · 0.45