Dimchikkk commented on code in PR #16456:
URL: https://github.com/apache/datafusion/pull/16456#discussion_r2156911331


##########
datafusion/sql/src/expr/substring.rs:
##########
@@ -77,8 +78,16 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
             }
         }
 
-        not_impl_err!(
-            "Substring not supported by UserDefinedExtensionPlanners: 
{substring_args:?}"
-        )
+        let fun = self
+            .context_provider
+            .get_function_meta("substr")
+            .ok_or_else(|| {
+                internal_datafusion_err!("Unable to find expected 'substr' 
function")
+            })?;
+
+        Ok(Expr::ScalarFunction(ScalarFunction::new_udf(
+            fun,
+            substring_args,
+        )))

Review Comment:
   Without this change the test started to fail:
   
   ```rs
   #[test]
   fn test_order_by_to_sql_3() {
       let statement = generate_round_trip_statement(
           GenericDialect {},
           r#"SELECT id, first_name, substr(first_name,0,5) FROM person ORDER 
BY id, substr(first_name,0,5)"#,
       );
       assert_snapshot!(
           statement,
           @r#"SELECT person.id, person.first_name, substr(person.first_name, 
0, 5) FROM person ORDER BY person.id ASC NULLS LAST, substr(person.first_name, 
0, 5) ASC NULLS LAST"#
       );
   }
   ```
   
   In the previous version substr were hitting:
   ```rs
               SQLExpr::Function(function) => {
                   self.sql_function_to_expr(function, schema, planner_context)
               }
   ```
   now it's hitting:
   ```rs
               SQLExpr::Substring {
                   expr,
                   substring_from,
                   substring_for,
                   special: _,
                   shorthand: _,
               } => self.sql_substring_to_expr(
                   expr,
                   substring_from,
                   substring_for,
                   schema,
                   planner_context,
               ),
   ```
   
   Open for suggestions if there is a better way to handle it.
   



##########
datafusion/sql/src/planner.rs:
##########
@@ -739,6 +739,12 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
             | SQLDataType::AnyType
             | SQLDataType::Table(_)
             | SQLDataType::VarBit(_)
+            | SQLDataType::UTinyInt
+            | SQLDataType::USmallInt

Review Comment:
   Not sure if the new data types should be handled here or Unsupported SQL 
type is fine.



##########
datafusion/sql/src/expr/subquery.rs:
##########
@@ -68,7 +68,18 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
             }
         }
 
-        let sub_plan = self.query_to_plan(subquery, planner_context)?;
+        let query = Query {
+            with: None,
+            body: Box::new(subquery),
+            order_by: None,
+            limit_clause: None,
+            fetch: None,
+            locks: vec![],
+            for_clause: None,
+            settings: None,
+            format_clause: None,
+        };
+        let sub_plan = self.query_to_plan(query, planner_context)?;

Review Comment:
   Not sure if I should create a new `set_expr_to_plan` function or wrapping 
subquery and passing it to `query_to_plan` is fine.



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