• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Hive on spark执行子查询报错code3

武飞扬头像
j0happy
帮助2

原始数据:

1001 2022-05-01

1001 2022-05-02

1001 2022-05-04

1001 2022-05-05

1001 2022-05-08

1001 2022-05-10

1002 2022-05-01

1002 2022-05-03

1002 2022-05-05

1002 2022-05-07

1002 2022-05-09

1002 2022-05-13

1002 2022-05-14

建表语句:

  1.  
    create table test2(
  2.  
    id string,
  3.  
    dt string)
  4.  
    row format delimited fields terminated by '\t';

插入数据:

load data local inpath '/opt/module/hive/datas/test2.txt' into table test2;

查询语句:

  1.  
    select
  2.  
     
  3.  
        id,
  4.  
     
  5.  
        dt,
  6.  
     
  7.  
        sum(if(days>2,1,0)) over(partition by id order by dt) g_id
  8.  
     
  9.  
    from
  10.  
     
  11.  
    (select
  12.  
     
  13.  
    id,dt,datediff(dt,lag(dt,1,"1970-01-01")over(partition by id order by dt)) days
  14.  
     
  15.  
    from test2)t1
学新通

报错信息:

学新通

解决办法:关闭hive的CBO优化

set hive.cbo.enable=false;

再次执行:顺利得到结果

学新通

猜测原因:

hive4.0.0之前版本的CBO优化(4.0.0版本解决了一些bug)

不支持

select

        xxx

from(

        select

                yyy

        from tmp

)t1

格式的查询语句,测试集群用的是3.1.2版本,所以需要把默认开启的CBO优化关闭。

这篇好文章是转载于:编程之路

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 编程之路
  • 本文地址: /boutique/detail/tanhggijhh
系列文章
更多 icon
同类精品
更多 icon
继续加载