Connecting Kyvos semantic models to Python using SQL connection
Applies to: Kyvos Enterprise Kyvos Cloud (SaaS on AWS) Kyvos AWS Marketplace
Kyvos Azure Marketplace  Kyvos GCP Marketplace Kyvos Single Node Installation (Kyvos SNI)
This section explains how to connect Python to Kyvos semantic models using SQL connection. Use the ODBC or JDBC Driver to establish a connection.
ODBC Driver
Prerequisites
To connect Kyvos using Python, you must have the following.
Python (3 and above) must be hosted either on an analyst’s machine or on Hadoop Cluster (Cloud/On-Premises).
PYODBC moduleÂ
Kyvos ODBC Driver
Steps to connect
Download the Kyvos ODBC driver from https://www.kyvosinsights.com/kyvos-odbc-driver/
You will be asked to register yourself to download the driver and the Installation Guide to set up the driver.Install the Kyvos ODBC driver using the system administrator credentials.
Create a System DSN named KyvosDSN, as explained:
Test the connectivity with Kyvos, and save the System DSN.
Now you can start browsing the Kyvos semantic models in Python Notebook.
For example:
import pyodbc
#connection string
cnxn = pyodbc.connect('DSN=KyvosDSN;UID=xxxx;PWD=xxxx', autocommit=True)
cursor = cnxn.cursor()
#execute the prepared SQL statement
cursor.execute("SELECT `ssb`.`brand1` AS `brand1`, SUM(`ssb`.`profit`) AS `sum_profit_ok` FROM `kyvos_browsing_automationcubes`.`ssb` `ssb` WHERE ((`ssb`.`mfgr` = 'MFGR#3') AND (`ssb`.`region` = 'ASIA')) GROUP BY `ssb`.`brand1`")
#iterate the results
D1=cursor.fetchall()
for showD1 in D1:
JDBC Driver
Prerequisites
To connect Kyvos using Python, you must have the following.
Python must be installed in the machine, where Python code will execute.
JayDeBeApi module
Hive JDBC Driver
Steps to connect
To download the Hive JDBC Driver, click here.
Save the Driver at any location. For example, /data/hdisk5/put_data/HiveJDBC/hive-jdbc-uber-2.6.5.0-292.jar
To install Python, execute the yum install python3 command if not installed.
To install Pip, execute the curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py command.
To install JayDeBeApi, execute the pip3 install JayDeBeApi command.
Set JAVA_HOME, if not set.
Create a Python file that contains the script code used to run the query.
For example, Test.py is a sample file to demonstrate how to create a file and use a script code. In the script code, you can make required changes.
Following is a sample script code.import jaydebeapi from contextlib import closing jclassname='org.apache.hive.jdbc.HiveDriver' jdbc_driver_loc = '/data/hdisk5/put_data/HiveJDBC/hive-jdbc-uber-2.6.5.0-292.jar' jdbc_driver_name = 'org.apache.hive.jdbc.HiveDriver' url='jdbc:hive2://<IP Address>:<Port>/;transportMode=http;httpPath=kyvos/sql' login="userid" pwd="password" sql = "select country, sum(sale_price) as SUM_sale_price from Kyvos_RawDataAccuracyCubes.RawData_CompanysaleSF as rawdata_companysalesf group by country order by country asc limit 10000" conn = jaydebeapi.connect(jclassname=jdbc_driver_name, url=url, driver_args=[login, pwd], jars=jdbc_driver_loc.split(",")) with closing(conn) as conn: with closing(conn.cursor()) as cur: cur.execute(sql) print(cur.fetchall())
Run the python file by executing the python3 <name of the file> command. For example, the command would be python3 Test.py
Â
Copyright Kyvos, Inc. All rights reserved.