@@ -488,37 +488,30 @@ class SQLViewSuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
488488 }
489489 }
490490
491- test(" create a permanent/temp view using a hive function" ) {
492- withView(" view1" , " tempView1" ) {
493- sql(s " CREATE VIEW tempView1 AS SELECT histogram_numeric(id, 5) from jt " )
494- checkAnswer(sql(" select count(*) FROM tempView1" ), Row (1 ))
495- sql(s " CREATE VIEW view1 AS SELECT histogram_numeric(id, 5) from jt " )
496- checkAnswer(sql(" select count(*) FROM view1" ), Row (1 ))
497- }
498- }
499-
500- test(" create a permanent/temp view using a built-in function" ) {
501- withView(" view1" , " tempView1" ) {
502- sql(s " CREATE TEMPORARY VIEW tempView1 AS SELECT abs(id) from jt " )
503- checkAnswer(sql(" select count(*) FROM tempView1" ), Row (9 ))
504- sql(s " CREATE VIEW view1 AS SELECT abs(id) from jt " )
505- checkAnswer(sql(" select count(*) FROM view1" ), Row (9 ))
506- }
507- }
508-
509- test(" create a permanent/temp view using a permanent function" ) {
510- val functionName = " myUpper"
511- val functionClass =
491+ test(" create a permanent/temp view using a hive, built-in, and permanent user function" ) {
492+ val permanentFuncName = " myUpper"
493+ val permanentFuncClass =
512494 classOf [org.apache.hadoop.hive.ql.udf.generic.GenericUDFUpper ].getCanonicalName
513- withUserDefinedFunction(functionName -> false ) {
514- sql(s " CREATE FUNCTION $functionName AS ' $functionClass' " )
515- withView(" view1" , " tempView1" ) {
516- withTable(" tab1" ) {
517- (1 to 10 ).map(i => s " $i" ).toDF(" id" ).write.saveAsTable(" tab1" )
518- sql(s " CREATE TEMPORARY VIEW tempView1 AS SELECT $functionName(id) from tab1 " )
519- checkAnswer(sql(" select count(*) FROM tempView1" ), Row (10 ))
520- sql(s " CREATE VIEW view1 AS SELECT $functionName(id) from tab1 " )
521- checkAnswer(sql(" select count(*) FROM view1" ), Row (10 ))
495+ val builtInFuncName = " abs"
496+ val hiveFuncName = " histogram_numeric"
497+
498+ withUserDefinedFunction(permanentFuncName -> false ) {
499+ sql(s " CREATE FUNCTION $permanentFuncName AS ' $permanentFuncClass' " )
500+ withTable(" tab1" ) {
501+ (1 to 10 ).map(i => (s " $i" , i)).toDF(" str" , " id" ).write.saveAsTable(" tab1" )
502+ Seq (" VIEW" , " TEMPORARY VIEW" ).foreach { viewMode =>
503+ withView(" view1" ) {
504+ sql(
505+ s """
506+ |CREATE $viewMode view1
507+ |AS SELECT
508+ | $permanentFuncName(str),
509+ | $builtInFuncName(id),
510+ | $hiveFuncName(id, 5) over()
511+ |FROM tab1
512+ """ .stripMargin)
513+ checkAnswer(sql(" select count(*) FROM view1" ), Row (10 ))
514+ }
522515 }
523516 }
524517 }
0 commit comments