bowenliang123 commented on code in PR #7153:
URL: https://github.com/apache/iceberg/pull/7153#discussion_r1144160631


##########
spark/v3.2/spark/src/test/java/org/apache/iceberg/spark/TestSparkSessionCatalog.java:
##########
@@ -86,4 +87,26 @@ public void testValidateHmsUri() {
             .defaultNamespace()[0]
             .equals("default"));
   }
+
+  @Test
+  public void testLoadFunction() {
+    String envHmsUriKey = "spark.hadoop." + METASTOREURIS.varname;
+    String catalogHmsUriKey = "spark.sql.catalog.spark_catalog.uri";
+    String hmsUri = hiveConf.get(METASTOREURIS.varname);
+
+    spark
+        .conf()
+        .set("spark.sql.catalog.spark_catalog", 
"org.apache.iceberg.spark.SparkSessionCatalog");
+    spark.conf().set("spark.sql.catalog.spark_catalog.type", "hive");
+
+    spark.sessionState().catalogManager().reset();
+    spark.conf().set(envHmsUriKey, hmsUri);
+    spark.conf().set(catalogHmsUriKey, hmsUri);
+
+    String functionClass = 
"org.apache.hadoop.hive.ql.udf.generic.GenericUDFUpper";
+    String createFuncSql = String.format("CREATE FUNCTION upper AS '%s'", 
functionClass);
+    spark.sql(createFuncSql);
+    Row[] rows = (Row[]) spark.sql("SELECT upper('xyz')").collect();
+    Assert.assertEquals("XYZ", rows[0].get(0));
+  }

Review Comment:
   After checking twice, an existed problem occurs, as Iceberg's 
SparkSessionCatalog is not able to load Iceberg's built-in functions correctly. 
Even without (or with) this PR, `SELECT system.years(date('1970-01-01'))` fails.
   
   ```
   Undefined function: 'years'. This function is neither a registered temporary 
function nor a permanent function registered in the database 'system'.; line 1 
pos 7
   org.apache.spark.sql.AnalysisException: Undefined function: 'years'. This 
function is neither a registered temporary function nor a permanent function 
registered in the database 'system'.; line 1 pos 7
        at 
org.apache.spark.sql.catalyst.catalog.SessionCatalog.failFunctionLookup(SessionCatalog.scala:1561)
        at 
org.apache.spark.sql.catalyst.catalog.SessionCatalog.resolvePersistentFunctionInternal(SessionCatalog.scala:1704)
        at 
org.apache.spark.sql.catalyst.catalog.SessionCatalog.resolvePersistentFunction(SessionCatalog.scala:1673)
        at 
org.apache.spark.sql.catalyst.analysis.Analyzer$ResolveFunctions$.org$apache$spark$sql$catalyst$analysis$Analyzer$ResolveFunctions$$resolveV1Function(Analyzer.scala:2168)
        at 
org.apache.spark.sql.catalyst.analysis.Analyzer$ResolveFunctions$$anonfun$apply$25$$anonfun$applyOrElse$101.$anonfun$applyOrElse$107(Analyzer.scala:2118)
   ```
   
   An it's not covered or fixed by this PR, since this PR is implementing 
methods of Spark's `FunctionCatalog` which correctly loads Iceberg's built-in 
functions (confirmed in debugging). But the problem comes with Spark's 
`org.apache.spark.sql.catalyst.catalog.SessionCatalog.resolvePersistentFunction`.
   
   So I have to add a todo here in unit tests. And I will report an issue for 
this later.



-- 
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: [email protected]

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