order by 在hive.mapred.mode = strict 模式下,必须指定 limit,否则执行会报错.
-- 设置严格模式set hive.mapred.mode= strict;-- 全表查询select*from user_install_status_limit orderby uptime;-- 报错信息
FAILED: SemanticException 1:49Orderby-s without limit are disabled for safety reasons.If you know what you are doing, please make sure that hive.strict.checks.large.query issettofalseand that hive.mapred.modeisnotsetto'strict'toenable them.. Error encountered near token 'uptime'-- 加上limit就正常执行.select*from user_install_status_limit orderby uptime limit10;-- 取消严格模式set hive.mapred.mode= nonstrict;
set mapred.reduce.tasks=2;insert overwrite local directory '/home/hadoop/sort_data'select*from user_install_status_limit sort by uptime;
总结
• 使用 ASC[ascdend] 或 DESC[descend] 关键字来设置查询结果是按升序或降序排列,默认按升序 ASC 排列.
• order by 后可跟多个字段,字段之间用英文逗号隔开,多个字段时,优先级按先后顺序而定.
• 若A、B都升序: order by A,B; 若A、B都用降序,必须用两个DESC: order by A DESC,B DESC;
• 若A用升序,B用降序,SQL该这样写: order by A ASC,B DESC; 也可以这样写(默认):order by A, B DESC;