如何参数化Impala SQL日期在其中

发布于 2025-02-13 05:51:05 字数 1067 浏览 0 评论 0原文

我想在Impala 中对我的日期字符串进行参数化查询:

WHERE   
    (From_unixtime(Cast(MyDate AS BIGINT),'yyyy-MM-dd HH:mm:ss') >= '2022-05-01 00:00:00.000'
    AND From_unixtime(Cast(MyDate AS BIGINT),'yyyy-MM-dd HH:mm:ss') < '2022-05-31 23:59:59.000')

我的初始尝试:

SET VAR:INC_CREATE_START_DATE='2022-06-01 00:00:00.000';
SET VAR:INC_CREATE_END_DATE='2022-06-30 23:59:59.000';    
.
.
WHERE   (From_unixtime(Cast(MyDate AS BIGINT),'yyyy-MM-dd HH:mm:ss') >=$(VAR:INC_CREATE_START_DATE)
        and From_unixtime(Cast(MyDate AS BIGINT),'yyyy-MM-dd HH:mm:ss') <$(VAR:INC_CREATE_END_DATE) 

来自文档: https://impala.apache.org/docs/build3x/html/topics/impala_set.html

在Impala 2.5及更高版本中,SET还定义了Impala-Shell解释器的用户指定的替换变量。此功能使用Impala-Shell内置的SET命令,而不是SQL Set语句。因此,该替代机制仅与Impala-shell处理的查询一起工作,而不是通过JDBC或ODBC提交的查询。

还有其他选择或解决方法吗?这是非常基本的。

I would like to parametrize my date strings in an Impala Select query:

WHERE   
    (From_unixtime(Cast(MyDate AS BIGINT),'yyyy-MM-dd HH:mm:ss') >= '2022-05-01 00:00:00.000'
    AND From_unixtime(Cast(MyDate AS BIGINT),'yyyy-MM-dd HH:mm:ss') < '2022-05-31 23:59:59.000')

My initial attempt:

SET VAR:INC_CREATE_START_DATE='2022-06-01 00:00:00.000';
SET VAR:INC_CREATE_END_DATE='2022-06-30 23:59:59.000';    
.
.
WHERE   (From_unixtime(Cast(MyDate AS BIGINT),'yyyy-MM-dd HH:mm:ss') >=$(VAR:INC_CREATE_START_DATE)
        and From_unixtime(Cast(MyDate AS BIGINT),'yyyy-MM-dd HH:mm:ss') <$(VAR:INC_CREATE_END_DATE) 

From the docs: https://impala.apache.org/docs/build3x/html/topics/impala_set.html

In Impala 2.5 and higher, SET also defines user-specified substitution variables for the impala-shell interpreter. This feature uses the SET command built into impala-shell instead of the SQL SET statement. Therefore the substitution mechanism only works with queries processed by impala-shell, not with queries submitted through JDBC or ODBC.

Is there any other alternatives or workarounds? This is quite fundamental.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文