Run HIVE HQL script on Beeline with Parameter

Cheat Code
beeline -u ‘jdbc:hive2://zk0-mycluster.mydomainads.onmicrosoft.com:2181,zk2-mycluster.mydomainads.onmicrosoft.com:2181,zk3-mycluster.mydomainads.onmicrosoft.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2-hive2’ –hivevar filedate=’2019-04-10′ –hivevar dwhdatabase=’dw_reporting_global’ –hivevar stagingdatabase=’dw_reproting_local’

Reuse, reuse, reuse!
I think this resonate very well with where we are today. Developer love to develop, but if you keep redeveloping e.g. rewriting same script again and again just for the sake of “clocking # of lines” then it’s a foolish!
In programming world we know what called parameter, it’s a magical thing that allow us to use same piece of code for different situation.
In our case we want to run Hive SQL script which load our Hive DW table but we don’t want to keep generating same script just to change some parameter like date, customer, etc. So we can use the “–hivevar” parameter magic for this.
Use the cheat code above!

If you wonder, our Hive cluster is actually hosted as Microsoft HDInsight service.

Photo by Markus Spiske temporausch.com from Pexels

Published by Feivel

We love to travel!

Leave a comment

Design a site like this with WordPress.com
Get started