11/**
2- * Copyright 2019-2024 LinkedIn Corporation. All rights reserved.
2+ * Copyright 2019-2025 LinkedIn Corporation. All rights reserved.
33 * Licensed under the BSD-2 Clause license.
44 * See LICENSE in the project root for license information.
55 */
@@ -236,9 +236,9 @@ public void testUdfLessThanHundred() {
236236 @ Test
237237 public void testPreserveNullabilitiesAfterApplyingOrdinalReturnTypeUDF () {
238238 String viewSql = "CREATE VIEW innerfield_with_udf "
239- + "tblproperties('functions' = 'ReturnInnerStuct :com.linkedin.coral.hive.hive2rel.CoralTestUDFReturnSecondArg', "
239+ + "tblproperties('functions' = 'ReturnInnerStruct :com.linkedin.coral.hive.hive2rel.CoralTestUDFReturnSecondArg', "
240240 + " 'dependencies' = 'ivy://com.linkedin:udf:1.0') " + "AS "
241- + "SELECT default_innerfield_with_udf_ReturnInnerStuct ('foo', innerRecord) AS innerRecord "
241+ + "SELECT default_innerfield_with_udf_ReturnInnerStruct ('foo', innerRecord) AS innerRecord "
242242 + "FROM basecomplexmixednullabilities" ;
243243
244244 TestUtils .executeCreateViewQuery ("default" , "innerfield_with_udf" , viewSql );
@@ -252,6 +252,28 @@ public void testPreserveNullabilitiesAfterApplyingOrdinalReturnTypeUDF() {
252252 TestUtils .loadSchema ("testPreserveNullabilitiesAfterApplyingOrdinalReturnTypeUDF-expected.avsc" ));
253253 }
254254
255+ @ Test
256+ public void testPreserveNullabilitiesAfterApplyingOrdinalReturnTypeUDFForNestedCalls () {
257+ String viewSql = "CREATE VIEW innerfield_with_udf "
258+ + "tblproperties('functions' = 'ReturnInnerStruct:com.linkedin.coral.hive.hive2rel.CoralTestUDFReturnSecondArg', "
259+ + " 'dependencies' = 'ivy://com.linkedin:udf:1.0') " + "AS "
260+ + "SELECT default_innerfield_with_udf_ReturnInnerStruct('foo', default_innerfield_with_udf_ReturnInnerStruct('foo', innerRecord)) AS innerRecord "
261+ + "FROM basecomplexmixednullabilities" ;
262+
263+ TestUtils .executeCreateViewQuery ("default" , "innerfield_with_udf" , viewSql );
264+
265+ ViewToAvroSchemaConverter viewToAvroSchemaConverter = ViewToAvroSchemaConverter .create (hiveMetastoreClient );
266+ Schema actualSchema = viewToAvroSchemaConverter .toAvroSchema ("default" , "innerfield_with_udf" );
267+
268+ // Inner ReturnInnerStruct call return type == Return type of it's second argument, innerRecord
269+ // Outer ReturnInnerStruct call return type == Return type of it's second argument, Inner ReturnInnerStruct call return type
270+ // Therefore, Outer ReturnInnerStruct call return type == Return type of innerRecord
271+ //
272+ // We also expect all fields to retain their nullability after applying the UDF calls
273+ Assert .assertEquals (actualSchema .toString (true ),
274+ TestUtils .loadSchema ("testPreserveNullabilitiesAfterApplyingOrdinalReturnTypeUDF-expected.avsc" ));
275+ }
276+
255277 @ Test
256278 public void testUdfGreaterThanHundred () {
257279 String viewSql = "CREATE VIEW foo_dali_udf2 "
0 commit comments