qstommyshu commented on code in PR #15736:
URL: https://github.com/apache/datafusion/pull/15736#discussion_r2047847506


##########
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...

Review Comment:
   This is currently only matching specific case for `select cast('1' as int)`, 
we need to support other types as well if we want to go with this idea. I'm 
thinking about a way to generalize the `Value` extraction.



-- 
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

Reply via email to