SAP HANA Development Basics PDF
SAP HANA Development Basics PDF
SAP HANA Development Basics PDF
Basics
December, 2017 Confidential
Agenda
Multi-core architecture
8 CPUs x (8-16) cores per blade
Parallel scaling with many blades
64-bit address space – 4 TB in current server boards
Dramatic decline in price/performance
https://global.sap.com/community/ebook/2014-09-02-hana-hardware/enEN/index.html
Compression
Partitioning
UPDATE ORDER
Technically, SAP HANA is an SET Sales = 1050
“insert-only” DBMS: WHERE ORDER = 457
Speeds up data modifications Column Column Column
Applies modifications to delta store first Order Product Sales
Less optimized columnar store Value Value Value
Delta Store
1 456 1 corn 1 1000
2 457 2 wheat 2 1050
3 458 3 corn 3 600
4 459 4 rice 4 800
Applications can still insert,
update, and delete data.
Main Store
Value Value Value
… … … … … …
102 457 102 wheat 102 900
… … … … … …
New New
Main Delta
Read
Today:
Data-intense
Application Layer
computations in
application layer
SAP HANA:
Data Layer Delegate
data-intense
operations to
data layer
• Developers will mostly work with the SAP HANA Development or Modeler perspective (you need
to switch to it manually the first time)
• The Administration console is useful to manipulate the SAP HANA data dictionary, manage
schemas, import/export data, perform interactive DB queries
The exercise for this Lesson is Exercise 1-1 in the “Student Exercise
Manual”.
BW
DSO
Openhub, RFC
Some Master
Data Tables ODBC HANA
DataServices
CRM
ABAP
Cluster tables Function calls
ODBC
Functions DS
Repo
DB2
Oracle (CVDS) ODBC
Tables, Views
▪ SAP LT uses trigger based approach. Trigger-based approach has no measureable performance
impact in source system
▪ It is based on the proven SLO technology (used for NearZeroDowntime, TDMS, etc.) used by
hundreds of customers with large DBs.
DB Trigger Write DB
Modules
Connection
Efficient initialization of data Flexible and reliable replication Fast data replication via DB connect
replication based on DB trigger process, incl. data migration LT replication functionality is fully
and delta logging concept (as used for TDMS and SAP LT) integrated with SAP HANA Studio
(as with NearZero downtime approach)
SLT HANA
HANA
Demo
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 38
SAP HANA Overview
Content and Views in the SAP HANA Studio
• Attribute View: Gives context to, and selects subset of columns and rows from data tables. Used
for all type of joins. In most cases used to model master data like entities (like Product, Location,
Business Partner)
• Analytic View: Used for calculation and aggregation (star-schema-like). Adds transactional tables
and measures (key figures), calculates aggregates (e.g. No. of Products sold per year), joins
Attribute Views. It is defined at least on one fact table. In most cases used for exposing transactional
data by joining the fact table with Attribute Views.
• Calculation View: Performs Engines cooperate with each
complex calculations not other. The SQL Optimizer
possible with other views and decides the best way to call
uses SQLScript. It can be each engine depending on the
defined as graphical view models
or scripted view.
The screen below shows you an example of the syntax used to create a table in a particular schema
using the SAP HANA Development perspective
Deprecated
• CDS Artifacts are the recommended way of defining tables, views, entity
types, associations, as well as annotating data.
• It is the new and recommended way to define database artifacts.
• You can see the Raw Data or perform some quick Analysis
• Insert data to your table using standard SQL • Use the Import / Export tools in the SAP HANA
statements on a SQL Console Studio to import DDL and data from/to the SAP
HANA server or from/to your local client
The exercises for this Lesson is Exercise 2-1 and 2-2 in the “Student
Exercise Manual”.
• Calculation Views are used to address complex business scenarios. They are created using tables,
other calculation views or the former attribute and analytic views.
Deprecated
• It is a SQL View
• A Calculation View can be queried with a SQL statement just as a standard View
• The Calculation View is a Column View stored under the schema _SYS_BIC, as for Attribute Views,
Analytic Views and Procedures created using the Modeler Content tools in the SAP HANA Studio.
• The naming pattern is the following:
• Attribute and Analytical Views are deprecated. Currently you can create
a Calculation View and later on specify which type of Information View it
will be.
• Scripted Views are also deprecated. This feature has been replaced by
Table Functions.
Add tables to Data Foundation – via drag & drop from the Catalog, or press the Add Objects button
(with the “+” sign)
We create a Dimension Calculation View based on several joined tables, for example, to display more
contact details for our Business Partners:
To join attributes, you may either right-click on the table and then click on Create Join or drag the join
arrow from one attribute on the first table to the attribute on the second table
For our business scenario we will join the NODE_KEY on the left table with the PARENT_KEY on the
right table
Returns all the rows from the left table, and all the rows from the right table.
If records fulfill the criteria, they are combined, otherwise columns will be empty.
Full Outer Join
Semantically an inner join that assumes that referential integrity is given, that is, the left table always
have an corresponding entry on the right table. Optimized or faster inner join where the right table is
Referential Join
not checked if no field from the right table is requested. Cannot be used if a filter is set on a field in
the right table.
Used to join a text table to a master data table (e.g. Material_ID Description) as requirement for
description mapping. The text join always filters on one language, and thus one needs to specify a
Text Join language column in the text table. The language is filtered based on the view settings (per default
taken from the user profile)
Used to combine the result-set of two or more SELECT. The Union operation is popular for combining
plan and actual values like CO-PA. It is not supported in the former Attribute Views, Analytical Views.
Union
http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html
Right click on the Dimension Calculation View and click on Validate, to verify the syntax
Right click on the Dimension Calculation View and click on Activate or Redeploy. A runtime object
will be created in the Catalog Schema _SYS_BIC.
Click on Add
Switch from the Data Preview (Raw Data) View to Distinct Values and click on an Attribute to display
your first analytic graphs
In your Content Package, open the Dimension Calculation View by double clicking on it.
Alternatively you can right-click on the Dimension Calculation View and click on Open.
Validate, Activate, Data Preview, etc.
The exercises for this Lesson are Exercises 2-3 and 2-4 in the
“Student Exercise Manual”.
• Cons: Fact tables are normalized (no redundancies) but dimension tables are de-normalized
(contain redundancies). No easy aggregate building. Performance issues with big dimension tables.
Changes in semantic data model mean complex table reorgs.
• Pros: Intuitive data model. Relatively few joins and tables. Easy to maintain.
Attribute
Measure
• On the Star Join level, join the Dimension Calculation View with the Fact Table defined above
• Click on Validate and then on Activate
• You can use the SQL Editor to check aggregates for the tables:
SELECT partner_guid, SUM(gross_amount)
FROM "<epm_schema>".snwd_po
GROUP by partner_guid
ORDER BY 2 DESC;
SELECT supplier_guid, SUM(gross_amount)
FROM "_SYS_BIC"."<package_name>/CV_PO"
GROUP BY supplier_guid
ORDER BY 2 DESC;
The exercises for this Lesson are Exercises 2-5, 2-6 and 2-7 in the
“Student Exercise Manual”.
Interval Use this where you want the user to specify a set start and end to
a selected Interval.
Range Use this when you want the end user to be able to use operators
such as “Greater Than” or “Less Than”.
Type Description
Currency Use this during currency conversion where the end user should
specify a source or target currency.
Date Use this to retrieve a date from the end user using a calendar
type input box.
Static List Use this when the end user should have a set list of values to
choose from.
Attribute Value When an Input Variable has this type, it serves the same
purpose as a normal Variable.
(none) If none of the above applies you do not have to specify an Input
Variable type. The Type can be left blank
Data Type Extension Allows the definition of table types without corresponding tables
(CREATE TYPE)
Procedures To push data intensive logic into the database. Supported are
(CREATE PROCEDURE) declarative (side-effect free) and imperative procedures to
encapsulate complex queries and data flows
User Defined Functions Creates side-effect free Scalar or Table functions
(CREATE FUNCTION)
© 2017 SAP SE or an SAP affiliate company. All rights reserved. 100 Confidential 100
Data Type Extensions
The SQLScript type system is based on the SQL-92 type system and supports the following
primitive data types:
VARBINARY, BLOB
© 2017 SAP SE or an SAP affiliate company. All rights reserved. 101 Confidential 101
Data Type Extensions
© 2017 SAP SE or an SAP affiliate company. All rights reserved. 102 Confidential 102
SQLScript and Procedures
• Procedures are reusable processing blocks, and describe a sequence of data transformations.
• Procedures can have multiple input and output parameters (scalar or table types).
• DROP and CREATE statements are used to modify the definition of a procedure.
• A procedure can be created as read only (without side-effects) or read-write (with side-effects).
• Read-only procedures can only call other read-only procedures.
• Procedures can be created with different languages, but SAP HANA Studio supports only SQLScript.
© 2017 SAP SE or an SAP affiliate company. All rights reserved. 103 Confidential 103
Procedure
• Cyclic dependencies that result from the intermediate result assignments or from calling other
functions are not allowed.
• A variable name is prefixed by “:” (colon) while used as input to another statement.
• A Procedure can be created using the SQL editor or using creation wizards available for the different
perspectives in the SAP HANA Studio (Modeler and Development perspectives).
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 104
Procedure creation using the SQL editor
• Syntax:
CREATE PROCEDURE {schema.}name
{({IN|OUT|INOUT} param_name data_type {,...})}
{LANGUAGE <LANG>} {SQL SECURITY <MODE>}
{READS SQL DATA {WITH RESULT VIEW <view_name>}} AS
BEGIN
...
END
▪ WITH RESULT VIEW is used to create a column view for the output parameter of type table
▪ SQL SECURITY modes defines who can call the procedure:
- INVOKER: assigned privileges / - DEFINER: only the owner
© 2017 SAP SE or an SAP affiliate company. All rights reserved. 105 Confidential 105
Calling a Procedure
Syntax
CALL [schema.]name (param1 [, ...])
• For table output parameters it is possible to either pass a (temporary) table name or to pass one of
? or NULL.
The option NULL will display the output directly on the client output screen.
© 2017 SAP SE or an SAP affiliate company. All rights reserved. 106 Confidential 106
Calling a Procedure – WITH OVERVIEW
Syntax
CALL [schema.]name (param1 [, ...]) WITH OVERVIEW
© 2017 SAP SE or an SAP affiliate company. All rights reserved. 107 Confidential 107
Calling a Procedure in Select Query
• When a procedure has been created with addition “WITH RESULT VIEW”, a column view is
generated. This column view can be used in an SQL SELECT statement.
• Column views also accept input parameters, which can be used in a query using the
‘PLACEHOLDER’ syntax as shown below.
Syntax
• Single quote ‘ ’ is used for values and double quote “ ” for identifiers
• Identifier names without double quote are converted into upper case. Double
quotes can be used to prevent this conversion.
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 109
Creation using the Modeler wizard
Deprecated
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 111
SQLScript: Calculation Engine Plan Operators
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 112
Functions
• Syntax:
CREATE [OR REPLACE] FUNCTION <function_name> (<parameter_clause>)
RETURNS <return_type>
[LANGUAGE <lang>] [SQL SECURITY <mode>]
[DEFAULT SCHEMA <default_schema_name>] [DETERMINISTIC] [WITH ENCRYPTION]
AS {
BEGIN
<function_body>
END | HEADER ONLY
}
• DETERMINISTIC is used for scalar functions to cache results
• WITH ENCRYPTION encrypts the function definition permanently
• HEADER ONLY is used to declare the function signature without specifying the body
• Help documentation
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 113
Using a Function
• A function used inside a select statement to modify the result of a selected column.
Syntax
SELECT [schema.]function (param1 [, ...]) FROM …
Example
SELECT body_mass_index (height, weight) FROM People;
Result:
BODY_MASS_INDEX(1.70, 70)
1 24,22
• If the function returns a table type you can perform a select on the function.
Syntax
SELECT * FROM [schema.]function (param1 [, ...])
© 2017 SAP SE or an SAP affiliate company. All rights reserved. 114 Confidential 114
SQLScript: Control Statement CONDITIONAL
IF <bool-expr1>
Example:
THEN
SELECT count(*) INTO found
{then-stmts1} FROM books WHERE isbn = :v_isbn;
© 2017 SAP SE or an SAP affiliate company. All rights reserved. 115 Confidential 115
SQLScript: Control Statement LOOP
Warning:
Control Statements negatively impact the planner parallelization.
Avoid them if possible. If not, push them to the end of the queries and views so that the planner can
execute as many as parallel tasks before waiting for conditions to be met.
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 116
SQLScript: Dynamic SQL
EXEC '<sql-statement>'
© 2017 SAP SE or an SAP affiliate company. All rights reserved. 117 Confidential 117
Exercise: Creating Procedures
The exercises for this Lesson are Exercises 3-1, 3-2 and 3-3 in the
“Student Exercise Manual”.
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 118
Export and Import
Exporting and importing with SAP HANA
HANA supports export and import of Information Models, tables and more
Export and Import is handled via SAP HANA Studio
Client-side export/import: to/from client PC running SAP HANA Studio
Server-side export/import: to file system of SAP HANA database server
Information Models
DB Server
Tables
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 120
Client-Side Export/Import of Information Models
• Client side export allows to export models and tables (table import to and from client supported from
SP4) to client file system.
• See Import / Export tools on the Quick Launch or clicking on the File Menu
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 121
Server side export and Import
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 122
Import with CDS
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 123
Exercise: Export and Import
The exercises for this Lesson are Exercises 4-1 and 4-2 in the
“Student Exercise Manual”. Exercises 4-3 and 4-4 are optional.
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 124
SAP HANA Performance
Modeling
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 126
General Principles
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 127
Join operations
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 128
Filter Operations
CONSTRAINT
▪ applies on a table of a cube calculation view
▪ is forced with inner join, and optional with left / referential join
▪ is executed before join and aggregation
▪ reduces data amount very early and for that it is very fast (especially when constraint is applied on a dimension
table)
WHERE
▪ applies on a tuple and has different semantic than constraint
▪ is very fast on column tables
HAVING
▪ is used to reduce the final result set after aggregation. However it has no performance gain
e.g. HAVING salesAmount > 10000
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 129
Database Expressions
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 130
SQLScript
• Query optimizer creates an execution plan that involves both storage engines even if the data reside
completely in the column store if feature used in query is not supported by column engine.
• Query should be formulated in such a way that minimizes data transfer between different engines.
• Avoid implicit type casting.
• Reduce complexity of SQL Statements. It helps in identifying common sub-expression.
• Reduce dependencies between different SQL statement and use declarative constructs to enable parallel
execution of SQL statements.
• Executing dynamic SQL is slow because compile time checks and query optimization must be done for
every invocation of the procedure.
• Avoid CURSOR (and other imperative constructs) as parallelization can’t be done.
• Consider the impact of expensive calculations (like unit and currency conversion).
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 131
SQLScript
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 132
Partitioning
• Load balancing: individual partitions may be distributed over the landscape. Queries could be
processed on multiple servers.
• Partition Pruning: scans on relevant partitions only and reduces load. Precondition is, that the query
must match the given partition specification
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 133
Performance Analysis
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 134
Execution Time measurement
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 135
Measure Expensive SQL Statement
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 136
Measure Expensive SQL Statements
Check the traced SQL statements:
Administrator view Performance Tab Expensive Statements Trace
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 137
Explain Plan
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 138
Explain Plan
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 139
Visualize Plan
Right click on the SQL statement, and select Visualize Plan (from SP4), then
• Right click on the yellow box and select Execute
• Open the yellow box using the triangle to see the Column Plan
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 140
Configure Performance Trace
To trace all SQL statements, you can configure it. It can be restricted by user.
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 141
Execute Performance Trace
After Starting the trace, execute query. Stop tracing once execution is over.
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 142
Analyze Performance Trace
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 143
Analyze Performance Trace
To analyze trace file, application HDBAdmin.sh is used. It’s required to have HDB
administrator authorization to use it.
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 144
Debugging Tools
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 145
Exercises: HANA Performance
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 146
User Management & Security
User Management and Security in SAP HANA
Create Users
Assign Initial
Passwords
Important User
Parameters
Manage Users
Assign Security Lock Users
Control Access to Reset Passwords
Objects
Check User
Row-Level Security Privileges
Restrict allowed actions Integration with BI
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 148
Types of Privileges
When accessing the SAP HANA database using a client interface (such as ODBC, JDBC, MDX), any
access to data must be backed by corresponding privileges. Different schemes are implemented
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 149
Object Privilege
In the SAP HANA database, a number of privileges are available to control the authorization of
SQL commands. Following the principle of least privilege, users should only be given the
smallest set of privileges required for their role.
Two groups of SQL Privileges are available:
System Privileges
These are system-wide privileges that control some general system
activities mainly for administrative purposes, such as creating
schema, creating and changing users and roles.
Object Privileges
These privileges are bound to an object, for example, to a database
table, and enable object-specific control activities, such as SELECT,
UPDATE, or DELETE to be performed.
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 150
Analytic Privilege - The Concept
Analytic Privileges are used to control access Implement row-level security with Analytic
to SAP HANA data models Privileges
• Without Analytic Privilege, no data can be • Restrict access to a given data container to
retrieved from selected Attribute Values
▪ Attribute Views ▪ Field from Attribute View
▪ Analytic Views ▪ Field from Attribute View used in Analytic View
▪ Calculation Views ▪ Private Dimension of Analytic View
▪ Attribute field in Calculation View
▪ Combinations of the above
▪ Single value, range, IN-list
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 151
User Provisioning - User and Role Concept
You can use the Security to manage users, roles and assign privileges
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 152
Pre-delivered Roles
Role Templates
CONTENT_ADMIN – the only role in the system with vital privileges, e.g.:
▪ SQL Privileges on Schema _SYS_BIC – with GRANT OPTION
▪ SQL Privileges on Schema _SYS_BI – with GRANT OPTION
MODELING – a very richly privileged role that enables
▪ Creation and activation of Information Models
▪ Creation and activation of Analytic Privileges
MONITORING – role with full read-only access to all meta data, monitoring and statistics
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 153
Web-based Workbench Roles
• SAP HANA Web-based Development Workbench provides an easy access to HANA features.
• It has basically the same features as the SAP HANA Studio on Eclipse.
• sap.hana.xs.ide.roles::EditorDeveloper
• sap.hana.xs.ide.roles::SecurityAdmin
• sap.hana.xs.ide.roles::TraceViewer
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 154
Exercise: User Management and Security
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 155
A Data Consumption example
using Microsoft Excel
Business Example
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 157
Microsoft Excel
Multidimensional reporting is
available via Excel Pivot Tables
“Quick and dirty” cross-tab style
reporting via Excel.
There are disadvantages as well:
The report definition is only available locally
(workarounds exist)
Subject to performance limitations of the
desktop machine where Excel runs
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 158
Procedure: Access HANA models from Excel I
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 159
Procedure: Access HANA models from Excel II
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 161
Exercise: Access HANA models from Excel
(OPTIONAL)
The exercises for this Lesson are Exercises 5-1 and 5-2 in the
“Student Exercise Manual”.
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 162
Obrigado! Inovação + Parceiros + SAP
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 164
© 2017 SAP SE or an SAP affiliate company. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate
company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its
affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and
services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as
constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop
or release any functionality mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future
developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time
for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forward-
looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place
undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.
© 2017 SAP SE or an SAP affiliate company. All rights reserved. Confidential 165