2626
2727
2828import org .apache .hadoop .hive .common .type .HiveVarchar ;
29- import org .apache .hadoop .hive .conf .HiveConf ;
3029import org .apache .hadoop .hive .conf .HiveConfForTest ;
3130import org .apache .hadoop .hive .ql .exec .FunctionInfo .FunctionResource ;
3231import org .apache .hadoop .hive .ql .plan .ExprNodeDesc ;
5352import org .junit .Assert ;
5453import static org .junit .Assert .assertEquals ;
5554import static org .junit .Assert .assertFalse ;
55+ import static org .junit .Assert .assertNotNull ;
56+ import static org .junit .Assert .assertNull ;
5657import static org .junit .Assert .assertTrue ;
5758import org .junit .Before ;
5859import org .junit .After ;
@@ -97,8 +98,6 @@ public void setUp() {
9798 varchar5 = TypeInfoFactory .getPrimitiveTypeInfo ("varchar(5)" );
9899 char10 = TypeInfoFactory .getPrimitiveTypeInfo ("char(10)" );
99100 char5 = TypeInfoFactory .getPrimitiveTypeInfo ("char(5)" );
100- HiveConf conf = new HiveConfForTest (getClass ());
101- SessionState .start (conf );
102101 }
103102
104103 private void implicit (TypeInfo a , TypeInfo b , boolean convertible ) {
@@ -440,6 +439,7 @@ public void testImpliesOrder() throws Exception {
440439
441440 @ Test
442441 public void testRegisterTemporaryFunctions () throws Exception {
442+ SessionState state = SessionState .start (new HiveConfForTest (TestFunctionRegistry .class ));
443443 FunctionResource [] emptyResources = new FunctionResource [] {};
444444
445445 // UDF
@@ -463,10 +463,12 @@ public void testRegisterTemporaryFunctions() throws Exception {
463463 FunctionRegistry .registerTemporaryUDF ("tmp_explode" , GenericUDTFExplode .class , emptyResources );
464464 functionInfo = FunctionRegistry .getFunctionInfo ("tmp_explode" );
465465 assertFalse (functionInfo .isNative ());
466+ state .close ();
466467 }
467468
468469 @ Test
469470 public void testRegisterPermanentFunction () throws Exception {
471+ SessionState state = SessionState .start (new HiveConfForTest (TestFunctionRegistry .class ));
470472 FunctionResource [] emptyResources = new FunctionResource [] {};
471473
472474 // UDF
@@ -505,6 +507,7 @@ public void testRegisterPermanentFunction() throws Exception {
505507 assertTrue (functionInfo .isPersistent ());
506508 assertTrue (functionInfo .isNative ());
507509 assertFalse (functionInfo .isBuiltIn ());
510+ state .close ();
508511 }
509512
510513 @ Test
@@ -516,6 +519,7 @@ public void testBuiltInFunction() throws Exception {
516519
517520 @ Test
518521 public void testIsPermanentFunction () throws Exception {
522+ SessionState state = SessionState .start (new HiveConfForTest (TestFunctionRegistry .class ));
519523 // Setup exprNode
520524 GenericUDF udf = new GenericUDFCurrentTimestamp ();
521525 List <ExprNodeDesc > children = new ArrayList <ExprNodeDesc >();
@@ -530,6 +534,32 @@ public void testIsPermanentFunction() throws Exception {
530534 GenericUDFCurrentTimestamp .class .getName (), true , emptyResources );
531535
532536 assertTrue ("Function should now be recognized as permanent function" , FunctionRegistry .isPermanentFunction (fnExpr ));
537+ state .close ();
538+ }
539+
540+ @ Test
541+ public void testGetFunctionInfoNoSessionValidName () throws Exception {
542+ assertNotNull (FunctionRegistry .getFunctionInfo ("concat" ));
543+ }
544+
545+ @ Test
546+ public void testGetFunctionInfoNoSessionMissingName () throws Exception {
547+ assertNull (FunctionRegistry .getFunctionInfo ("nofn" ));
548+ }
549+
550+ @ Test
551+ public void testGetWindowFunctionInfoNoSessionValidName () throws Exception {
552+ assertNotNull (FunctionRegistry .getWindowFunctionInfo ("max" ));
553+ }
554+
555+ @ Test
556+ public void testGetWindowFunctionInfoNoSessionMissingName () throws Exception {
557+ assertNull (FunctionRegistry .getWindowFunctionInfo ("nofn" ));
558+ }
559+
560+ @ Test
561+ public void testGetWindowFunctionInfoNoSessionInvalidName () throws Exception {
562+ assertNull (FunctionRegistry .getWindowFunctionInfo ("concat" ));
533563 }
534564
535565 private GenericUDF getUDF (String udfName ) throws Exception {
0 commit comments