diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java index 578b16cc7c..d7f069eaa7 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java @@ -283,7 +283,7 @@ system.registerUDF("replace", UDFReplace.class, false); system.registerUDF("regexp_extract", UDFRegExpExtract.class, false); system.registerUDF("parse_url", UDFParseUrl.class, false); - system.registerGenericUDF("nvl", GenericUDFNvl.class); + system.registerGenericUDF("nvl", GenericUDFCoalesce.class); //HIVE-20961 system.registerGenericUDF("split", GenericUDFSplit.class); system.registerGenericUDF("str_to_map", GenericUDFStringToMap.class); system.registerGenericUDF("translate", GenericUDFTranslate.class); diff --git ql/src/test/results/clientnegative/nvl_mismatch_type.q.out ql/src/test/results/clientnegative/nvl_mismatch_type.q.out index 80406bcc8b..f60d641d46 100644 --- ql/src/test/results/clientnegative/nvl_mismatch_type.q.out +++ ql/src/test/results/clientnegative/nvl_mismatch_type.q.out @@ -40,4 +40,4 @@ POSTHOOK: query: load data local inpath '../../data/files/over1k' into table ove POSTHOOK: type: LOAD #### A masked pattern was here #### POSTHOOK: Output: default@over1k -FAILED: SemanticException [Error 10016]: Line 4:14 Argument type mismatch 'true': The first and seconds arguments of function NLV should have the same type, but they are different: "tinyint" and "boolean" +FAILED: SemanticException [Error 10016]: Line 4:14 Argument type mismatch 'true': The expressions after COALESCE should all have the same type: "tinyint" is expected but "boolean" is found diff --git ql/src/test/results/clientpositive/udf_nvl.q.out ql/src/test/results/clientpositive/udf_nvl.q.out index 32272a9a40..d072b9b2e9 100644 --- ql/src/test/results/clientpositive/udf_nvl.q.out +++ ql/src/test/results/clientpositive/udf_nvl.q.out @@ -2,16 +2,17 @@ PREHOOK: query: DESCRIBE FUNCTION nvl PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION nvl POSTHOOK: type: DESCFUNCTION -nvl(value,default_value) - Returns default value if value is null else returns value +nvl(a1, a2, ...) - Returns the first non-null argument PREHOOK: query: DESCRIBE FUNCTION EXTENDED nvl PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION EXTENDED nvl POSTHOOK: type: DESCFUNCTION -nvl(value,default_value) - Returns default value if value is null else returns value +nvl(a1, a2, ...) - Returns the first non-null argument +Synonyms: coalesce Example: - > SELECT nvl(null,'bla') FROM src LIMIT 1; - bla -Function class:org.apache.hadoop.hive.ql.udf.generic.GenericUDFNvl + > SELECT nvl(NULL, 1, NULL) FROM src LIMIT 1; + 1 +Function class:org.apache.hadoop.hive.ql.udf.generic.GenericUDFCoalesce Function type:BUILTIN PREHOOK: query: EXPLAIN SELECT NVL( 1 , 2 ) AS COL1, diff --git ql/src/test/results/clientpositive/union_offcbo.q.out ql/src/test/results/clientpositive/union_offcbo.q.out index 7d31613024..61413983de 100644 --- ql/src/test/results/clientpositive/union_offcbo.q.out +++ ql/src/test/results/clientpositive/union_offcbo.q.out @@ -294,7 +294,7 @@ STAGE PLANS: outputColumnNames: _col8, _col9, _col10, _col12, _col13, _col16, _col17, _col18, _col19 Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Filter Operator - predicate: (((NVL(_col8,-1) <> NVL(_col18,-1)) or (NVL(_col9,-1) <> NVL(_col19,-1))) and (CASE WHEN ((_col18 is not null and _col8 is null and (_col12 >= '2016-02-05'))) THEN ('DEL') WHEN ((_col18 is not null and _col8 is null and (_col12 <= '2016-02-05'))) THEN ('RET') WHEN (((_col18 = _col8) and (_col19 <> _col9))) THEN ('A_INS') ELSE ('NA') END <> 'RET') and _col18 is not null) (type: boolean) + predicate: (((COALESCE(_col8,-1) <> COALESCE(_col18,-1)) or (COALESCE(_col9,-1) <> COALESCE(_col19,-1))) and (CASE WHEN ((_col18 is not null and _col8 is null and (_col12 >= '2016-02-05'))) THEN ('DEL') WHEN ((_col18 is not null and _col8 is null and (_col12 <= '2016-02-05'))) THEN ('RET') WHEN (((_col18 = _col8) and (_col19 <> _col9))) THEN ('A_INS') ELSE ('NA') END <> 'RET') and _col18 is not null) (type: boolean) Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Select Operator expressions: _col10 (type: bigint), _col16 (type: string), _col17 (type: bigint), _col13 (type: string), _col18 (type: string), _col19 (type: string), CASE WHEN ((_col18 is not null and _col8 is null and (_col12 >= '2016-02-05'))) THEN ('DEL') WHEN ((_col18 is not null and _col8 is null and (_col12 <= '2016-02-05'))) THEN ('RET') WHEN (((_col18 = _col8) and (_col19 <> _col9))) THEN ('A_INS') ELSE ('NA') END (type: string) @@ -386,7 +386,7 @@ STAGE PLANS: outputColumnNames: _col0, _col1, _col6, _col7, _col8, _col9, _col11, _col18, _col19 Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Filter Operator - predicate: (((NVL(_col8,-1) <> NVL(_col18,-1)) or (NVL(_col9,-1) <> NVL(_col19,-1))) and (CASE WHEN ((_col18 is not null and _col8 is null and (_col11 <= _col1))) THEN ('DEL') WHEN (((_col18 is null and _col8 is not null) or ((_col18 = _col8) and (_col19 <> _col9)))) THEN ('INS') ELSE ('NA') END <> 'RET') and _col8 is not null) (type: boolean) + predicate: (((COALESCE(_col8,-1) <> COALESCE(_col18,-1)) or (COALESCE(_col9,-1) <> COALESCE(_col19,-1))) and (CASE WHEN ((_col18 is not null and _col8 is null and (_col11 <= _col1))) THEN ('DEL') WHEN (((_col18 is null and _col8 is not null) or ((_col18 = _col8) and (_col19 <> _col9)))) THEN ('INS') ELSE ('NA') END <> 'RET') and _col8 is not null) (type: boolean) Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Select Operator expressions: _col0 (type: bigint), _col6 (type: string), _col7 (type: bigint), '2099-12-31' (type: string), _col8 (type: string), _col9 (type: string), CASE WHEN ((_col18 is not null and _col8 is null and (_col11 <= _col1))) THEN ('DEL') WHEN (((_col18 is null and _col8 is not null) or ((_col18 = _col8) and (_col19 <> _col9)))) THEN ('INS') ELSE ('NA') END (type: string) @@ -644,7 +644,7 @@ STAGE PLANS: outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8 Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Filter Operator - predicate: (((NVL(_col0,-1) <> NVL(_col7,-1)) or (NVL(_col1,-1) <> NVL(_col8,-1))) and CASE WHEN ((_col0 is null and (_col3 >= '2016-02-05'))) THEN (true) WHEN ((_col0 is null and (_col3 <= '2016-02-05'))) THEN (false) WHEN (((_col7 = _col0) and (_col8 <> _col1))) THEN (true) ELSE (true) END) (type: boolean) + predicate: (((COALESCE(_col0,-1) <> COALESCE(_col7,-1)) or (COALESCE(_col1,-1) <> COALESCE(_col8,-1))) and CASE WHEN ((_col0 is null and (_col3 >= '2016-02-05'))) THEN (true) WHEN ((_col0 is null and (_col3 <= '2016-02-05'))) THEN (false) WHEN (((_col7 = _col0) and (_col8 <> _col1))) THEN (true) ELSE (true) END) (type: boolean) Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Select Operator expressions: _col2 (type: bigint), _col5 (type: string), _col6 (type: bigint), _col4 (type: string), _col7 (type: string), _col8 (type: string), CASE WHEN ((_col0 is null and (_col3 >= '2016-02-05'))) THEN ('DEL') WHEN ((_col0 is null and (_col3 <= '2016-02-05'))) THEN ('RET') WHEN (((_col7 = _col0) and (_col8 <> _col1))) THEN ('A_INS') ELSE ('NA') END (type: string) @@ -739,7 +739,7 @@ STAGE PLANS: outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6 Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Filter Operator - predicate: ((NVL(_col3,-1) <> NVL(_col5,-1)) or (NVL(_col4,-1) <> NVL(_col6,-1))) (type: boolean) + predicate: ((COALESCE(_col3,-1) <> COALESCE(_col5,-1)) or (COALESCE(_col4,-1) <> COALESCE(_col6,-1))) (type: boolean) Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Select Operator expressions: _col0 (type: bigint), _col1 (type: string), _col2 (type: bigint), '2099-12-31' (type: string), _col3 (type: string), _col4 (type: string), CASE WHEN ((_col5 is null or ((_col5 = _col3) and (_col6 <> _col4)))) THEN ('INS') ELSE ('NA') END (type: string) @@ -994,7 +994,7 @@ STAGE PLANS: outputColumnNames: _col8, _col9, _col10, _col12, _col13, _col16, _col17, _col18, _col19 Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Filter Operator - predicate: (((NVL(_col8,-1) <> NVL(_col18,-1)) or (NVL(_col9,-1) <> NVL(_col19,-1))) and _col18 is not null) (type: boolean) + predicate: (((COALESCE(_col8,-1) <> COALESCE(_col18,-1)) or (COALESCE(_col9,-1) <> COALESCE(_col19,-1))) and _col18 is not null) (type: boolean) Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Select Operator expressions: _col10 (type: bigint), _col16 (type: string), _col17 (type: bigint), _col13 (type: string), _col18 (type: string), _col19 (type: string), CASE WHEN ((_col18 is not null and _col8 is null and (_col12 >= '2016-02-05'))) THEN ('DEL') WHEN ((_col18 is not null and _col8 is null and (_col12 <= '2016-02-05'))) THEN ('RET') WHEN (((_col18 = _col8) and (_col19 <> _col9))) THEN ('A_INS') ELSE ('NA') END (type: string) @@ -1100,7 +1100,7 @@ STAGE PLANS: outputColumnNames: _col0, _col1, _col6, _col7, _col8, _col9, _col11, _col18, _col19 Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Filter Operator - predicate: (((NVL(_col8,-1) <> NVL(_col18,-1)) or (NVL(_col9,-1) <> NVL(_col19,-1))) and _col8 is not null) (type: boolean) + predicate: (((COALESCE(_col8,-1) <> COALESCE(_col18,-1)) or (COALESCE(_col9,-1) <> COALESCE(_col19,-1))) and _col8 is not null) (type: boolean) Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Select Operator expressions: _col0 (type: bigint), _col6 (type: string), _col7 (type: bigint), '2099-12-31' (type: string), _col8 (type: string), _col9 (type: string), CASE WHEN ((_col18 is not null and _col8 is null and (_col11 <= _col1))) THEN ('DEL') WHEN (((_col18 is null and _col8 is not null) or ((_col18 = _col8) and (_col19 <> _col9)))) THEN ('INS') ELSE ('NA') END (type: string) @@ -1353,7 +1353,7 @@ STAGE PLANS: outputColumnNames: _col8, _col9, _col10, _col12, _col13, _col16, _col17, _col18, _col19 Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Filter Operator - predicate: (((NVL(_col8,-1) <> NVL(_col18,-1)) or (NVL(_col9,-1) <> NVL(_col19,-1))) and _col18 is not null) (type: boolean) + predicate: (((COALESCE(_col8,-1) <> COALESCE(_col18,-1)) or (COALESCE(_col9,-1) <> COALESCE(_col19,-1))) and _col18 is not null) (type: boolean) Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Select Operator expressions: _col10 (type: bigint), _col16 (type: string), _col17 (type: bigint), _col13 (type: string), _col18 (type: string), _col19 (type: string), CASE WHEN ((_col18 is not null and _col8 is null and (_col12 >= '2016-02-05'))) THEN ('DEL') WHEN ((_col18 is not null and _col8 is null and (_col12 <= '2016-02-05'))) THEN ('RET') WHEN (((_col18 = _col8) and (_col19 <> _col9))) THEN ('A_INS') ELSE ('NA') END (type: string) @@ -1457,7 +1457,7 @@ STAGE PLANS: outputColumnNames: _col0, _col1, _col6, _col7, _col8, _col9, _col11, _col18, _col19 Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Filter Operator - predicate: (((NVL(_col8,-1) <> NVL(_col18,-1)) or (NVL(_col9,-1) <> NVL(_col19,-1))) and _col8 is not null) (type: boolean) + predicate: (((COALESCE(_col8,-1) <> COALESCE(_col18,-1)) or (COALESCE(_col9,-1) <> COALESCE(_col19,-1))) and _col8 is not null) (type: boolean) Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Select Operator expressions: _col0 (type: bigint), _col6 (type: string), _col7 (type: bigint), '2099-12-31' (type: string), _col8 (type: string), _col9 (type: string), CASE WHEN ((_col18 is not null and _col8 is null and (_col11 <= _col1))) THEN ('DEL') WHEN (((_col18 is null and _col8 is not null) or ((_col18 = _col8) and (_col19 <> _col9)))) THEN ('INS') ELSE ('NA') END (type: string) @@ -1713,7 +1713,7 @@ STAGE PLANS: outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8 Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Filter Operator - predicate: (((NVL(_col0,-1) <> NVL(_col7,-1)) or (NVL(_col1,-1) <> NVL(_col8,-1))) and CASE WHEN ((_col0 is null and (_col3 >= '2016-02-05'))) THEN (true) WHEN ((_col0 is null and (_col3 <= '2016-02-05'))) THEN (false) WHEN (((_col7 = _col0) and (_col8 <> _col1))) THEN (true) ELSE (true) END) (type: boolean) + predicate: (((COALESCE(_col0,-1) <> COALESCE(_col7,-1)) or (COALESCE(_col1,-1) <> COALESCE(_col8,-1))) and CASE WHEN ((_col0 is null and (_col3 >= '2016-02-05'))) THEN (true) WHEN ((_col0 is null and (_col3 <= '2016-02-05'))) THEN (false) WHEN (((_col7 = _col0) and (_col8 <> _col1))) THEN (true) ELSE (true) END) (type: boolean) Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Select Operator expressions: _col2 (type: bigint), _col5 (type: string), _col6 (type: bigint), _col4 (type: string), _col7 (type: string), _col8 (type: string), CASE WHEN ((_col0 is null and (_col3 >= '2016-02-05'))) THEN ('DEL') WHEN ((_col0 is null and (_col3 <= '2016-02-05'))) THEN ('RET') WHEN (((_col7 = _col0) and (_col8 <> _col1))) THEN ('A_INS') ELSE ('NA') END (type: string) @@ -1806,7 +1806,7 @@ STAGE PLANS: outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6 Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Filter Operator - predicate: ((NVL(_col3,-1) <> NVL(_col5,-1)) or (NVL(_col4,-1) <> NVL(_col6,-1))) (type: boolean) + predicate: ((COALESCE(_col3,-1) <> COALESCE(_col5,-1)) or (COALESCE(_col4,-1) <> COALESCE(_col6,-1))) (type: boolean) Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column stats: NONE Select Operator expressions: _col0 (type: bigint), _col1 (type: string), _col2 (type: bigint), '2099-12-31' (type: string), _col3 (type: string), _col4 (type: string), CASE WHEN ((_col5 is null or ((_col5 = _col3) and (_col6 <> _col4)))) THEN ('INS') ELSE ('NA') END (type: string) diff --git ql/src/test/results/clientpositive/vector_nvl.q.out ql/src/test/results/clientpositive/vector_nvl.q.out index de1cb36355..b7b7e75934 100644 --- ql/src/test/results/clientpositive/vector_nvl.q.out +++ ql/src/test/results/clientpositive/vector_nvl.q.out @@ -133,7 +133,7 @@ STAGE PLANS: TableScan Vectorization: native: true Select Operator - expressions: cfloat (type: float), NVL(cfloat,1) (type: float) + expressions: cfloat (type: float), COALESCE(cfloat,1) (type: float) outputColumnNames: _col0, _col1 Select Vectorization: className: VectorSelectOperator