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.
Error logs running with Spark 3.3.2
```
org.apache.spark.sql.AnalysisException: Undefined function: system.years;
line 1 pos 7
at
org.apache.spark.sql.errors.QueryCompilationErrors$.noSuchFunctionError(QueryCompilationErrors.scala:1797)
at
org.apache.spark.sql.catalyst.analysis.Analyzer$LookupFunctions$$anonfun$apply$23.applyOrElse(Analyzer.scala:2045)
at
org.apache.spark.sql.catalyst.analysis.Analyzer$LookupFunctions$$anonfun$apply$23.applyOrElse(Analyzer.scala:2032)
at
org.apache.spark.sql.catalyst.trees.TreeNode.$anonfun$transformDownWithPruning$1(TreeNode.scala:584)
at
org.apache.spark.sql.catalyst.trees.CurrentOrigin$.withOrigin(TreeNode.scala:176)
at
org.apache.spark.sql.catalyst.trees.TreeNode.transformDownWithPruning(TreeNode.scala:584)
at
org.apache.spark.sql.catalyst.trees.TreeNode.$anonfun$transformDownWithPruning$3(TreeNode.scala:589)
at
org.apache.spark.sql.catalyst.trees.UnaryLike.mapChildren(TreeNode.scala:1228)
at
org.apache.spark.sql.catalyst.trees.UnaryLike.mapChildren$(TreeNode.scala:1227)
at
org.apache.spark.sql.catalyst.expressions.UnaryExpression.mapChildren(Expression.scala:498)
at
org.apache.spark.sql.catalyst.trees.TreeNode.transformDownWithPruning(TreeNode.scala:589)
at
org.apache.spark.sql.catalyst.plans.QueryPlan.$anonfun$transformExpressionsDownWithPruning$1(QueryPlan.scala:159)
at
org.apache.spark.sql.catalyst.plans.QueryPlan.$anonfun$mapExpressions$1(QueryPlan.scala:200)
```
An it's not covered or fixed by this PR, since this PR is implementing
methods of Spark's `FunctionCatalog` which correctly loads built-in functions.
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]