Anda di halaman 1dari 17

1_Modeler

Run SQL statements in SQL Editor


Create Joins
Create Unions
** Remember to save your views regularly.
Start Vora modeler:
Click on the connect button next to your OpenSap instance on CAL

A window will pop-up. Click on Open next to SAP HANA Vora Tools to connect to Vora
Data Modeler for the purpose of this exercise.

Click on the SQL Editor perspective

Run SQL statements in SQL Editor


In order to see your Vora tables in the modeler you have to register them first:
REGISTER ALL TABLES using com.sap.spark.vora
Run the following command to make sure you dont have the CUSTOMER_TEXT table
already created on your Vora engine.
-DROP TABLE CUSTOMER_TEXT;
-CREATE TABLE CUSTOMER_TEXT
(LANGU string, CUSTOMER_ID string, TEXT string)

USING com.sap.spark.vora
OPTIONS
(tableName "CUSTOMER_TEXT", paths "/user/vora/customer_text_data.csv");
-SELECT * FROM CUSTOMER;

Create Joins
Scenario 1:
1. Create a SQL view as STAR_CUSTOMERS

2. Drag and drop a subselect to your view, and add an alias as CUSTOMER_INFO"

3. Now we want to select dierent attributes for the customers and for that we need to
join CUSTOMER and CUSTOMER_GROUP: Double click on the subselect which you
created in step 2 and add CUSTOMER and CUSTOMER_GROUP as data sources

4. Add CUSTOMER_GROUP table the same way you added CUSTOMER table.
5. To create a join between these two tables, highlight the CUSTOMER table and click on
the join symbol as is shown in the following image and drag and drop it to
CUSTOMER_GROUP table.

6. The join window will pop up as below. Click on propose condition and you see the
common column between two tables are added as join condition. Please note that we
accepted the default type of join which is INNER join but you can change it by clicking
on the arrow next to the Type.

-Notice the join symbol and condition in the subselect view.

7. Choose CUSTOMER_ID, CUSTOMER_GROUP, LOCATION and CATEGORY


ABBREVIATION columns by clicking on the small circle next to each column name. The
circle will become black once the column is selected.

8. Now go back to your main view by clicking on the STAR_CUSTOMERS hyperlink as


below.

9. Click on the Star on top of your subselect rectangle to add all the selected columns to
the output of the view and then save your work.

Create Unions
We want to create union of the SALES and SALES_2015 tables in order to have the sales
data from 2013-2015.
10. Add SALES a from datasources same way you added CUSTOMER datasource in step
3.

11. Join the CUSTOMER_INFO with SALES table as you did in step 6.

12. Add SALES_2015 and CUSTOMER tables as you did in step 3.

13. Join CUSTOMER with SALES data as in step 6.

14. Add a resultset and use its arrow to create the connection to CUSTOMER_INFO or
SALES

15. Add another Resultset and draw a connection with the CUSTOMER or SALES_2015
table

16. Draw a connection between the one Resultset to another, using the 8 icon. By default,
the 1st result from where the union was initiated, is marked as Default ResultSet.

17. Add the columns in the following order:


CUSTOMER_ID from the CUSTOMER_INFO table and YEAR, REVENUE from
SALES_P table.
Then add CUSTOMER_ID from CUSTOMER and YEAR, REVENUE from SALES_2015
table. The selected columns will be shown in the Default ResultSet as below. The
columns in the Default ResultSet will be part of the output. The selected columns will
be shown in the Default ResultSet as below. The columns in the Default ResultSet
will be part of the output.

18. Now, Save your result and press on the SQL button to create the generated SQL and
click on close
SELECT CUSTOMER_INFO.CUSTOMER_ID , YEAR , REVENUE
FROM SALES_P
INNER JOIN ( SELECT CUSTOMER_ID , CUSTOMER_GROUP.CUSTOMER_GROUP ,
LOCATION , CATEGORY_ABBREVIATION
FROM CUSTOMER
INNER JOIN CUSTOMER_GROUP
ON CUSTOMER.CUSTOMER_GROUP = CUSTOMER_GROUP.CUSTOMER_GROUP)
CUSTOMER_INFO
ON SALES_P.CUSTOMER_ID = CUSTOMER_INFO.CUSTOMER_ID
UNION
SELECT CUSTOMER.CUSTOMER_ID , YEAR , REVENUE
FROM SALES_2015
INNER JOIN CUSTOMER
ON SALES_2015.CUSTOMER_ID = CUSTOMER.CUSTOMER_ID

12. Go back to the SQL Editor view and paste the generated SQL and click on play button
to execute the statement.

13. Notice the result has the sales from 2015 as well.

SCENARIO 2:
objectives in this scenario is to get familiar with how to use Modeler artifacts to create
Group By, Aggregations, Order By, etc. We want to figure out the average revenue per
region per year.
14. Create a new and call it STAR_CUSTOMERS2 and add CUSTOMER and SALE as data
sources.

15. Create a join between CUSTOMER and SALE as showed in step 6 and choose the
following column for the result.

16. Right click on the Revenue and choose the Edit from the drop down menu. Then
choose the AVG as aggregation function in the popped up window and type AVG_REV
as Alias.

17. Add YEAR and REVENUE to GROUP BY Revenue per year per region

18. Right click on AVG_REV and add to Order BY

19. Save and copy the generated SQL

20. The result should look as below:

Anda mungkin juga menyukai