...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
Applies to:Kyvos Enterprise Kyvos Azure Marketplace
Kyvos AWS Marketplace Kyvos Free (
...
This section explains how you can connect Python to Kyvos semantic models using the MDX connection.
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).
Steps to connect
- Open the Command prompt (CMD).
- Run the following command to create a test environment.
python3 -m venv python_testenv
- Run the following command to enter the test environment.
cd python_testenv
- On Windows/Mac computer, run the following command to activate the test environment.
Scripts\activate.bat
- On Linux, run the following command to activate the test environment.
source bin/activate
- Go to URL: https://github.com/may-day/olap
- Download the olap-master.zip folder as shown in the following figure.
- Extract files from the downloaded zip folder, copy the unzipped folder (named – olap-master), and paste it in the test environment folder location (created as mentioned in Step 4)
Switch to CMD and run the following commands:
Code Block language py theme Confluence linenumbers true cd olap-master cd olap-master cd xmla
Install the following libraries:
Code Block language py theme Confluence linenumbers true pip install zope pip install olap pip install xmla pip install lxml pip install zeep==3.4.0
Copy the Python Code, paste it on the notepad file, edit the code by providing your Kyvos server URL in Kyvos Server IP, Kyvos User ID, and Password (within the double quotes) on Line#3 and #4 and save the notepad file with extension .py in the C:\Users\python_testenv\olap-master\olap-master\xmla folder.
Code Block language py theme Confluence linenumbers true import olap.xmla.xmla as xmla p = xmla.XMLAProvider() c = p.connect(location="http://<Kyvos Server IP>:8081/kyvos/xmlaKyvos", auth=("<Enter Kyvos User Name>", "<Enter Kyvos Password>")) sba = """ SELECT NON EMPTY Hierarchize(AddCalculatedMembers({DrilldownLevel({[Vendor].[H_Vendor].[Hierarchy.ALL].[0]})})) DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON COLUMNS FROM [NYC] WHERE ([Measures].[fare_amount]) CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGS """ tweetRes = c.Execute(sba, Catalog="NYC") i= tweetRes.getSlice() l= tweetRes.getSlice(Axis0=0) m= tweetRes.getSlice(Axis0=0,SlicerAxis=0) print(m)
Switch to CMD and execute the script by running the following command.
Code Block language py theme Confluence linenumbers true py <filename.py>
- After the script runs, it gives an output of the MDX as shown in the following figure.
...