Skip to content

Apache DataFusion SQL Query Engine

minor feat: impl FromStr for JoinType enum (#6033)

Nick Karpov9d35f4187037
diff --git a/datafusion/expr/src/logical_plan/plan.rs b/datafusion/expr/src/logical_plan/plan.rs
index 825a7b56e4..03ee55baa5 100644
--- a/datafusion/expr/src/logical_plan/plan.rs
+++ b/datafusion/expr/src/logical_plan/plan.rs
@@ -41,6 +41,7 @@ use datafusion_common::{
use std::collections::{HashMap, HashSet};
use std::fmt::{self, Debug, Display, Formatter};
use std::hash::{Hash, Hasher};
+use std::str::FromStr;
use std::sync::Arc;
/// A LogicalPlan represents the different types of relational
@@ -1160,6 +1161,27 @@ impl Display for JoinType {
}
}
+impl FromStr for JoinType {
+ type Err = DataFusionError;
+
+ fn from_str(s: &str) -> Result<Self> {
+ let s = s.to_uppercase();
+ match s.as_str() {
+ "INNER" => Ok(JoinType::Inner),
+ "LEFT" => Ok(JoinType::Left),
+ "RIGHT" => Ok(JoinType::Right),
+ "FULL" => Ok(JoinType::Full),
+ "LEFTSEMI" => Ok(JoinType::LeftSemi),
+ "RIGHTSEMI" => Ok(JoinType::RightSemi),
+ "LEFTANTI" => Ok(JoinType::LeftAnti),
+ "RIGHTANTI" => Ok(JoinType::RightAnti),
+ _ => Err(DataFusionError::NotImplemented(format!(
+ "The join type {s} does not exist or is not implemented"
+ ))),
+ }
+ }
+}
+
/// Join constraint
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum JoinConstraint {