【问题标题】:how to delete columns with less than 20 repetitions on a hive table如何删除配置单元表上重复次数少于 20 的列
【发布时间】:2018-12-25 16:30:26
【问题描述】:

我正在尝试了解如何删除评分表中重复不到 20 次的 user_id(不到 20 票的 id 会破坏预测)

delete * FROM rating
WHERE COUNT(user_id) <20; 

以下是我得到的错误:org.apache.hive.service.cli.HiveSQLException:编译语句时出错:FAILED:SemanticException [错误 10128]:第 3:6 行尚不支持 UDAF 'COUNT' 的位置”

【问题讨论】:

    标签: hadoop hive hortonworks-sandbox


    【解决方案1】:

    有两个大问题

    • 您的查询错误。要正常工作,您需要在 user_id 列上使用聚合函数 count 和 groupby。
    • 你不能使用delete语句删除记录,除非你的表是transactional table.

    要从非跨国表中删除记录,您需要使用insert overwrite 语句用您想要的记录覆盖该表。

    语法:

    Insert overwrite table select * from <table_name> where <condition>
    

    你的代码应该是这样的

    INSERT overwrite TABLE rating 
    SELECT * 
    FROM   rating 
    WHERE  
    user_id IN 
           ( 
            SELECT   user_id 
            FROM     rating 
            GROUP BY(user_id) 
            HAVING   count(user_id) > 20 
            );
    

    【讨论】:

      【解决方案2】:

      如果您拥有transactional table,那么您可以使用以下语句delete user_id 的计数小于20

      hive> delete from rating where user_id in 
            (select user_id from rating group by user_id having count(user_id) < 20);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-03-24
        • 2022-01-16
        • 1970-01-01
        • 1970-01-01
        • 2012-02-01
        • 2017-02-08
        • 1970-01-01
        相关资源
        最近更新 更多