JingsongLi commented on code in PR #293:
URL: https://github.com/apache/paimon-rust/pull/293#discussion_r3168851824
##########
crates/integrations/datafusion/src/sql_context.rs:
##########
@@ -654,34 +710,61 @@ impl PaimonSqlHandler {
ok_result(&self.ctx)
}
- /// Resolve an ObjectName like `paimon.db.table` or `db.table` to a Paimon
Identifier.
- fn resolve_table_name(&self, name: &ObjectName) -> DFResult<Identifier> {
+ fn current_catalog(&self) -> DFResult<Arc<dyn Catalog>> {
+ self.catalogs
+ .get(&self.current_catalog)
+ .cloned()
+ .ok_or_else(|| {
+ DataFusionError::Plan(
+ "No catalog registered. Call register_catalog()
first.".to_string(),
+ )
+ })
+ }
+
+ /// Resolve an ObjectName like `catalog.db.table` or `db.table` to a
catalog and Identifier.
+ fn resolve_catalog_and_table(
+ &self,
+ name: &ObjectName,
+ ) -> DFResult<(Arc<dyn Catalog>, String, Identifier)> {
let parts: Vec<String> = name
.0
.iter()
.filter_map(|p| p.as_ident().map(|id| id.value.clone()))
.collect();
match parts.len() {
3 => {
- // catalog.database.table — strip catalog prefix
- if parts[0] != self.catalog_name {
- return Err(DataFusionError::Plan(format!(
- "Unknown catalog '{}', expected '{}'",
- parts[0], self.catalog_name
- )));
- }
- Ok(Identifier::new(parts[1].clone(), parts[2].clone()))
+ let catalog = self.catalogs.get(&parts[0]).ok_or_else(|| {
+ DataFusionError::Plan(format!("Unknown catalog '{}'",
parts[0]))
+ })?;
+ Ok((
+ catalog.clone(),
+ parts[0].clone(),
+ Identifier::new(parts[1].clone(), parts[2].clone()),
+ ))
+ }
+ 2 => {
+ let catalog = self.current_catalog()?;
+ Ok((
+ catalog,
+ self.current_catalog.clone(),
+ Identifier::new(parts[0].clone(), parts[1].clone()),
+ ))
}
- 2 => Ok(Identifier::new(parts[0].clone(), parts[1].clone())),
1 => Err(DataFusionError::Plan(format!(
Review Comment:
We should support it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]