qstommyshu commented on code in PR #15736: URL: https://github.com/apache/datafusion/pull/15736#discussion_r2047845110
########## datafusion/sql/src/parser.rs: ########## @@ -469,9 +473,101 @@ impl<'a> DFParser<'a> { } _ => { // use sqlparser-rs parser - Ok(Statement::Statement(Box::from( - self.parser.parse_statement()?, - ))) + let mut stmt = self.parser.parse_statement()?; + + use sqlparser::ast::{DataType, Expr, Spanned, Value}; + + if let sqlparser::ast::Statement::Query(query) = &mut stmt { + if let sqlparser::ast::SetExpr::Select(select) = + &mut *query.body + { + // if missing from + if select.from.is_empty() { + let mut new_projection = Vec::new(); + + for expr in &select.projection { + match expr { + sqlparser::ast::SelectItem::UnnamedExpr( + cast_expr, + ) => { + if let Expr::Cast { + expr: inner_expr, + data_type, + .. + } = cast_expr + { + let inner_str = match &**inner_expr { + Expr::Value(sqlparser::ast::ValueWithSpan { value: Value::SingleQuotedString(s), .. }) => { + format!("'{}'", s) + }, + Expr::Value(sqlparser::ast::ValueWithSpan { value: Value::Number(n, _), .. }) => { + n.clone() + }, + // TODO: need to take care of other types of values, like TimeStamp, etc... + _ => format!("{:?}", inner_expr), + }; + + // get cast to type string + let type_str = match data_type { + DataType::Int(_) => "INT", + DataType::BigInt(_) => "BIGINT", + DataType::SmallInt(_) => { + "SMALLINT" + } + DataType::Boolean => "BOOLEAN", + DataType::Varchar(_) => "VARCHAR", + DataType::Float(_) => "FLOAT", + DataType::Double(_) => "DOUBLE", + DataType::Text => "TEXT", + // TODO: need to support more DataType, probably use an Extension Trait Review Comment: We need to support a full list of enum elements for `DataType` here, this `DataType` comes from an external library. This probably means everything we update this API, we need to make accommodation as well. Or we can look into using `strum` crate to auto derive `ToString` for all `DataType`, we are currently using it for the `datafusion proto` crate. -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org