CD161 Presentation

download CD161 Presentation

of 37

Transcript of CD161 Presentation

  • 8/12/2019 CD161 Presentation

    1/37

    Rich Heilman, SAP HANA Product Management

    October, 2013

    CD161

    Introduction to SQL Script Basics and Deb

  • 8/12/2019 CD161 Presentation

    2/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    Disclaimer

    This presentation outlines our general product direction and should not be relied on

    purchase decision. This presentation is not subject to your license agreement or anywith SAP. SAP has no obligation to pursue any course of business outlined in this pr

    develop or release any functionality mentioned in this presentation. This presentatio

    strategy and possible future developments are subject to change and may be chang

    time for any reason without notice. This document is provided without a warranty of a

    express or implied, including but not limited to, the implied warranties of merchantab

    particular purpose, or non-infringement. SAP assumes no responsibility for errors or

    document, except if such damages were caused by SAP intentionally or grossly neg

  • 8/12/2019 CD161 Presentation

    3/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    Agenda

    SQLScript Basics

    R Integration

    Application Function Library

    User Defined Functions

    Triggers

  • 8/12/2019 CD161 Presentation

    4/37

    SQLScript Basics

  • 8/12/2019 CD161 Presentation

    5/37 2013 SAP AG or an SAP affiliate company. All rights reserved.

    SQLScriptWhat?

    SQL Script is an interface for applications to access SAP HANA

    Extension of ANSI Standard SQL

    Language for creating stored procedures in HANA:

    Declarative Logic including SELECT queries, Built-In Calculation Engine functions

    Orchestration Logic including Data Definition Language(DDL), Data Manipulation Language

    imperative logic

  • 8/12/2019 CD161 Presentation

    6/37 2013 SAP AG or an SAP affiliate company. All rights reserved.

    SQLScriptWhy?

    The main goal of SQLScript is to allow the execution of data intensive calculations in

    There are two reasons why this is required to achieve the best performance:

    Eliminates the need to transfer large amounts of data from the database to the application

    Calculations need to be executed in the database layer to get the maximum benefit from SA

    such as fast column operations, query optimization and parallel execution. If applications fet

    rows for processing on application level they will not benefit from these features

  • 8/12/2019 CD161 Presentation

    7/37 2013 SAP AG or an SAP affiliate company. All rights reserved.

    SQLScriptAdvantages

    Compared to plain SQL queries, SQL Script has the following advantages:

    Functions can return multiple results, while a SQL query returns only one result set Complex functions can be broken down into smaller functions. Enables modular programmi

    better understandability by functional abstraction. For structuring complex queries, standard

    definition of SQL views. However, SQL views have no parameters

    SQLScript supports local variables for intermediate results with implicitly defined types. With

    would be required to define globally visible views even for intermediate steps

    SQL Script has control logic such as if/else that is not available in SQL

  • 8/12/2019 CD161 Presentation

    8/37 2013 SAP AG or an SAP affiliate company. All rights reserved.

    Presentati

    Control flo

    Calculatio

    Data

    HANA

    SQLSc

    SQLScriptPerformance gains

  • 8/12/2019 CD161 Presentation

    9/37 2013 SAP AG or an SAP affiliate company. All rights reserved.

    DB Layer

    Code

    Traditional: Data to Code New Model: Co

    Massive datacopies creates

    bottleneck

    TransferMinimum

    Result Set

    SQLScriptTraditional model vs. new model

    Application Application Layer

    DB Layer

  • 8/12/2019 CD161 Presentation

    10/37 2013 SAP AG or an SAP affiliate company. All rights reserved.

    SQLScriptCode example

    BEGIN

    ...

    -- Query 1product_ids = select "ProductId", "Category", "DescId"

    from "SAP_HANA_EPM_DEMO"."sap.hana.democontent.epm.data::products"

    where "Category" = 'Notebooks'or "Category" = 'PC';

    -- Query 2

    product_texts = select "ProductId", "Category", "DescId", "Text"

    from :product_ids as prod_idsinner join "SAP_HANA_EPM_DEMO"."sap.hana.democontent.epm.data::texts"

    as texts on prod_ids."DescId" = texts."TextId";

    -- Query 3out_notebook_count = select count(*) as cnt from

    :product_textswhere "Category" = 'Notebooks';

    -- Query 4

    out_pc_count = select count(*) as cnt from:product_textswhere "Category" = 'PC';

    ...

    END;

    Notebooks

    Produ

    Q3

    Q2

    Q1

  • 8/12/2019 CD161 Presentation

    11/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    SQLScriptParallel processing

    SELECT statements are executed in parallel unless:

    Any local scalar parameters and variables are used in the procedure Read/Write procedures or DML/DDL operations are executed

    Imperative logic is used within the procedure

    Any SQL statements are used that are not assigned to a variable

  • 8/12/2019 CD161 Presentation

    12/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    SQLScriptCE(Calculation Engine) Built in functions

    SQL CE-Built In FunctionSELECT on column table out = SELECT A, B, C from "COLUMN_TABLE" out = CE_COLUMN_TABLE("COLUMN_TABLE",

    SELECT on attribute view out = SELECT A, B, C from "ATTRIBUTE_VIEW" out = CE_JOIN_VIEW("ATTRIBUTE_VIEW",

    SELECT on olap view out = SELECT A, B, C, SUM(D) from"ANALYTIC_VIEW" GROUP BY A, B, C

    out = CE_OLAP_VIEW("ANALYTIC_VIEW", [A

    WHERE HAVING out = SELECT A, B, C, SUM(D) from"ANALYTIC_VIEW" WHERE B = 'value' AND C =

    'value'

    col_tab= CE_COLUMN_TABLE("COLUMN_TABLE

    CE_PROJECTION(col_tab, [A, B, C], ' "B

    ''value'' ');

    GROUP BY out = SELECT A, B, C, SUM(D) FROM"COLUMN_TABLE"GROUP BY A, B, C

    col_tab= CE_COLUMN_TABLE("COLUMN_TABLE

    CE_AGGREGATION( (col_tab, SUM(D), [A,

    INNER JOIN out = SELECT A, B, Y, SUM(D) from "COLTAB1"INNER JOIN "COLTAB2" WHERE "COLTAB1"."KEY1" =

    "COLTAB2"."KEY1" AND "COLTAB1"."KEY2" =

    "COLTAB2"."KEY2"

    out = CE_JOIN("COLTAB1","COLTAB2", [KE

    LEFT OUTER JOIN out = SELECT A, B, Y, SUM(D) from "COLTAB1"LEFT OUTER JOIN "COLTAB2" WHERE

    "COLTAB1"."KEY1" = "COLTAB2"."KEY1" AND

    "COLTAB1"."KEY2" = "COLTAB2"."KEY2"

    out = CE_LEFT_OUTER_JOIN("COLTAB1","CO

    [A, B, Y, D])

    SQL Expressions out = SELECT A, B, C, SUBSTRING(D,2,5) FROM"COLUMN_TABLE"

    proj_tab = CE_COLUMN_TABLE("COLUMN_TAB

    CE_PROJECTION( :proj_tab, ["A", "B",

    CE_CALC('midstr("D",2,5)', string) ])

    UNION ALL col_tab1 = SELECT A, B, C, D FROM"COLUMN_TABLE1"; col_tab2 = SELECT A, B, C, D

    FROM "COLUMN_TABLE2"; out = SELECT * FROM

    :col_tab1 UNION ALL SELECT * FROM :col_tab2;

    col_tab1 = CE_COLUMN_TABLE("COLUMN_TA

    col_tab2 = CE_COLUMN_TABLE("COLUMN_TAB

    CE_UNION_ALL(:col_tab1,:col_tab2);

  • 8/12/2019 CD161 Presentation

    13/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    SQLScriptBuilt in function code example

    Built in functions should be used exclusively where possible

    Calculation Engine functions should not be mixed with standard SQL statements

    Queries can be well optimized and parallelized by the engine

    bp_addresses =

    select a."PartnerId", a."PartnerRole", a."EmailAddress", a."CompanyName",

    a."AddressId", b."City", b."PostalCode", b."Street"

    from "SAP_HANA_EPM_DEMO"."sap.hana.democontent.epm.data::businessPartner" as a

    inner join "SAP_HANA_EPM_DEMO"."sap.hana.democontent.epm.data::addresses" as b

    on a."AddressId" = b."AddressId" where a."PartnerRole" = :partnerrole;

    lt_bp = CE_COLUMN_TABLE("SAP_HANA_EPM_DEMO"."sap.hana.democontent.epm.data::businessPartner",["PartnerId", "PartnerRole", "EmailAddress", "CompanyName", "AddressId" ]);

    lt_bp_proj = CE_PROJECTION(:lt_bp, ["PartnerId", "PartnerRole", "EmailAddress" , "CompanyName",

    "AddressId" ], '"PartnerRole" = :partnerrole' );

    lt_address = CE_COLUMN_TABLE("SAP_HANA_EPM_DEMO"."sap.hana.democontent.epm.data::addresses",

    ["AddressId", "City", "PostalCode", "Street"]);

    bp_addresses = CE_JOIN(:lt_bp_proj, :lt_address, ["AddressId"],

    ["PartnerId", "PartnerRole", "EmailAddress", "CompanyName",

    "AddressId", "City", "PostalCode", "Street"]);

  • 8/12/2019 CD161 Presentation

    14/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    SQLScriptEditor Integration with SAP HANA Development Perspective

    Client side syntax checking

    Code hints

    Syntax highlighting

    Local table types

  • 8/12/2019 CD161 Presentation

    15/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    SQLScriptDebug Perspective

    Set Breakpoints

  • 8/12/2019 CD161 Presentation

    16/37

    R Language Integration

  • 8/12/2019 CD161 Presentation

    17/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    An open source software language and environment for

    statistical computing and graphics with over 3000 add-on

    packages. http://www.r-project.org/

    The packages cover wide range topics - Cluster Analysis & Finite Mixture Models

    Probability Distributions

    Computational Econometrics

    Empirical Finance

    Statistical Genetics

    Graphic Displays, Dynamic Graphics, Graphic Devices

    & Visualisation

    Machine Learning & Statistical Learning

    Medical Image Analysis

    Multivariate Statistics

    Natural Language Processing

    Statistics for the Social Sciences

    Time Series Analysis

    R LanguageWhat is open source R

    http://www.r-project.org/http://www.r-project.org/http://www.r-project.org/http://www.r-project.org/
  • 8/12/2019 CD161 Presentation

    18/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    R LanguageWhat R supports

    Data handling and storage: numeric and textual

    Matrix algebra Hash tables and regular expressions

    High-level data analytic and statistical functions

    graphics

    Programming language: loops,

    Branching, subroutines, OO

  • 8/12/2019 CD161 Presentation

    19/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    R LanguageCode examples

  • 8/12/2019 CD161 Presentation

    20/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    JoinOP

    ROP

    OLAPOP

    Calc. Engine

    R External

    Packages(Forecasting,Parallelism,

    statistics, etc.)

    RClient

    SAP RHANAPackage

    Send data

    and R script

    NewDB Space OpenSource R Space

    1

    3

    NewDB R Integration Open Source R

    2 Run the R scripts

    Get back the

    result from R toSAP HANA

    Sample Codes in SAP HANA SQLScript

    R LanguageIntegration with HANA database

  • 8/12/2019 CD161 Presentation

    21/37

    Application Function Libra

  • 8/12/2019 CD161 Presentation

    22/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    Application Function Library(AFL)

    Application Function Library (AFL)what is it?

    Pre-delivered commonly utilized business, predictive and other types of algorithms for solutions that run on SAP HANA. The technology framework enabling the use of

    is called theApplication Function Library .

    AFL functions run in the core of SAP HANA in-memory DB.

    What are its benefits?

    These algorithms can be leveraged directly in development projects, speeding up p

    avoiding writing custom complex algorithms from scratch. AFL operations also offer

    performance, as AFL functions run in the core of SAP HANA in-memory DB, where

    specifically optimized for performance.

  • 8/12/2019 CD161 Presentation

    23/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    Application Function Library(AFL)

    The Business Function Library (BFL) is a set of functions in the AFL. It contains pre-b

    driven, commonly used algorithms primarily related to finance.

    The Predictive Analysis Library (PAL) is a set of functions in the AFL. It contains pre-b

    driven, commonly used algorithms primarily related to predictive analysis and data mi

    Predictive Analysis Library Business Function Library

    Application Functions (C++)

  • 8/12/2019 CD161 Presentation

    24/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    Application Function Library(AFL)

    Application Functions (C++)

    SQLScript

    HANA Clients (App Server, Analytics Tech

    SAP HANA

    Business FuLibrary

    Predictive AnalysisLibrary

    AFL Framework

    AFL Technology includes

    Application Functions

    Written in C++ and delivered as AFL content by SAP Predictive Analysis- and Business Function Library have been

    released in SPS05 as AFL content,

    new in SPS06 the Data Quality Functions Library

    AFL Framework

    On demand library loading framework for registered and

    supported libraries

    AFL are consumed for use from SQLScript via

    so-called wrapper-procedures. Consumption can be controlledvia permissions.

    Beyond the initial script-based approach, the Application

    Function Modeler is released with SPS06 as a graphical editor

    to facilitate the design-time process of creating the

    wrapper-procedures and

    can easily be re-used as

    part of development

    workflow.

    Parameter Table

  • 8/12/2019 CD161 Presentation

    25/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    Business Function Library(BFL)

    Compiled analytic function library for business functionality

    Support various pre-built, parameter-driven algorithms Embedded into calculation engine

    Compute Quickly

    Reuse common business functionalities without developing

    Perform functions in real-time with high-performance comp

    memory

    Help Customers To

    Bring decision support capabilities to the business users thr

    simplified experience and pre-built scenariosEmpower the business

    Built applications Quickly

    *no

  • 8/12/2019 CD161 Presentation

    26/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    Predictive Analysis Library(PAL)

    Compiled analytic function library for predictive analysis

    Support multiple algorithms: K-Means, Association Analysis, C4.5 Decision Tree, Regression, Exponential Smoothing

    Know Your Business

    Decide with Confidence

    Compute Quickly

    Uncover deep insights & patterns about the business: associatio

    customer clustering, or sales prediction

    Drive more advanced analyses. Decision is made with support f

    numbers

    Query and analyze data in real-time with high-performance com

    memory

    Help Customers To

    Bring decision support capabilities to the business users through

    experience and pre-built scenariosEmpower the business

  • 8/12/2019 CD161 Presentation

    27/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    Application Function Modeler(AFM)

    A graphical editor to facilitate a faster and easier design-time process of creating the wrapper-procedur

    AFL Models are stored as repository objects and can easily be re-used as part of development workflow

    Model Editor

    Dragndrop of functions

    Template for table types

    Data source selection and

    automatic mappings to table

    types

    Sample SQL for

    procedure

    consumption

  • 8/12/2019 CD161 Presentation

    28/37

    User Defined Functions

  • 8/12/2019 CD161 Presentation

    29/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    User Defined FunctionsOverview

    Management of objects can only be done via SQL Console. Support for storing the

    repository is coming in a future support packageLanguage used within the body is SQLScript, no other languages are supported

    Functions are read-only, side effect free

    Two types:

    Table User Defined Function

    Scalar User Defined Function

    User Defined Functions

  • 8/12/2019 CD161 Presentation

    30/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    User Defined FunctionsTable UDF

    Can have any number of input parameters

    Returns exactly one table Table operations are allowed within the body

    User Defined Functions

  • 8/12/2019 CD161 Presentation

    31/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    User Defined FunctionsScalar UDF

    Can have any number of input parameters

    Returns exactly one value Expressions are allowed within the body

    No table operations such as CURSOR, CE

    functions or Array operations

    Input parameters can not be table type

  • 8/12/2019 CD161 Presentation

    32/37

    Triggers

  • 8/12/2019 CD161 Presentation

    33/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    TriggersOverview

    Special type of stored procedure that

    automatically executes when an event occurs in

    the database server, for example upon INSERT

    of a table

    Management of objects can only be done via

    SQL Console. Support for storing the artifacts

    in the repository is coming in a future support

    package

  • 8/12/2019 CD161 Presentation

    34/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    Further Information

    SAP Education and Certification Opportunities

    www.sap.com/education

    Watch SAP TechEd Online

    www.sapteched.com/online

    SAP Public Web

    scn.sap.comwww.sap.com

    SAP TechEd Virtual Hands-on Workshops and SAP Tech

    http://www.sap.com/educationhttp://www.sapteched.com/onlinehttp://scn.sap.com/welcomehttp://www.sap.com/http://www.sap.com/http://scn.sap.com/welcomehttp://www.sapteched.com/onlinehttp://www.sap.com/education
  • 8/12/2019 CD161 Presentation

    35/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    SAP TechEd Virtual Hands-on Workshops and SAP TechContinue your SAP TechEd education after the event!

    SAP TechEd Virtual Hands-on Workshops

    Access hands-on workshops post-event

    Available JanuaryMarch 2014

    Complementary with your SAP TechEd registration

    SAP TechEd Online

    Access replays of keynotes, Demo

    LIVE interviews, select lecture ses

    View content only available online

    http://saptechedhandson.sap.com/ http://sapteched.com/o

    http://saptechedhandson.sap.com/http://sapteched.com/onlinehttp://sapteched.com/onlinehttp://saptechedhandson.sap.com/
  • 8/12/2019 CD161 Presentation

    36/37

    FeedbackPlease complete your session evaluation for CD161.

    Thanks for attending this SAP TechEd s

    2013 SAP AG SAP ffili t All i ht

  • 8/12/2019 CD161 Presentation

    37/37

    2013 SAP AG or an SAP affiliate company. All rights reserved.

    2013 SAP AG or an SAP affiliate company. All rights

    No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG.

    The information contained herein may be changed without prior notice.

    Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

    National product specifications may vary.

    These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation

    SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services

    in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an

    SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SA

    other countries.

    Please see http://www.sap.com/corporate-en/legal/copyright/index.epx#trademarkfor additional trademark information and notices.

    http://www.sap.com/corporate-en/legal/copyright/index.epxhttp://www.sap.com/corporate-en/legal/copyright/index.epxhttp://www.sap.com/corporate-en/legal/copyright/index.epxhttp://www.sap.com/corporate-en/legal/copyright/index.epx