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 fails:
   
   ```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.
   



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