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 update
sudo apt-get install make
sudo apt-get install gcc g++
sudo apt-get install libreadline-dev
sudo apt-get install unixodbc unixodbc-dev
Open odbc.ini file in the path /installpath/Progress/ DataDirect/ODBC_80_64bit and configure your Hive connection details as shown in the below sample.
Description=DataDirect 8.0 Apache Hive Wire Protocol
Save ODBC.ini file and exit.
Open a text editor and paste the following code:
odbc = require "odbc"
dbassert = odbc.assert
cnn = odbc.connect('Hive1', '<
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));
assert(stmt:closed()) -- foreach close cursor
assert(not stmt:destroyed()) -- statement valid
The above code connects to Hive using Progress DataDirect Hive ODBC driver, executes a query and prints the data. Make necessary changes to the above code that suits your need.
Open your terminal and run the below command to execute the program and you should the results printed on your terminal.
We hope this tutorial helped you to connect to Hive using Progress DataDirect ODBC driver from Lua. You can use similar steps to connect to Salesforce, SQL Server, Oracle, DB2, etc.
Note that we recommend and require use of the Progress ODBC driver manager, which is shipped with the Progress ODBC drivers. Progress DataDirect ODBC drivers are not certified with the unixODBC Driver Manager and reported issues must be reproducible with a supported version of the DataDirect ODBC Driver Manager for Unix/Linux.
Feel free to try any of the free evaluation Progress DataDirect
drivers with Lua.