SQL 错误消息:当前上下文中不支持 TOK_ALLCOLREF - 在 HIVE 中使用 DISTINCT 时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21088865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 00:42:16  来源:igfitidea点击:

Error Message: TOK_ALLCOLREF is not supported in current context - while Using DISTINCT in HIVE

sqlhadoophivedistinctbigdata

提问by user3107144

I'm using the simple command: SELECT DISTINCT * FROM first_working_table;in HIVE 0.11, and I'm receiving the following error message:

我正在使用简单的命令:SELECT DISTINCT * FROM first_working_table;在 HIVE 0.11 中,我收到以下错误消息:

FAILED: SemanticException TOK_ALLCOLREF is not supported in current context.

失败:当前上下文不支持 SemanticException TOK_ALLCOLREF。

Does anyone know why this is happening? How can we solve it?

有谁知道为什么会这样?我们该如何解决?

Thank you, Gal.

谢谢你,加尔。

回答by Nigel Tufnel

Hive doesn't support DISTINCT *syntax. You can manually specify every field of the table to get the same result:

Hive 不支持DISTINCT *语法。您可以手动指定表的每个字段以获得相同的结果:

SELECT DISTINCT field1, field2, ...., fieldN
  FROM first_working_table

回答by kalpesh

As specified in earlier comment distinct * not supported. Which is true. One trick can be like this.

正如之前的评论中指定的不同 * 不支持。这是真的。一招可以是这样。

Distinct * can be used in this fashion:

Distinct * 可以以这种方式使用:

select distinct * from (
select t1.col1,t1.col2,t1.col3,t2.* from t1,t2
)tbl;

I have used this syntax in Hive 2.x. So I can confirm that this works.

我在 Hive 2.x 中使用过这种语法。所以我可以确认这是有效的。