nastra commented on code in PR #9675:
URL: https://github.com/apache/iceberg/pull/9675#discussion_r1501378409
##########
spark/v3.5/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestViews.java:
##########
@@ -471,6 +471,39 @@ public void readFromViewReferencingGlobalTempView() throws
NoSuchTableException
.hasMessageContaining("cannot be found");
}
+ @Test
+ public void readFromViewReferencingTempFunction() throws
NoSuchTableException {
+ insertRows(10);
+ String viewName = viewName("viewReferencingTempFunction");
+ String functionName = "test_avg";
+ String sql = String.format("SELECT %s(id) FROM %s", functionName,
tableName);
+ sql(
+ "CREATE TEMPORARY FUNCTION %s AS
'org.apache.hadoop.hive.ql.udf.generic.GenericUDAFAverage'",
+ functionName);
+
+ ViewCatalog viewCatalog = viewCatalog();
+ Schema schema = tableCatalog().loadTable(TableIdentifier.of(NAMESPACE,
tableName)).schema();
+
+ // it wouldn't be possible to reference a TEMP FUNCTION if the view had
been created via SQL,
+ // but this can't be prevented when using the API directly
+ viewCatalog
+ .buildView(TableIdentifier.of(NAMESPACE, viewName))
+ .withQuery("spark", sql)
+ .withDefaultNamespace(NAMESPACE)
+ .withDefaultCatalog(catalogName)
+ .withSchema(schema)
+ .create();
+
+ assertThat(sql(sql)).hasSize(1).containsExactly(row(5.5));
+
+ // reading from a view that references a TEMP FUNCTION shouldn't be
possible
+ assertThatThrownBy(() -> sql("SELECT * FROM %s", viewName))
+ .isInstanceOf(AnalysisException.class)
+ .hasMessageContaining("The function")
Review Comment:
In order to do that we could pass a custom error msg in
https://github.com/apache/iceberg/blob/main/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SupportsFunctions.java#L61
instead of relying on Spark's default error msg. But that's probably something
we'd want to handle in a separate PR?
--
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]