You are on page 1of 37

DMM208 – New and Best Practices for Data

Modeling with SAP HANA

Public
Speakers

Las Vegas, Oct 19 - 23 Barcelona, Nov 10 - 12

 Werner Steyn  Christoph Morgen

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 2


Agenda

 Data Modeling in SAP HANA


 New Approaches
 Best Practices

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 3


Disclaimer

This presentation outlines our general product direction and should not be relied on in making a
purchase decision. This presentation is not subject to your license agreement or any other agreement
with SAP. SAP has no obligation to pursue any course of business outlined in this presentation or to
develop or release any functionality mentioned in this presentation. This presentation and SAP's
strategy and possible future developments are subject to change and may be changed by SAP at any
time for any reason without notice. This document is provided without a warranty of any kind, either
express or implied, including but not limited to, the implied warranties of merchantability, fitness for a
particular purpose, or non-infringement. SAP assumes no responsibility for errors or omissions in this
document, except if such damages were caused by SAP intentionally or grossly negligent.

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 4


Data Modeling with SAP HANA

Overview SAP HANA Information Views

Public
SAP HANA View Modeling – Overview
Virtual Data Modeling as a key SAP HANA concept

Virtual Data Flow Models

Operational Reporting | Applications | Analytics

SAP HANA PLATFORM

HANA Views
• No persistent Aggregations | single atomic copy of data
Physical Tables • In-Memory Engines | Performance
Database Layer • Multidimensional Reporting Models
• Enterprise Applications Virtual Data Models

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 6


SAP HANA View Modeling – Overview
Flavors of SAP HANA View Modeling Approaches

Attribute Views Analytic Views Calculation View


• Compose a dimensional view • Combines Fact-Tables with • Great flexibility for advanced use
with a series of attributes derived Attribute-Views to Star-Schema- • Approach to model custom
from a collection of tables or OLAP Cube-like objects for scenarios like
e.g. Master Data Views multidimensional reporting.  Combined use of Multiple-Fact
 Highly re-used and shared in • Stores no aggregates and mass- Tables/Analytics Views
Analytic- and Calculation Views aggregates on the fly  Build Models on Normalized Data
 Used to build Hierarchies • Hierarchies are key for multi-  Re-Use and stack views
 Hierarchies are key elements in dimensional access (navigation,  Make use of custom scripted views
use with Analytic View for multi- filtering, slicing and aggregation)
dimensional reporting
© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 7
SAP HANA View Modeling – Overview
Virtual Data Models for Multidimensional Scenarios
Calculation Views are Reporting Tools can usually
usually build upon other directly consume
Calculation Views and Calculation Views.
Column Tables
Multidimensional Tools
support Hierarchies for
Navigation, Filtering and
Aggregation and HANA
Prompts (Variables & Input
Parameters) for efficient
Pre-Filtering of Data.

Calculation Views
Column table

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 8


SAP HANA View Modeling – Overview
Virtual Data Models for Normalized Data Model Scenarios
SAP HANA Calculation Views
typically feed data to
SAP HANA Calculation Business Applications (i.e. SAP
Views provide the HANA XS build Applications,
means to model Enterprise Analytical
sophisticate views based Applications)
on normalized data
structures.

Complex Calculation
Views demand a
more explicit intent
and control of the
modeled set-based
data flow, i.e. slicing,
aggregation and
filtering of sets as
input to joins, unions
etc.

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 9


SAP HANA Modeling – Graphical Editors
Eclipse-based & Web-based Development Workbench
SAP HANA Studio SAP HANA Web-based Development Workbench

Browser-based graphical View Editor


 Modeler Eclipse-perspective
Browser  http://hana-server:port/sap/hana/ide/editor/
Systems view: Supports basic Modeling artifacts.
(no support for functions, roles, CDS objects, repository)  No Analytic- and Attribute-view Modeling support
 Supports Calculation Models (table functions, roles,
 Development Eclipse-perspective procedures, script based calc-models, analytical privileges etc.)
Project/Navigator/Repository view: Support all design-
time artifacts and repository functionality.  SQL Editor support, Catalog, Security, Admin, etc.
Note: Web-based editors are future/mid-term innovation platform for SAP HANA
development tools, however currently not yet feature complete (SAP HANA SPS10).

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 10


New Approaches

SAP HANA Information Models

Public
SAP HANA View Modeling – New Approaches
New Approaches Overview
Key new approaches
Specific Enhancements
 Calculation View Modeling
• Column lineage analysis
– Calculation views-Star-join instead of Analytical/Attribute
• Comment & View Deprecation
 SQL-Script Integration • Copy & Replace nodes!
– Table functions as data sources • Multilanguage-label support in Views
(instead of script-based Calculation Views) • Performance Analysis / Debugger enhancements
• Support Labels/Descriptions in value help dialogs
 Analytic Privileges
– Support for SQL based analytic privileges

 Hierarchies
– SQL enablement & Time Dependent hierarchies General Enhancements
• Implicit SQL Execution - Model unfolding
 Data Sources
– CDS entities, tenant container database tables

 Web-based Editor

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 12


SAP HANA View Modeling – New Approaches
Modeling multidimensional Scenarios in Calculation Views
Calculation Views
Multidimensional scenarios in Calculation Views Attribute View
 Calculation Views of type Dimension
– Composing Dimension-Attributes and -Hierarchies
 Calculation Views of type CUBE with StarJoin
– Star-joins fact data with dimension-type calculation views
like Analytic Views (with same performance guidance's)
– Implicit Calculation View optimization will evaluate
to delegate processing to same execution behavior as Analytic Views
 Note: Table functions can be used as input sources for either Dimensions or Analytic View
Facts

Usage Scenario
 Implement new multidimensional scenarios / new projects
 Seek to refactor Attribute-/Analytic View scenarios

Note: As of SAP HANA SPS10 Calculation Views are not yet functional feature equivalent to Attribute- and Analytic Views (i.e. Temporal Join & Fuzzy search).

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 13


SAP HANA View Modeling – New Approaches
Scripting custom Data Flow Scenarios
Enabling SQL Script with Calculation views
• Going forward use SQL Script table functions instead of script-based Calculation views
 Side-effect free read-only functions using standard SQL
 Consume data from tables, models, functions, function QuarterToDateByYear(
in ip_period varchar(1), in ip_date varchar(10)
predictive algorithms, etc. )
 Script based-calculation models can be re-factored into returns series_data_t

table functions New!


language sqlscript sql security invoker as
begin SQL
Graphical Calculation View sd = select source_period_start, source_period_end
Historical referencing Table function from series_disaggregate_date ('interval 3 month',
Script-based Calculation View 'interval 1 day',:v_year,:v_next_year);

if :ip_period = 'c' then


return select
bb.generated_period_start as generatedperiodstart,
aa.generated_period_start as factdate,
bb.generated_period_start as datesql,
'qtd' as "timekpi", 'cy' as cypy_flag
from …

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 14


© SAP AG 2011
SAP HANA View Modeling – New Approaches
Scripting custom Data Flow Scenarios
SQL Script approaches
• Standard SQL versus Calculation Engine (CE Functions) Plan Operators
 Recommendation! When creating functions or procedures with SAP HANA SP09+ use standard SQL syntax
instead of CE Functions. The SQL optimizer is able to leverage alternative execution engines and are not
restricted only to the Calculation Engine

Recommended approach

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 15


© SAP AG 2011
SAP HANA View Modeling – New Approaches
New Design-time Data Sources
New data sources for Calculation Views
 Multitenant database container tables  CDS (Entities and Types)
– While modeling graphical calculation views, you can add data – Graceful data structure lifecycle
source from any of the isolated databases.

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 16


SAP HANA View Modeling – New Approaches
Modeling with Virtual and Extended Tables
Leveraging “warm data” Leveraging “cold data”
Consuming non-In Memory data in Calculation views from SAP HANA via SAP HANA
Dynamic Tiering Smart Data Access
 Dynamic Tiering external tables virtual tables
– Provides a disk-based columnar SAP HANA database extension using
SAP HANA external tables (extended tables) *
 Smart Data Access
– Provides a virtual access layer to outside SAP HANA data (e.g. other
databases, Hadoop systems, etc.) using so-called virtual tables

 Model and approach these scenarios carefully and monitoring query


performance
– Remote data imposes a natural break in the execution
– Ensure that filters and aggregation is pushed to remote sources
– Use and observer join settings and optimizations
– Implement input source pruning (explicit or implicit) techniques

*Supported external systems and restrictions are documented in SAP Note 1868209

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 17


SAP HANA View Modeling – New Approaches
Calculation View Enhancements – Hierarchies
Hierarchy SQL Integration
 Hierarchy-based SQL processing capabilities enabled
via SAP HANA View based hierarchies
– SQL processing includes hierarchy-based filtering,
aggregations as well as analytic privileges*.
 Usage scenario and enablement
– Shared hierarchies from Dimension-Type and StarJoin-Type
Calculation Views. Compound parent-child hierarchies are
not allowed.
– SQL use of hierarchies needs to be activated in the view
properties (for all shared hierarchies). Once activated
custom node-column name and hierarchy-expression
parameter* can be given custom name

*Note: Use of hierarchy expression will be fully enabled, once hierarchy-expressions are
documented in the SAP HANA SQL documentation and thus generally supported.

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 18


SAP HANA View Modeling – New Approaches
Calculation View Enhancements – Hierarchies
Hierarchy SQL Integration
Hierarchy
 Hierarchy-aggregation Prompts
– The node column can be used for group by:

– ..
 Filtering on a hierarchy node value
– The node column can be used for filtering

Note, the Revenue and Cost column contain the hierarchical


aggregated values, i.e. the Revenue for MAJESTIX is the sum of the
revenue of all its child nodes.
The calculated column Margin (percentage) is calculated correctly Note, that the filter on the node column constrains to the hierarchy subtree. All the
after the aggregation on each hierarchy level. descendants of the node are selected

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 19


SAP HANA View Modeling - New Approaches
Analytic Privileges Editor – SQL-based Analytic Privileges
Create SQL-based Analytic Privileges
 Start with general Attribute based Analytic Privilege, then switch to SQL-based

 Use SQL Hierarchies within SQL Analytical Privileges

SalesHierarchyNode = MAJESTIX

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 20


Best Practices

SAP HANA Information Models

Public
SAP HANA View Modeling – Best Practices
General Performance Guidelines
Avoid transfer data of large result sets between the HANA DB and client
application

Client A G Y Z
Do calculation after aggregation
Avoid Complex expressions, instead push down into model

Aggregate data records (e.g using GROUP BY,


A G Y
reducing Columns)
Calculation Views
Join on Key Columns or Indexed Columns
Procedures / Functions A B C D G Y

Avoid calculations before aggregation


on line item level
Replace sequential cursor looping with
A B C
set processing
A B C

A B C Filter data amount as early as possible in


Column the lower layers (e.g using Constraints,
WHERE clause filters, Analytical
Privileges, Partitioning)
Store

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 22


SAP HANA View Modeling – Best Practices
Optimized Calculation View Execution
Optimized execution for SQL-queries against Calculation Views
 The initial Calculation Engine optimization generates a single SQL statement across a stacked model,
which is then passed to the SQL optimizer
 The SQL optimizer adds additional optimizations and delegates operations to the best database execution
operator, e.g. delegate star join-nodes to the OLAP processing engine where possible

Additional SQL Optimization  Since SAP HANA Rev 62 the SQL optimization
SQL Optimization can explicitly be determined setting
Calculation Engine Optimization
includes the “Execute In:” property to “SQL Engine”
• Stacked Views /
Calculation Views SQL unfolding  Since SAP HANA SPS9 the optimized execution
• Cost-based behavior implicitly evaluates to leverage
Optimization additional SQL optimization
• Delegate
processing to  SAP HANA SPS10 optimization enhancements
best operator include implicit optimized Star Join processing

* Implicit SQL optimization details are documented in SAP Note 2223597.

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 23


SAP HANA View Modeling – Best Practices
Performance Analysis & Query Insight Tools
Timeline – root cause analysis
Visualize Plan

Operator list

Calculation View
Debugger

Explain Plan

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 24


SAP HANA View Modeling – Best Practices
Essential Tips and Tricks - Filter & Aggregation Push Down
• Ensure that filters are pushed down
• Aggregate and ensure Group By are
pushed down (i.e. SDA remote DB)
union constant
database

select
division, sum(prevamount), sum(currentamount)
from CvOrdersQuery calculated column
('placeholder' = ('$$year$$', '2013')) quarter
where
country in ('USA', 'GERMANY') and database = 'IQ'
group by division input parameter
year

constraint
category
analytical privilege
unit
group by
where clause
division, quarter
country

group by division, quarter where


country in ('USA','GERMANY') and year = '2013' and quarter = '4' and category= '100' and unit = 'XYZ'

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 25


SAP HANA View Modeling – Best Practices
Essential Tips and Tricks - Value Help Lookup Models
Out-source Value Help Information to dedicated views
The processing of the value help is
• Benefit from faster value help dialogs directed to an external model instead
• Provide consistent LOVs across consuming views of querying the central model

• Dependencies between value help views


• Support Analytical Privileges

select
teamname, playername, rank,
sum(playergoals), sum(teamgoals) select teamid, teamname
from from CvTeamLookup
CvSoccerPlayers(
'placeholder'=('$$top_n_players$$','2'),
'placeholder'=('$$ip_team$$','paderbom')
) Select playerid, playername from
group by teamname, playername, rank CvTeamLookup where teamname = ?
order by teamname

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 26


SAP HANA View Modeling – Best Practices
Essential Tips and Tricks - Input Source Pruning

Explicit pruning Implicit pruning

select select
country, sum(prevous), sum(current) country, sum(prevous), sum(current)
from CvSalesQuery from CvSalesQuery (
where year = 2015 and 'placeholder' = ('$$ip_year$$', '2015')
country in ('usa', 'germany') and )
SOURCE = 'Hot' where country in ('usa', 'germany')
group by country order by country group by country order by country

Query execution direction relies on Query execution direction relies on


the Union Constant filter the Date Input parameter

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 27


SAP HANA View Modeling – Best Practices
Essential Tips and Tricks – Keep Flag
Show Mouse sales in February! Regular SQL

Sales
$160

Solution!
Generally the requested columns mandates the level of aggregation. Within Calculation Model Set
Under certain circumstances this level of aggregation is to course and Keep Flag = True on Order ID
instead requires a finer level of aggregation.
• Setting the Keep flag will force additional columns into context
altering the level of granularity.

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 28


SAP HANA View Modeling – Best Practices
Essential Tips and Tricks – Transparent Filter
Count the amount of stores that sold a Mouse to Johan and Susan!
select product, sum(quantity), sum(storecount) from model Stacked Calculation Model
where Customer in (john, susan) and product = mouse group by product

Solution! Set the Transparency Filter


The Transparent Filter will omit columns from unnecessary being used part for the column Customer to true, on
all models and nodes that references
of Group By’s. This Flag is required when using … the Customer
• Stacked views where the lower views have count distinct measures
• Queries on the upper Calculation view contain filters on columns that
are not projected
© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 29
SAP HANA View Modeling – Best Practices
Essential Tips and Tricks – Dynamic Join
Show the Sales & Total Sales by Region & Product! Join on Country and
Region

Dynamic Join

Only the Join columns requested in the query will be brought


into context and play a part in the Join execution
Regular Join

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 30


SAP HANA View Modeling – Best Practices
Essential Tips and Tricks – Optimize Join Columns

Generally tables are pruned if no columns are


requested and Join types such as Left-Outer or
Referential are involved; under certain
circumstances the Joined columns could be
brought into context altering the level of
aggregation.

This setting will ensure that the joined columns


are omitted and will lead to smaller intermediate
result sets which can improve performance
significantly depending on the type of query.

*Note: This feature generally applies to earlier revisions

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 31


SAP HANA View Modeling – Best Practices
Designing larger Virtual Data Models using HANA Views
Architecting complex SAP HANA View-based data models

Identify
reproducible
pattern

Split big
models into
smaller parts

Do not build
monolithic
views

• Learn from SAP HANA Live! Layering approach.

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 32


SAP TechEd Online
Continue your SAP TechEd education after the event!

 Access replays of keynotes, Demo Jam, SAP TechEd live interviews, select lecture sessions, and more!
 Hands-on replays

http://sapteched.com/online

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 33


Further Information

Related SAP TechEd sessions:


DMM360 – Advanced Data Modeling in SAP HANA, Hands-On Workshop
DMM163 – Introduction to Data Modeling in SAP HANA, Hands-On Workshop
SAP Public Web
scn.sap.com http://scn.sap.com/community/developer-center/hana http://scn.sap.com/community/hana-in-memory
www.sap.com www.saphana.com
What’s new in SAP HANA (incl. SAP HANA View Modeling
https://blogs.saphana.com/2014/10/21/what-is-new-in-sap-hana-sps-09/ https://blogs.saphana.com/2015/06/16/new-sap-hana-sps10/
SAP Education and Certification Opportunities
www.sap.com/education
https://www.youtube.com/user/saphanaacademy https://open.sap.com/courses
Watch SAP TechEd Online
www.sapteched.com/online

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 34


Feedback
Please complete your session evaluation for
DMM208

©©2015
2015
SAP
SAP
SESE
oror
anan
SAP
SAP
affiliate
affiliate
company.
company.
AllAll
rights
rights
reserved.
reserved. Public 3535
Thank you!

Contact information:
Christoph Morgen
SAP HANA Product Management Werner Steyn
SAP SE | Dietmar-Hopp-Allee 16 | 69190 Walldorf | Germany SAP HANA Competence Center, SAP SE
christoph.morgen@sap.com | www.sap.com werner.steyn@sap.com | www.sap.com

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 36


© 2015 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.

National product specifications may vary.

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.

© 2015 SAP SE or an SAP affiliate company. All rights reserved. Public 37

You might also like