Apache DataFusion SQL Query Engine
impl from str for column and scalar (#762)
Jiayu Liua11a5d4dbd59
diff --git a/datafusion/src/logical_plan/expr.rs b/datafusion/src/logical_plan/expr.rsindex 2eee140f47..c3126980f4 100644--- a/datafusion/src/logical_plan/expr.rs+++ b/datafusion/src/logical_plan/expr.rs@@ -30,7 +30,9 @@ use aggregates::{AccumulatorFunctionImplementation, StateTypeFunction};use arrow::{compute::can_cast_types, datatypes::DataType};use functions::{ReturnTypeFunction, ScalarFunctionImplementation, Signature};use std::collections::{HashMap, HashSet};+use std::convert::Infallible;use std::fmt;+use std::str::FromStr;use std::sync::Arc;/// A named reference to a qualified field in a schema.@@ -153,6 +155,14 @@ impl From<&str> for Column {}}+impl FromStr for Column {+ type Err = Infallible;++ fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {+ Ok(s.into())+ }+}+impl fmt::Display for Column {fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {match &self.relation {diff --git a/datafusion/src/scalar.rs b/datafusion/src/scalar.rsindex e7354f8e62..ab08364242 100644--- a/datafusion/src/scalar.rs+++ b/datafusion/src/scalar.rs@@ -27,6 +27,8 @@ use arrow::{TimestampSecondType, UInt16Type, UInt32Type, UInt64Type, UInt8Type,},};+use std::convert::Infallible;+use std::str::FromStr;use std::{convert::TryFrom, fmt, iter::repeat, sync::Arc};/// Represents a dynamically typed, nullable single value.@@ -854,6 +856,14 @@ impl From<&str> for ScalarValue {}}+impl FromStr for ScalarValue {+ type Err = Infallible;++ fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {+ Ok(s.into())+ }+}+macro_rules! impl_try_from {($SCALAR:ident, $NATIVE:ident) => {impl TryFrom<ScalarValue> for $NATIVE {