我正在尝试在bash的配置单元中运行子查询。但问题是编译器说它无法识别查询中的子查询。有什么想法吗?
# !/bin/bash
echo "Hello world"
#####################################################################
# This line will connect to the database and execute the query in Hive
####################################################################
var1=$(beeline --showHeader=false --outputformat=tsv2 -u "jdbc:hive2:XXXXXXXXX" <<EOF
select $2 from $3.$1 where length($2)=(select max(length($2)) from $3.$1) limit 1;
EOF
)
#####################################################################
# This will output the result of the query
####################################################################
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
echo "We are currently analyzing Table:$1 and Column:$2"
echo "The value wth a maximum length for $1 is $var1"
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
1条答案
按热度按时间xurqigkl1#
恐怕您的查询在配置单元中无法工作,因为您执行子查询的方式不同。您必须重写查询。
请尝试下一个代码以获取最大长度的$2:
select $2 from (select max(length($2)) as length_2, $2 from $3.$1 group by $2 order by length_2 desc) a limit 1;
此外,您还可以使用-e选项执行查询,正如@mazaneicha所提到的。