【问题标题】:SQL in Hive SemanticException [Error 10004]: Line 3:5 Invalid table alias or column referenceHive SemanticException [错误 10004] 中的 SQL:第 3:5 行无效的表别名或列引用
【发布时间】:2021-09-16 16:44:30
【问题描述】:

正在尝试找出 hive 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 将列转换为日期/时间字段所以我的图表可以将其读取为日期/时间与字符串值。

收到此错误;

错误

编译语句时出错:FAILED: SemanticException [Error 10004]: Line 3:5 Invalid table alias or column reference

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

【问题讨论】:

  • 您不能在稍后的查询中使用列别名作为源列。如果您确实需要这两列,则必须重复整个表达式,而不是引用MyLocalTime。要么,要么使用嵌套查询。

标签: sql hive hiveql


【解决方案1】:

你能试试这个吗?

如果您选择所有列以及其他内容,则需要为表设置别名并使用它来获取所有列。

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) ````
【解决方案2】:

谢谢你,我确实尝试过,但不幸的是没有运气。我确实修改了 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')`

【讨论】:

    猜你喜欢
    • 2020-04-24
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2019-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多