Let’s talk about connecting to your database in Lua. For those who aren’t aware, Lua is a lightweight, powerful and efficient scripting language designed primarily for embedded systems and clients, used in many industrial applications, games (like World of Warcraft, Angry Birds) etc.,
In Lua, to be able to connect to your database, you can use an ODBC driver, but you need to install an ODBC Lua module to interact with ODBC drivers. This tutorial will walk you through how you can connect to your Hive instance using Progress DataDirect Hive ODBC driver.
Before you start, this tutorial assumes that you are using an Ubuntu, have a Hive instance to connect to and basic programming knowledge.
Open your Terminal and run the below commands to install required tools for building the code and using ODBC drivers.
sudo apt-get updatesudo apt-get install makesudo apt-get install gcc g++sudo apt-get install libreadline-devsudo apt-get install unixodbc unixodbc-dev
tar zxf lua-5.3.4.tar.gzcd lua-5.3.4make linux testcd srcsudo mv lua luac /usr/local/bin/sudo mkdir -p /usr/local/include/lua/5.3sudo mv * /usr/local/include/lua/5.3/tar zxpf luarocks-2.4.3.tar.gzcd luarocks-2.4.3./configure; sudo make bootstrapsudo luarocks install luasocketsudo luarocks install odbctar -zxf PROGRESS_DATADIRECT_ODBC_HIVE_LINUX_64.tgz./PROGRESS_DATADIRECT_ODBC_8.0_LINUX_64_INSTALL.binsudo chmod +x odbc.sh./odbc.shecho $ODBCINIexport LD_LIBRARY_PATH=/install_path/Progress/ DataDirect/ODBC_80_64bit/libexport ODBCINI=/install_path/Progress/ DataDirect/ODBC_80_64bit/odbc.iniexport ODBCINST=/ install_path/Progress/ DataDirect/ODBC_80_64bit/odbcinst.inisource ~/.bashrcodbc = require "odbc"dbassert = odbc.assertcnn = odbc.connect('Hive1', '<User>', '<Password>')stmt = cnn:execute('SELECT activityid, activitydate, url FROM pmkdatalake.activity_pageview limit 10')stmt:foreach(function(f1, f2, f3) print(string.format("activityid: %d, url: %s, activitydate: %s", f1, f3, f2));end)assert(stmt:closed()) -- foreach close cursor assert(not stmt:destroyed()) -- statement validlua <filename>.lua