sunchao commented on a change in pull request #32407:
URL: https://github.com/apache/spark/pull/32407#discussion_r627866183



##########
File path: 
sql/core/src/test/java/test/org/apache/spark/sql/connector/catalog/functions/JavaStrLen.java
##########
@@ -73,50 +73,52 @@ public DataType resultType() {
     public String name() {
       return "strlen";
     }
+  }
 
+  public static class JavaStrLenDefault extends JavaStrLenBase {
     @Override
     public Integer produceResult(InternalRow input) {
       String str = input.getString(0);
       return str.length();
     }
   }
 
-  public static class JavaStrLenMagic implements ScalarFunction<Integer> {
-    @Override
-    public DataType[] inputTypes() {
-      return new DataType[] { DataTypes.StringType };
+  public static class JavaStrLenMagic extends JavaStrLenBase {
+    public int invoke(UTF8String str) {
+      return str.toString().length();
     }
+  }
 
-    @Override
-    public DataType resultType() {
-      return DataTypes.IntegerType;
+  public static class JavaStrLenStaticMagic extends JavaStrLenBase {
+    public static int invoke(UTF8String str) {
+      return str.toString().length();
     }
+  }
 
+  public static class JavaStrLenBoth extends JavaStrLenBase {
     @Override
-    public String name() {
-      return "strlen";
+    public Integer produceResult(InternalRow input) {
+      String str = input.getString(0);
+      return str.length();
     }
-
     public int invoke(UTF8String str) {
-      return str.toString().length();
+      return str.toString().length() + 100;
     }
   }
 
-  public static class JavaStrLenNoImpl implements ScalarFunction<Integer> {
-    @Override
-    public DataType[] inputTypes() {
-      return new DataType[] { DataTypes.StringType };
+  // even though the static magic method is present, it has incorrect 
parameter type and so Spark
+  // should fallback to the non-static magic method
+  public static class JavaStrLenBadStaticMagic extends JavaStrLenBase {
+    public static int invoke(String str) {
+      return str.length();

Review comment:
       Yes we could do that, although I think it doesn't matter much since we 
compare the result with the expected value.




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

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to