java—当配置单元子查询返回null时,我得到的是预期的结果,但当它返回空时,我得到的是runtimeexception

guicsvcw  于 2021-05-27  发布在  Hadoop
关注(0)|答案(0)|浏览(221)

我必须执行一个要求如下的查询:当子查询返回null或空查询应返回x或y。当子查询返回null时,我得到了预期的结果,但当它返回空时,我得到了运行时异常。下面是配置单元查询。

select case when a.x is null then 'x' else 'y' end from (select 1 x from dual where 1 = 1) a;

上面的查询按预期工作,但是当按如下方式修改查询时,因为当where子句为1=2时,subquery返回空,结果为空,而不是x或y。

select case when a.x is null then 'x' else 'y' end from (select 1 x from dual where 1 = 2) a;

下面是输出

+------+--+
| _c0  |
+------+--+
+------+--+

因此,我重新修改了查询,如下所示

select case when a.x is null then 'x' when a.x = '' then 'x' else 'y' end from (select 1 x from dual where 1 = 2) a;

当我执行上述查询时,我得到了以下异常。

2020-03-06 05:57:21,767 WARN [main] org.apache.hadoop.mapred.YarnChild: Exception running child : java.lang.RuntimeException: Error in configuring object
    at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:109)
    at org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:75)
    at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:133)
    at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:449)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:343)
    at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:422)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1707)
    at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:106)
    ... 9 more
Caused by: java.lang.RuntimeException: Error in configuring object
    at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:109)
    at org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:75)
    at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:133)
    at org.apache.hadoop.mapred.MapRunner.configure(MapRunner.java:38)
    ... 14 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:106)
    ... 17 more
Caused by: java.lang.RuntimeException: Map operator initialization failed
    at org.apache.hadoop.hive.ql.exec.mr.ExecMapper.configure(ExecMapper.java:147)
    ... 22 more
Caused by: org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException: "boolean" is expected after WHEN, but "void" is found
    at org.apache.hadoop.hive.ql.udf.generic.GenericUDFWhen.initialize(GenericUDFWhen.java:64)
    at org.apache.hadoop.hive.ql.udf.generic.GenericUDF.initializeAndFoldConstants(GenericUDF.java:117)
    at org.apache.hadoop.hive.ql.exec.ExprNodeGenericFuncEvaluator.initialize(ExprNodeGenericFuncEvaluator.java:144)
    at org.apache.hadoop.hive.ql.exec.Operator.initEvaluators(Operator.java:954)
    at org.apache.hadoop.hive.ql.exec.Operator.initEvaluatorsAndReturnStruct(Operator.java:980)
    at org.apache.hadoop.hive.ql.exec.SelectOperator.initializeOp(SelectOperator.java:63)
    at org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:385)
    at org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:469)
    at org.apache.hadoop.hive.ql.exec.Operator.initializeChildren(Operator.java:425)
    at org.apache.hadoop.hive.ql.exec.FilterOperator.initializeOp(FilterOperator.java:66)
    at org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:385)
    at org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:469)
    at org.apache.hadoop.hive.ql.exec.Operator.initializeChildren(Operator.java:425)
    at org.apache.hadoop.hive.ql.exec.TableScanOperator.initializeOp(TableScanOperator.java:193)
    at org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:385)
    at org.apache.hadoop.hive.ql.exec.MapOperator.initializeOp(MapOperator.java:431)
    at org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:385)
    at org.apache.hadoop.hive.ql.exec.mr.ExecMapper.configure(ExecMapper.java:126)

所以基本上,当子查询返回空的外部查询并按预期执行时,但是当子查询返回空的查询抛出异常时,就会发生这种情况。有人能告诉我如何处理hivecase语句中子查询的空结果吗?以下是双表供您参考。我在Hive里创造了它。

select * from dual;
+-------------+--+
| dual.dummy  |
+-------------+--+
| X           |
+-------------+--+

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题