|
58 | 58 | import org.apache.hadoop.hive.ql.io.orc.OrcInputFormat;
|
59 | 59 | import org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat;
|
60 | 60 | import org.apache.hadoop.hive.ql.io.orc.OrcSerde;
|
| 61 | +import org.apache.hadoop.hive.ql.udf.generic.GenericUDAFCount; |
61 | 62 | import org.apache.hadoop.hive.ql.udf.generic.GenericUDFAbs;
|
62 | 63 | import org.apache.hadoop.hive.serde.serdeConstants;
|
63 | 64 | import org.apache.hadoop.hive.serde2.columnar.LazyBinaryColumnarSerDe;
|
@@ -635,6 +636,35 @@ public void testTemporaryFunction() throws Exception {
|
635 | 636 | tableEnv.executeSql("drop temporary function if exists foo");
|
636 | 637 | }
|
637 | 638 |
|
| 639 | + @Test |
| 640 | + public void testTemporaryFunctionUDAF() throws Exception { |
| 641 | + // create temp function |
| 642 | + tableEnv.executeSql( |
| 643 | + String.format( |
| 644 | + "create temporary function temp_count as '%s'", |
| 645 | + GenericUDAFCount.class.getName())); |
| 646 | + String[] functions = tableEnv.listUserDefinedFunctions(); |
| 647 | + assertArrayEquals(new String[] {"temp_count"}, functions); |
| 648 | + // call the function |
| 649 | + tableEnv.executeSql("create table src(x int)"); |
| 650 | + tableEnv.executeSql("insert into src values (1),(-1)").await(); |
| 651 | + assertEquals( |
| 652 | + "[+I[2]]", |
| 653 | + queryResult(tableEnv.sqlQuery("select temp_count(x) from src")).toString()); |
| 654 | + // switch DB and the temp function can still be used |
| 655 | + tableEnv.executeSql("create database db1"); |
| 656 | + tableEnv.useDatabase("db1"); |
| 657 | + assertEquals( |
| 658 | + "[+I[2]]", |
| 659 | + queryResult(tableEnv.sqlQuery("select temp_count(x) from `default`.src")) |
| 660 | + .toString()); |
| 661 | + // drop the function |
| 662 | + tableEnv.executeSql("drop temporary function temp_count"); |
| 663 | + functions = tableEnv.listUserDefinedFunctions(); |
| 664 | + assertEquals(0, functions.length); |
| 665 | + tableEnv.executeSql("drop temporary function if exists foo"); |
| 666 | + } |
| 667 | + |
638 | 668 | @Test
|
639 | 669 | public void testCatalog() {
|
640 | 670 | List<Row> catalogs =
|
|
0 commit comments