67
67
import org .apache .hadoop .hive .ql .udf .generic .GenericUDF .DeferredJavaObject ;
68
68
import org .apache .hadoop .hive .ql .udf .generic .GenericUDFBaseCompare ;
69
69
import org .apache .hadoop .hive .ql .udf .generic .GenericUDFBridge ;
70
- import org .apache .hadoop .hive .ql .udf .generic .GenericUDFCase ;
71
70
import org .apache .hadoop .hive .ql .udf .generic .GenericUDFCoalesce ;
72
71
import org .apache .hadoop .hive .ql .udf .generic .GenericUDFOPAnd ;
73
72
import org .apache .hadoop .hive .ql .udf .generic .GenericUDFOPEqual ;
@@ -564,13 +563,13 @@ private static ExprNodeDesc shortcutFunction(GenericUDF udf, List<ExprNodeDesc>
564
563
ExprNodeGenericFuncDesc caseOrWhenexpr = null ;
565
564
if (newExprs .get (0 ) instanceof ExprNodeGenericFuncDesc ) {
566
565
caseOrWhenexpr = (ExprNodeGenericFuncDesc ) newExprs .get (0 );
567
- if (caseOrWhenexpr .getGenericUDF () instanceof GenericUDFWhen || caseOrWhenexpr . getGenericUDF () instanceof GenericUDFCase ) {
566
+ if (caseOrWhenexpr .getGenericUDF () instanceof GenericUDFWhen ) {
568
567
foundUDFInFirst = true ;
569
568
}
570
569
}
571
570
if (!foundUDFInFirst && newExprs .get (1 ) instanceof ExprNodeGenericFuncDesc ) {
572
571
caseOrWhenexpr = (ExprNodeGenericFuncDesc ) newExprs .get (1 );
573
- if (!(caseOrWhenexpr .getGenericUDF () instanceof GenericUDFWhen || caseOrWhenexpr . getGenericUDF () instanceof GenericUDFCase )) {
572
+ if (!(caseOrWhenexpr .getGenericUDF () instanceof GenericUDFWhen )) {
574
573
return null ;
575
574
}
576
575
}
@@ -596,21 +595,6 @@ private static ExprNodeDesc shortcutFunction(GenericUDF udf, List<ExprNodeDesc>
596
595
ExprNodeGenericFuncDesc newCaseOrWhenExpr = ExprNodeGenericFuncDesc .newInstance (childUDF ,
597
596
caseOrWhenexpr .getFuncText (), children );
598
597
return newCaseOrWhenExpr ;
599
- } else if (childUDF instanceof GenericUDFCase ) {
600
- for (i = 2 ; i < children .size (); i +=2 ) {
601
- children .set (i , ExprNodeGenericFuncDesc .newInstance (new GenericUDFOPEqual (),
602
- Lists .newArrayList (children .get (i ),newExprs .get (foundUDFInFirst ? 1 : 0 ))));
603
- }
604
- if (children .size () % 2 == 0 ) {
605
- i = children .size ()-1 ;
606
- children .set (i , ExprNodeGenericFuncDesc .newInstance (new GenericUDFOPEqual (),
607
- Lists .newArrayList (children .get (i ),newExprs .get (foundUDFInFirst ? 1 : 0 ))));
608
- }
609
- // after constant folding of child expression the return type of UDFCase might have changed,
610
- // so recreate the expression
611
- ExprNodeGenericFuncDesc newCaseOrWhenExpr = ExprNodeGenericFuncDesc .newInstance (childUDF ,
612
- caseOrWhenexpr .getFuncText (), children );
613
- return newCaseOrWhenExpr ;
614
598
} else {
615
599
// cant happen
616
600
return null ;
@@ -769,59 +753,6 @@ private static ExprNodeDesc shortcutFunction(GenericUDF udf, List<ExprNodeDesc>
769
753
}
770
754
}
771
755
772
- if (udf instanceof GenericUDFCase ) {
773
- // HIVE-9644 Attempt to fold expression like :
774
- // where (case ss_sold_date when '1998-01-01' then 1=1 else null=1 end);
775
- // where ss_sold_date= '1998-01-01' ;
776
- if (!(newExprs .size () == 3 || newExprs .size () == 4 )) {
777
- // In general case can have unlimited # of branches,
778
- // we currently only handle either 1 or 2 branch.
779
- return null ;
780
- }
781
- ExprNodeDesc thenExpr = newExprs .get (2 );
782
- ExprNodeDesc elseExpr = newExprs .size () == 4 ? newExprs .get (3 ) :
783
- new ExprNodeConstantDesc (newExprs .get (2 ).getTypeInfo (),null );
784
-
785
- if (thenExpr instanceof ExprNodeConstantDesc && elseExpr instanceof ExprNodeConstantDesc ) {
786
- ExprNodeConstantDesc constThen = (ExprNodeConstantDesc ) thenExpr ;
787
- ExprNodeConstantDesc constElse = (ExprNodeConstantDesc ) elseExpr ;
788
- Object thenVal = constThen .getValue ();
789
- Object elseVal = constElse .getValue ();
790
- if (thenVal == null ) {
791
- if (null == elseVal ) {
792
- return thenExpr ;
793
- } else if (op instanceof FilterOperator ) {
794
- return Boolean .TRUE .equals (elseVal ) ? ExprNodeGenericFuncDesc .newInstance (new GenericUDFOPNotEqual (), newExprs .subList (0 , 2 )) :
795
- Boolean .FALSE .equals (elseVal ) ? elseExpr : null ;
796
- } else {
797
- return null ;
798
- }
799
- } else if (null == elseVal && op instanceof FilterOperator ) {
800
- return Boolean .TRUE .equals (thenVal ) ? ExprNodeGenericFuncDesc .newInstance (new GenericUDFOPEqual (), newExprs .subList (0 , 2 )) :
801
- Boolean .FALSE .equals (thenVal ) ? thenExpr : null ;
802
- } else if (thenVal .equals (elseVal )){
803
- return thenExpr ;
804
- } else if (thenVal instanceof Boolean && elseVal instanceof Boolean ) {
805
- ExprNodeGenericFuncDesc equal = ExprNodeGenericFuncDesc .newInstance (
806
- new GenericUDFOPEqual (), newExprs .subList (0 , 2 ));
807
- List <ExprNodeDesc > children = new ArrayList <>();
808
- children .add (equal );
809
- children .add (new ExprNodeConstantDesc (false ));
810
- ExprNodeGenericFuncDesc func = ExprNodeGenericFuncDesc .newInstance (new GenericUDFCoalesce (),
811
- children );
812
- if (Boolean .TRUE .equals (thenVal )) {
813
- return func ;
814
- } else {
815
- List <ExprNodeDesc > exprs = new ArrayList <>();
816
- exprs .add (func );
817
- return ExprNodeGenericFuncDesc .newInstance (new GenericUDFOPNot (), exprs );
818
- }
819
- } else {
820
- return null ;
821
- }
822
- }
823
- }
824
-
825
756
if (udf instanceof GenericUDFUnixTimeStamp ) {
826
757
if (newExprs .size () >= 1 ) {
827
758
// unix_timestamp(args) -> to_unix_timestamp(args)
0 commit comments