SQL 在 Hive SemanticException [错误 10004] 中:行 3:5 无效 table 别名或列引用

SQL in Hive SemanticException [Error 10004]: Line 3:5 Invalid table alias or column reference

正在尝试弄清楚配置单元 sql,似乎在基础知识方面不太走运,但我就是不懂!!

我有一个问题;

select
from_unixtime(unix_timestamp(unixTimeStampField)+43200) as MyLocalTime,
cast(MyLocalTime as timestamp) as EventTime,
*
from mart.table
where names in ('abc','xyz')

我想做的是,首先使用 from_unixtime 将 unixtime 转换为我的当地时间,然后使用 cast 列到 date/time 字段中,因此我的图表可以将其读取为 date/time 与字符串值。

收到此错误;

错误

Error while compiling statement: FAILED: SemanticException [Error 10004]: Line 3:5 Invalid table alias or column reference

在聊天中尝试了一些建议的修复,但 none 我似乎得到了结果。提前致谢

你能试试这个吗?

如果您 select 所有列以及其他内容,您需要为 table 添加别名并使用它来获取所有列。

select
from_unixtime(unix_timestamp(unixTimeStampField)+43200) as MyLocalTime,
cast(MyLocalTime as timestamp) as EventTime,
t.*  -- You need to call the table by alias.
from mart.table t -- alias the table.
where names in ('abc','xyz')

谢谢你,我试过了,不幸的是没有运气。虽然我确实修改了 unix 转换,然后将其转换为时间戳,但似乎有效。

cast(from_unixtime(unix_timestamp(tfield)+43200)as TIMESTAMP)

看起来像这样

`select 
    cast(from_unixtime(unix_timestamp(tfield)+43200)as TIMESTAMP) as MyLocalTime, 
    * 
from 
    mart.table 
where 
    names in ('abc','xyz')`