Professional Documents
Culture Documents
TABLE OF CONTENTS
1 TABLES AND VIEWS .................................................................................................................................... 3
Create tables .................................................................................................................................................... 4
Select from the table ....................................................................................................................................... 4
Listing tables and views ................................................................................................................................. 4
Loading tables from Vora into Spark ............................................................................................................. 5
Appending tables ............................................................................................................................................. 5
Dropping tables ............................................................................................................................................... 5
Creating views ................................................................................................................................................. 5
SQL VIEW ......................................................................................................................................................... 5
Dimension View ............................................................................................................................................... 6
Cube view ......................................................................................................................................................... 6
Drop views ........................................................................................................................................................ 7
Check how the view is created ....................................................................................................................... 7
2 DIFFERENT DATA TYPES ............................................................................................................................ 9
Parquet Files .................................................................................................................................................. 10
Creating a table in Vora loading data from parquet format ............................................................................. 10
Check the result ............................................................................................................................................... 10
ORC Files ........................................................................................................................................................ 11
Check the result ............................................................................................................................................... 11
3 HIERARCHIES ............................................................................................................................................. 12
Create Hierarchies ......................................................................................................................................... 13
Check the table ................................................................................................................................................ 13
Joining Hierarchies with regular tables ...................................................................................................... 13
Create the ADDRESSES table and check the values ..................................................................................... 13
Create a view of Hierarchy which will make it easier to play with later: .......................................................... 14
Join the ADDRESSES and OFFICERS tables ................................................................................................ 15
Running UDFs on the Hierarchies .............................................................................................................. 15
Returns the rank of the descendants of the root ............................................................................................. 15
Returns the address and the rank for the officers from level 2 ........................................................................ 16
2
openSAP Big Data with SAP HANA Vora
Start Zeppelin:
- Click on the connect button next to your openSAP instance on CAL
- A window will pop up. Click on Open next to Zeppelin to connect to Vora Data Modeler for the purpose of
this exercise.
- Zeppelin opens up in your browser. As you can see youll have access to the solutions of the exercises
and the create table statements via zeppelin notebooks:
- You can use the solutions as a guide while running the exercises or creating a new notebook by clicking
on Create new note and write your own solution.
- In order to run a command on your Zeppelin notebook, click on the play button as below:
3
openSAP Big Data with SAP HANA Vora
Create tables
%vora
CREATE TABLE CUSTOMER
(CUSTOMER_ID string, REGION string, LONGITUDE int, LATITUDE int, CUSTOMER_GROUP
string, LOCATION string)
USING com.sap.spark.vora
OPTIONS
(tableName "CUSTOMER", paths "/user/vora/customer_data.csv")
4
openSAP Big Data with SAP HANA Vora
Appending tables
%vora APPEND TABLE SALES OPTIONS (paths
"/user/vora/sales_2015_data.csv,/user/vora/sales_data.csv", eagerload "true")
** Now you can see the sales from 2015 data is also added Sales from 2013 and 2014
Dropping tables
%vora DROP TABLE CUSTOMER
Creating views
SQL VIEW
%vora CREATE VIEW SALES_2014
AS
(SELECT * FROM SALES
WHERE YEAR = 2014)
USING com.sap.spark.vora
%vora SELECT * FROM SALES_2014
5
openSAP Big Data with SAP HANA Vora
Dimension View
Creating a CUSTOMER Dimension from the SALES data:
%vora
CREATE DIMENSION VIEW CUSTOMERDIM
AS SELECT CUSTOMER_ID, YEAR FROM
SALES
USING com.sap.spark.vora
%vora SELECT * FROM CUSTOMERDIM
Cube view
Jouining the Customer dimension with the sales table to create a sales cube (To show how you
could join different tables and dimensions to create a cube)
%vora
CREATE CUBE VIEW SALESCUBE
AS
(SELECT * FROM CUSTOMERDIM C
JOIN
SALES S
ON C.CUSTOMER_ID = S.CUSTOMER_ID)
USING com.sap.spark.vora
6
openSAP Big Data with SAP HANA Vora
Drop views
%vora DROP VIEW SALESCUBE using com.sap.spark.vora
7
openSAP Big Data with SAP HANA Vora
8
openSAP Big Data with SAP HANA Vora
Start Zeppelin:
- Click on the connect button next to your openSAP instance on CAL
- A window will pop up. Click on Open next to Zeppelin to connect to Vora Data Modeler for the purpose of
this exercise.
- Zeppelin opens up in your browser. As you can see youll have access to the solutions of the exercises
and the create table statements via zeppelin notebooks:
- You can use the solutions as a guide while running the exercises or creating a new notebook by clicking
on Create new note and write your own solution.
- In order to run a command on your Zeppelin notebook, click on the play button as below:
9
openSAP Big Data with SAP HANA Vora
Follow the first steps in exercise 2 to open Zeppelin and run the following exercises.
Parquet Files
Creating a table in Vora loading data from parquet format
10
openSAP Big Data with SAP HANA Vora
ORC Files
%vora CREATE TABLE SALES_O(CUSTOMER_ID string, YEAR string, REVENUE bigint)
USING com.sap.spark.vora
OPTIONS (tablename "SALES_O",paths "/user/vora/sales_O.orc/*",format "orc")
11
openSAP Big Data with SAP HANA Vora
3 HIERARCHIES
Start Zeppelin:
- Click on the connect button next to your openSAP instance on CAL
- A window will pop up. Click on Open next to Zeppelin to connect to Vora Data Modeler for the purpose of
this exercise.
- Zeppelin opens up in your browser. As you can see youll have access to the solutions of the exercises
and the create table statements via zeppelin notebooks:
- You can use the solutions as a guide while running the exercises or creating a new notebook by clicking
on Create new note and write your own solution.
- In order to run a command on your Zeppelin notebook, click on the play button as below:
12
openSAP Big Data with SAP HANA Vora
Create Hierarchies
%vora CREATE TABLE OFFICERS (id int, pred int, ord int, rank string)
USING com.sap.spark.vora
OPTIONS (
tableName "OFFICERS",
paths "/user/vora/officers.csv)
13
openSAP Big Data with SAP HANA Vora
Create a view of Hierarchy which will make it easier to play with later:
%vora CREATE VIEW HV AS SELECT * FROM HIERARCHY (
USING OFFICERS AS child
JOIN PARENT par ON child.pred = par.id
SEARCH BY ord ASC
START WHERE pred=0
SET node) AS H
14
openSAP Big Data with SAP HANA Vora
15
openSAP Big Data with SAP HANA Vora
Returns the address and the rank for the officers from level 2
%vora SELECT OFFICERS.rank, ADDRESSES.address
FROM (SELECT Descendants.rank AS rank FROM HV Parents, HV Descendants
WHERE IS_DESCENDANT(Descendants.node, Parents.node) AND LEVEL(Parents.node) = 2
) OFFICERS,ADDRESSES
WHERE OFFICERS.rank = ADDRESSES.rank
16
openSAP Big Data with SAP HANA Vora
Coding Samples
Any software coding or code lines/strings (Code) provided in this documentation are only examples and are
not intended for use in a production system environment. The Code is only intended to better explain and
visualize the syntax and phrasing rules for certain SAP coding. SAP does not warrant the correctness or
completeness of the Code provided herein and SAP shall not be liable for errors or damages cause by use of
the Code, except where such damages were caused by SAP with intent or with gross negligence.
17
www.sap.com