HiveQL中的变量 [英] Variables in HiveQL
问题描述
背景:
作为现代化工作的一部分,我试图将一个大型存储过程转换为HiveQL脚本.每当从Azure Data Factory触发管道时,作为蜂巢活动的一部分的HiveQL脚本便会在Azure HDInsight群集上运行.
As a part of the Modernization effort, I am trying to convert a big Stored Procedure into HiveQL script. HiveQL script, as a part of hive activity, runs on Azure HDInsight cluster whenever a Pipeline is triggered from Azure Data Factory.
我要转换的存储过程有很多使用'DECLARE'语句声明的变量.例如:
The stored procedure that I am trying to transform has a lot of variables declared using 'DECLARE' statements. For eg:
DECLARE @Variable1 INT;
这些变量中的值是使用SELECT语句设置的.例如:
Values in these variables are Set using SELECT statements. For eg:
SELECT @Variable1 = ColumnName1 FROM Table_Name;
这些变量在整个存储过程中都是这样引用的:
and these variables are referenced throughout the stored procedure like this:
SELECT * FROM Some_Table where ColumeName < @Variable1
以及许多无法进行子查询的复杂方案.
and many complex scenarios where subquerying is not possible.
如何在HiveQL中执行相同的操作?是否可以在HiveQL脚本中声明,修改和使用变量?
How can I do the same in HiveQL? Is there any way to declare, modify and use variables in HiveQL script?
推荐答案
HiveQL
不是过程语言.
您不能使用像这样的变量.
You cannot use variables like this.
HiveQL
中的变量仅是文本替换,它们不是经过计算的,而是按字面意义进行替换.
Variables in HiveQL
are just text replacement, they are not calculated and being substituted as is literally.
使用一些shell脚本或python等,或尝试 HPL/SQL
Use some shell script or python, etc or try HPL/SQL
相关答案: https://stackoverflow.com/a/37821218/2700344 和一个: https://stackoverflow.com/a/51492264/2700344 -请阅读以更好地理解hiveql中变量替换的工作原理
Related answer: https://stackoverflow.com/a/37821218/2700344 and this one: https://stackoverflow.com/a/51492264/2700344 - read for better understanding how variable substitution works in hiveql
这篇关于HiveQL中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!