week 1: database development unit 1: introduction and review
TRANSCRIPT
2PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Business Needs Key Capabilities Business Benefit
Create custom
applications
Database: SQL, SQLScript, CDS, HDI
Application server: XSA, JavaScript/Node.js, Java
Development Tools
• Build applications which reflect the unique business processes and key innovations of your business• Customize user interfaces to your business process and terminology, thereby increasing end-user efficiency• Gain competitive advantage by focusing applications on the key value providers of your business• Fill gaps in standard applications that are specific to your business• Build custom analytics which give specific insights into your business
Architecture
scalability and
security
Application server: XSA, JavaScript/Node.js, Java
• XSA offers the all-in-one-box application server and database server by default, thereby providing low cost of ownership and an easy start to using it
• XSA scales independent of the SAP HANA database. It can run on lower-cost hardware and can scale to Internet scale loads without directly increasing the cost of your SAP HANA-specific hardware
• XSA can be installed in a DMZ or with a firewall between it and SAP HANA, providing multiple security options
Developer
productivity
Database: SQL, SQLScript, CDS, HDI
Application server: XSA, JavaScript/Node.js, Java
Development Tools
• Support development tools and debugging that work with the developer to reduce the time to deliver custom development
• Tools which support continuous integration and agile development reduce defects and increase the time to delivery• Code scanners and automated unit testing reduce the number of development bugs which reach production systems• Developer tool optimization reduces the cost of development
Introduction and ReviewA comprehensive portfolio for the developer persona
Manage the lifecycle
of SAP and custom
applications
Application lifecycle management
• Ease the adoption of new releases and product upgrades• Deliver application fixes and new functionality to your business with less downtime and disruption• Manage your design-time assets more efficiently, reducing the cost of ownership for your SAP HANA-based
applications• Integrate SAP HANA application lifecycle management with other SAP solution lifecycles for better overall visibility
and lower complexity
Extend SAP
applications
Database: SQL, SQLScript, CDS, HDI
Application server: XSA, JavaScript/Node.js, Java
Development Tools
• Customize user interfaces to your business process and terminology, thereby increasing end-user efficiency• Gain competitive advantage by focusing applications on the key value providers of your business• Fill gaps in standard applications that are specific to your business• Add customer-specific fields to database, services, and user interfaces extended to your key business needs• Reduce training and cost of ownership by adjusting applications to reflect your industry or business-specific
terminology and processes
3PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Introduction and ReviewSAP HANA development platform
What: Combine powerful SAP HANA in-memory processing with a
microservice application server / web server / basis for an
application development platform inside SAP HANA
Rationale: Enable application development and deployment while
minimizing architectural “layers”
Create apps that have an http-based UI (browser, mobile apps)
Apps run on SAP HANA w/o additional external servers or components, but
with the option to scale the application layer independent of SAP HANA
→ simplified system architecture = low TCO
Best possible usage of SAP HANA resources by pushing as much logic
execution as possible into the database
Scope: Wide range of apps
Lightweight small web-based applications
Enterprise business applications
4PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
What: XS in SPS 11 represents an evolution of the application server
architecture within SAP HANA, building upon the previous strengths while
expanding the scope
Rationale: Enable additional deployment models and development languages
With SPS 11, XS will provide additional runtimes based upon open architecture
for JavaScript on Node.js, Java on TomEE and Bring Your Own Language
The existing runtime remains for full backwards-compatible support
The XS application router embraces microservices architectures, where
applications are implemented on multiple – possibly different – runtimes
In cloud deployments, XS applications run on SAP Cloud Platform PaaS
In on-premise deployments, XS applications can still run/manage “in-a-box” but
also scale out to lower-cost hardware
Applications are written once, and can then be deployed to either cloud or on-
premise without coding changes
Source code repository based upon on Git/GitHub with support for
Merge/Branch/Containers
Introduction and ReviewSAP HANA extended application services (XS) evolution
5PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Introduction and ReviewSAP HANA XS, advanced model positioning – The freedom of choice
SAP HANA XS, advanced model offers customers the freedom of choice
of technologies, tools, and deployment options for high-scale
development and operation of native SAP HANA applications.
6PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Introduction and ReviewXS architecture
HANA Database
SAP HANA XS Adv. (New in SAP HANA SPS 11)
SAP HANA Database
Tomcat / TomEE
OData (Java)
Other
Containers
Node.jsXSJS Compt.
R R R
R
XSJS App
User Account
and
Authentication
Java AppCentral
Security
Service
Node App
OData (JavaScript)
SAP HANA
DI
RR R R R R
SAP HANA XS Adv. Runtime Platform / SAP Cloud Platform
HTML5
App
Application Router
SAP HANA
XS Classic
(existing
runtime
still for
several
SPS
levels)
R
R
R
SAP Web
Dispatcher
R
Browser
BOYL/R
7PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
SAP HANA DI is a service layer of the SAP HANA database that simplifies the deployment of SAP HANA
database artifacts by providing a declarative approach for defining database objects and ensuring a
consistent deployment into the database, based on a transactional all-or-nothing deployment model
and implicit dependency management.
Containers; SAP HANA DI containers allow multiple deployments, sandboxing, etc.
Focus on deployment; no version control aspects, no lifecycle management aspects
Database objects only; no JavaScript programs, no OData, no application-layer artifacts
Introduction and ReviewSAP HANA Deployment Infrastructure (DI)
8PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Version control will be done in an external
version control system (e.g. Git/GitHub
repository)
The SAP HANA Deployment Infrastructure only deploys
design-time artifacts but does not manage their lifecycle
Pre SPS 11 repository will remain part of the
shipment for some SPSs
Enables custom XS applications to adopt new runtime at
own pace
Introduction and ReviewChanges to the SAP HANA repository
9PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Streamlined version of SAP HANA; footprint
optimized to improve access to technology
Available for download on a laptop, personal
computer, server, or available in the cloud
for flexible development and deployment options
Build apps/data stores up to 32 GB of memory use
for free (production and non-production)
Introduction and ReviewSAP HANA, express edition 2.0 – Build apps from anywhere
10PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
SAP Web IDE for SAP HANA provides a
comprehensive, web-based, end-to-end development
experience for creating SAP HANA native applications:
Development of SAP HANA content and models
UI development with SAPUI5
Node.js or XSJS business code
Git integration
SAP Web IDE for SAP HANA comprises capabilities of
SAP HANA studio and SAP HANA Web-based
Development Workbench
It consolidates technologies, follows industry trends, and
leverages industry standards where possible, while
retaining a competitive innovation focus of SAP’s current
offering
Introduction and Review Development tools on SAP HANA – Vision
This is the current state of planning and may be changed by SAP at any time.
SAP Web IDE for SAP HANA
SAP HANA Dev &
Modeling Tools
SAPUI5 &
Node.JS Dev
Tools
11PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Introduction and ReviewSAP Web IDE for SAP HANA
Project wizard Module
(DB, JS, UI) wizardsModeler
Run
configurations
Debugger
Text editor
Version
control
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.
The information contained herein may be changed without prior notice. 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 or its affiliated
companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP 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,
and they should not be relied upon in making purchasing decisions.
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. All other product and service names mentioned are the trademarks of their respective companies.
See http://global.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
© 2017 SAP SE or an SAP affiliate company. All rights reserved.
2PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
New development artifact extension in
SAP HANA SPS 06 – hdbdd (data dictionary)
– changed to hdbcds in HDI with SPS 11
Defines reusable types, multiple entities
(tables), and views all within one source file
Multiple catalog objects are generated upon
activation
Core Data ServicesDevelopment artifact
3PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Individual types as well as structured types
A structured type is a data type comprising
a list of attributes, each of which has its
own data type
The attributes of the structured type can be
defined manually in the structured type
itself, and reused either by another
structured type or an entity
Core Data ServicesUser-defined types
4PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
An entity is the core artifact for persistence-
model definition using the CDS syntax
A CDS entity is a table with a set of data
elements that are organized using columns
and rows
Associations define relationships between
entities (tables)
Associations are specified by adding an
element to a source entity with an association
type that points to a target entity,
complemented by optional information
defining cardinality and which keys to use
Core Data ServicesEntities and associations
5PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
CDS syntax expands to include the definition
of views
A view is a virtual table, not persisted, based
on the dynamic results returned in response
to a SQL statement
Views can utilize the defined associations
between entities
Supports the use of functions and
expressions as well as aggregation and
filtering
Core Data ServicesViews
6PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Core Data Services HDI-incompatible changes
7PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
In general, CDS works in HDI like it does in the SAP HANA repository. There are some incompatible
changes, however.
The following annotations are not supported in HDI:
@Schema
@Catalog (index and tableType)
@SearchIndex
@SearchIndexes
@nokey
@GenerateTableType
@WithStructuredPrivilegeCheck
For all annotations that have been replaced by regular syntax in HDI, the syntax variant is also available and
recommended in the repository
Core Data ServicesIncompatible changes
8PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The annotation "Schema" is not supported in HDI
Schema is handled automatically via the HDI
container
Core Data ServicesSchema handling
9PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The "Catalog" annotation is not supported in HDI
In order to specify indexes, use the corresponding
syntax in the technical configuration (see Index)
The specification of tableType is split: the storage
type (row/column) is specified in the technical
configuration section (see Row/Column); in order to
get a temporary table, use the keyword "temporary
entity"
Core Data ServicesIndex, tableType, and @Catalog
10PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The annotations "SearchIndex" and "SearchIndexes"
are not supported in HDI
In order to define full-text indexes, use the
corresponding syntax in the technical configuration
(see Full-text index)
Core Data ServicesFulltext index, @SearchIndex and @SearchIndexes
11PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
In order to define an entity without key elements, in
the repository the annotation "nokey" had to be used
In HDI, it is possible to define an entity without key
elements without using an annotation
The annotation "nokey" is not supported in HDI
Core Data ServicesKeyless entities
12PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
In the repository, for each structured CDS type, an SAP HANA table type was generated by default. The
generation of table types could be controlled explicitly via the "GenerateTableType" annotation.
In HDI, no SAP HANA table type is generated for a structured type by default. To enforce generation of an
SAP HANA table type, use the keyword "table type" instead of "type":
type Struc1 { ... }; // no HANA table type is generated
table type Struc2 { ... }; // a corresponding HANA table type is created
Core Data Services@GenerateTableType
13PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The annotation
"WithStructuredPrivilegeCheck" is not
supported in HDI. Use the syntax variant
instead
view MyView as select from Foo {
<select_list>
} <where_groupBy_Having_OrderBy> with
structured privilege check;
Core Data ServicesAccess control via DCL
14PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Core Data Services New features
15PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The definition of an entity can contain a section
called "technical configuration"
In this section, you can specify
– storage type (row/column)
– indexes
– full-text indexes
– partitioning (HDI only)
– grouping (HDI only)
– unload priority (HDI only)
The syntax in the technical configuration section
is as close as possible to the corresponding
clauses in the HANA SQL Create Table statement
Each clause in the technical configuration must
end with a semicolon
Core Data ServicesTechnical configuration
entity MyEntity {
<element_definitions>
} technical configuration {
<technical_configurations>
};
16PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
In the technical configuration for an entity, the
storage type (row or column) for the generated
table can be specified
Default: if no storage type is specified, a column
store table is generated
In repo, this is an alternative way to specifying
the storage type via the annotation
Catalog.tableType. It is not possible to use both
the annotation and the technical configuration at
the same time to define the storage type for an
entity
In HDI, the storage type can only be specified
via the technical configuration. The respective
annotation is not supported
entity MyEntity {
key id : Integer;
a : Integer;
} technical configuration {
row store;
};
Core Data ServicesStorage type
17PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
In repo, this is an alternative way to
specifying the index via the index annotation.
It is not possible to use both the index
annotation and the technical configuration at
the same time to define indexes for an entity
In HDI, indexes can only be specified via the
technical configuration. The index annotation
is not supported
entity MyEntity {
key id : Integer;
a : Integer;
b : Integer;
c : Integer;
s {
m : Integer;
n : Integer;
};
} technical configuration {
index MyIndex1 on (a, b) asc;
unique index MyIndex2 on (c, s) desc;
};
Core Data ServicesIndex
18PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The <fulltext_parameter_list> is basically identical to the
standard HANA SQL syntax for CREATE FULLTEXT
INDEX
A fuzzy search index corresponds to specifying "FUZZY
SEARCH INDEX ON" for a table column
It is not possible to specify both a full-text index and a
fuzzy search index for the same element
In repo, this is an alternative way to specifying full-text
indexes via the annotations SearchIndex and
SearchIndexes. It is not possible to use both the
annotations and the technical configuration at the same
time to define full-text indexes for an entity
In HDI, full-text indexes can only be specified via the
technical configuration. The respective annotations are not
supported. The full-text parameters CONFIGURATION
and TEXT MINING CONFIGURATION are not supported
Core Data ServicesFull-text index
entity MyEntity {
key id : Integer;
t : String(100);
s {
u : String(100);
};
} technical configuration {
fulltext index MyFTI1 on (t)
<fulltext_parameter_list>;
fuzzy search index on (s.u);
};
19PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
In the technical configuration for an entity, the
partitioning information for the generated table
can be specified
The <partition_clause> is identical to the
respective clause in the standard HANA SQL
CREATE TABLE statement
The partition clause is only supported in HDI
entity MyEntity {
key id : Integer;
a : Integer;
} technical configuration {
partition by hash (id) partitions 2,
range (a) (partition 1 <=
values < 10, partition values = 10,
partition others);
};
Core Data ServicesPartitioning
20PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
In the technical configuration for an entity, the
grouping information for the generated table can
be specified
The <group_option> is identical to the respective
clause in the standard HANA SQL CREATE
TABLE statement
The group option clause is only supported in HDI
entity MyEntity {
key id : Integer;
a : Integer;
} technical configuration {
group type Foo group subtype Bar
group name myGroup;
};
Core Data ServicesGrouping
21PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
In the technical configuration for an entity,
the unload priority for the generated table
can be specified
The unload priority clause is only supported
in HDI
Core Data ServicesUnload priority
entity MyEntity {
<element_list>
} technical configuration {
unload priority <integer_literal>;
};
22PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Constants could already be defined before SPS11,
but their usage was restricted to annotation
assignments and default values for entity elements
With SPS11, constants can also be used in views
and in the ON-condition of unmanaged associations
When constants are used in a view definition, their
name must be prefixed with the scope operator ":".
Usually, names that appear in a query are resolved
as alias or element names. The scope operator
makes the compiler resolve the name outside of the
query
Core Data ServicesUsing constants in queries and associations
23PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
When an infix filter effectively reduces the
cardinality of a to-N association to to-1, this can
be made explicit in the filter
This allows to use the association also in
the WHERE clause, where to-N associations
are not allowed
entity Person {
key id : Integer;
name : String(100);
address : Association[*] to Address on
address.personId = id;
};
entity Address {
key id : Integer;
personId : Integer;
type : String(20); // home, business,
vacation, ...
street : String(100);
city : String(100);
};
view V as select from Person {
name
} where address[1: type='home' ].city
= 'Hamburg';
Core Data ServicesCardinality in filters
24PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The definition of an entity can contain calculated fields
The values for calculated fields are not persisted in the database, but only computed on access, i.e.
when the element is selected. Basically, when the field is used in a select statement, it is replaced by
the expression
The calculation expression can contain arbitrary expressions and SQL functions
Note: in SAP HANA tables, you can define columns with the addition "GENERATED ALWAYS AS".
These columns are physically present in the table and all the values are actually stored. They behave
like ordinary columns, with the difference that their value is computed upon insertion rather than
specified in the INSERT statement. This is in contrast to calculated fields: For them, no values are
actually stored. The values are computed upon SELECT
Restrictions
– must not contain other calculated fields, associations, aggregations, or subqueries
– cannot be a key
– no index can be defined
– cannot be used as foreign key for a managed association
Core Data ServicesCalculated fields
25PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
CDS now supports the JOIN clause in
view definitions. The following JOIN
types are supported:
[ INNER ] JOIN
LEFT [ OUTER ] JOIN
RIGHT [ OUTER ] JOIN
FULL [ OUTER ] JOIN
CROSS JOIN
Core Data ServicesJOIN
entity E {
key id : Integer;
a : Integer;
};
entity F {
key id : Integer;
b : Integer;
};
entity G {
key id : Integer;
c : Integer;
};
view V_join as select from E join
(F as X full outer join G on X.id = G.id)
on E.id = c {
a, b, c
};
26PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
LIMIT & OFFSET is used to return a
subset of the selected rows
LIMIT value defines the number of rows
returned after OFFSET has been applied
OFFSET will skip the first n rows of the
selected dataset
Core Data ServicesLIMIT & OFFSET
27PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Support for the SQL clause TOP in
query of view definition
Limits result set to TOP n rows
Core Data ServicesTOP
28PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
CDS now supports SELECT DISTINCT
semantic. Note the position of the
DISTINCT keyword directly in front of
the curly brace
Core Data ServicesDISTINCT
view V_dist as
select from E distinct { a };
29PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
GENERATED {ALWAYS | BY DEFAULT }
AS IDENTITY is used to create identity
columns with auto-increment functionality
Creates a sequence automatically
If ALWAYS is specified, values are always
generated; if BY DEFAULT is specified, the
values are generated by default, but can be
overridden
Core Data ServicesGENERATED {ALWAYS | BY DEFAULT} AS IDENTITY
30PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
GENERATED ALWAYS AS <Expression> is
used to create calculated columns
An element which is defined corresponds to a
field in the database table that is present in the
persistence and has a value
Since the value is computed on INSERT, the
expression cannot contain non-deterministic
functions
Core Data ServicesGENERATED ALWAYS AS <Expression>
31PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Same subquery functionality provided by
SAP HANA core SQL brought to the CDS
layer
Core Data ServicesSubquery support
32PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
@Odata.publish allows the generation of
generic OData services
No need for separate xsodata file
Consumable via Java module
Consumable via JavaScript module in a future
support package
Core Data [email protected]
33PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Up to now, a CDS file could contain only a single
top-level artifact. As a consequence, in order
to define several artifacts in a single source file,
you had to use a context as top-level artifact and
put all other artifacts inside that context. Since
multiple top-level artifacts are now allowed, there
is no longer any requirement that the name of the
CDS source file must be the same as the name
of a top-level artifact. You can choose any name
for the CDS source file
Core Data ServicesMultiple top-level artifacts
34PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
CDS views can now have parameters
Must be defined in the view definition before the
query block
Parameters must be typed with built-in primitive,
user-defined scalar types, or use “Type of”
operator
Parameters can be used at any position in a
query where an expression is allowed. A
parameter is referred to inside a query by
prefixing the parameter name either with the scope operator ':' or "$parameters“
Runtime object is a table function
Core Data ServicesView with parameters
35PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The new view
SYS.CDS_ANNOTATION_ASSIGNMENTS
in the CDS catalog API returns annotation
values in a flat manner. This is in contrast to
the view CDS_ANNOTATION_VALUES,
where values of structured annotations are
returned in structured form as a JSON value
Core Data ServicesNew view – SYS.CDS_ANNOTATION_ASSIGNMENT
36PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Allows developer to insert comments into the source code of the CDS artifact via annotations.
Column-level comment is transferred to the runtime object in the catalog.
Core Data ServicesComments
37PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Developer can now define a CDS
view which selects from a native
table function which was defined
using .hdbfunction artifact
Core Data ServicesSelecting from table functions
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.
The information contained herein may be changed without prior notice. 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 or its affiliated
companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP 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,
and they should not be relied upon in making purchasing decisions.
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. All other product and service names mentioned are the trademarks of their respective companies.
See http://global.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
© 2017 SAP SE or an SAP affiliate company. All rights reserved.
2PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
– Tables
– Indexes
– Full-Text Indexes
– Constraints
– Triggers
– Procedures
– Functions
– SQL Views
– Table Types
Pure Database ConceptsDDL-based artifacts
– Sequences
– Statistics
– Structured Privilege
– Graph Workspace
– Collections
– Result Cache
Core Data Services is good for defining reusable types, multiple entities (tables), views, and relationships via
associations all within one source file.
But sometimes it is preferred to use DDL-based artifacts as DB developers have become quite comfortable
with DDL. Since SPS11, with HDI we also have the DDL-based artifacts
3PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The table plugin .hdbtable transforms a design-
time table resource into a table database object
Pure Database ConceptsTables
4PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The index plugin .hdbindex transforms a
design-time index resource into an index on
a database table
Pure Database ConceptsIndexes
5PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The full-text index plugin .hdbfulltextindex
transforms a design-time full-text index resource
into a full-text index on a database table
Pure Database ConceptsFull-text index
6PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The foreign-key constraint plugin .hdbconstraint
transforms a design-time constraint into a
constraint on database tables
Pure Database ConceptsConstraints
7PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The trigger plugin .hdbtrigger transforms a design-
time trigger resource into a trigger on a database
table
Pure Database ConceptsTrigger
8PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The procedure plugin .hdbprocedure transforms a
design-time procedure resource into a procedure
database object. Supported languages are:
SQLScript and R.
Pure Database ConceptsProcedure
9PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The function plugin .hdbfunction
transforms a design-time function
resource into a function database object.
The function plugin handles scalar and
table functions, too
Pure Database ConceptsFunction
10PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The view plugin .hdbview transforms a design-time
view resource into a SQL view database object
Pure Database ConceptsSQL views
11PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The table type plugin .hdbtabletype transforms a
design-time table type resource into a table type
database object, for example, for use by signatures
of SQL procedures
Pure Database ConceptsTable types
12PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The sequence plugin .hdbsequence transforms
a design-time sequence resource into a
sequence database object. If the sequence
definition contains a RESET BY query, then this
RESET BY query is executed during deployment
to set the sequence to its start value.
Sequences without a RESET BY query are also
supported
Pure Database ConceptsSequences
13PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The statistics plugin .hdbstatistics transforms a
design-time statistics resource into a statistics
object on a database table
Pure Database ConceptsStatistics
14PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The structured privilege plugin
.hdbstructuredprivilege transforms a design-time
DDL-based structured privilege resource into a
structured privilege object in the database. The
referenced views must be defined using the WITH
STRUCTURED PRIVILEGE CHECK clause
Pure Database ConceptsStructured privilege
15PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The graph workspace plugin .hdbgraphworkspace
transforms a design-time graph workspace
resource into a graph workspace object in the
database
Pure Database ConceptsGraph workspace
16PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The collection plug-in .hdbcollections transforms a
design-time, document-collection resource into a
collection database object, which is a data store with
the table_type “COLLECTION. The so-called
“collections” are used to store JSON documents in
the SAP HANA Document Store (DocStore)
Pure Database ConceptsCollections
17PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The result cache plugin .hdbresultcache transforms
a design-time DDL-based definition of a result
cache into a catalog-level result cache definition.
The file must use an artificial cache name which
uses the prefix _SYS_CACHE# followed by the
name of the referenced view or function
Pure Database ConceptsResult cache
18PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The public synonym plugin .hdbpublicsynonym
can be used to create public synonyms that refer
to database objects located in the target schema
of the current container
The _SYS_BIC synonym plugin
.hdbsysbicsynonym can be used to create
synonyms in the _SYS_BIC schema that refer to
database objects located in the target schema of
the current container
Pure Database ConceptsBreaking the container concept with synonyms
19PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
User provided service for authentication
with DB user
HDBEXT provides the SAP HANA DB API
and manages the connection pool
All of this allows you to violate the rules of
container-based development and access
all schemas
Useful for very dynamic query processing
or system/admin level tooling
Pure Database ConceptsBreaking the container concept from application logic
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.
The information contained herein may be changed without prior notice. 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 or its affiliated
companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP 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,
and they should not be relied upon in making purchasing decisions.
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. All other product and service names mentioned are the trademarks of their respective companies.
See http://global.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
© 2017 SAP SE or an SAP affiliate company. All rights reserved.
2PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
SQLScript is
Extension of ANSI standard SQL
Language for creating stored procedures and user-defined functions in SAP HANA
Set-based declarative SQL & imperative control flow constructs
Suitable for mass data processing and OLTP scenarios as well
Advantages compared to plain SQL:
Smaller, parameterized reusable chunks of code (procedures, functions)
Well-structured query logic (using table variables)
improves maintainability
gains performance by parallel execution
debuggable intermediate steps
Supports invoker security mode
SQLScriptOverview
3PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
If multiple statements do not dependent on each other they are candidates for parallelization
Not Supported:
DMLs
Read-write procedures
Implicit SELECT
– Use parallel execution blocks to parallelize these statements
BEGIN PARALLEL EXECUTION
<dml_stmt>
END;
Supported:
Table assignments
Read-only procedures
SELECT INTO
SQLScriptParallelization
4PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
BEGIN…product_ids = SELECT ProductId, Category, DescId
FROM PRODUCTSWHERE Category = 'Notebooks' or Category = 'PC';
product_texts = SELECT ProductId, Category, DescId, TextFROM :product_ids as prod_ids
INNER JOIN TEXTS AS texts ON prod_ids.DescId = texts.TextId;
SELECT COUNT(*) INTO out_notebook_countFROM :product_texts WHERE Category = 'Notebooks';
SELECT COUNT(*) INTO out_pc_countFROM :product_texts WHERE Category = 'PC';
SELECT COUNT(*) INTO out_total_countFROM products;…
END;
SQLScriptImplicit parallelization
5PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
CREATE PROCEDURE cproc3 ASBEGIN
INSERT INTO ctab3 values (2);END;
CREATE PROCEDURE cproc4 ASBEGININSERT INTO ctab4 values (3);END;
CREATE PROCEDURE parallel (…) ASBEGIN
...
UPDATE CTAB1 SET A = A + 1; UPDATE CTAB2 SET A = A + 1; CALL CPROC4();CALL CPROC3();
...
END;
SQLScriptExplicit parallelization
6PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
CREATE PROCEDURE cproc3 ASBEGIN
INSERT INTO ctab3 values (2);END;
CREATE PROCEDURE cproc4 ASBEGININSERT INTO ctab4 values (3);END;
CREATE PROCEDURE parallel (…) ASBEGIN
...BEGIN PARALLEL EXECUTION
UPDATE CTAB1 SET A = A + 1; UPDATE CTAB2 SET A = A + 1; CALL CPROC4();CALL CPROC3();
END;...
END;
Restrictions: Only column-store tables
Modification of tables with a foreign key or triggers are not allowed
Updating the same table in different statements is not allowed
Reading / writing the same table is not allowed
Calling procedures containing dynamic SQL (for example, EXEC, EXECUTE IMMEDIATE)
is not supported in parallel blocks
Mixing read-only procedure calls and read-write procedure calls in a parallel block is not
allowed
SQLScriptExplicit parallelization
7PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Allows to pass scalar parameters to the SQL
query as well as return scalar output values
Does not support table variables
Use ? or $1, $2, $3 to parameterize the query.
Can only use in SQL statements where query
parameters are supported
Query will fail if the result set does not have a
single row
SQLScriptDynamic SQL with in/out scalar variables
8PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Allows the developer to access any
cell (read/write) of an intermediate
table variable or table parameter
directly
– Access via
<table>.<column>[<index>] notation
Introduced in SAP HANA 2.0 SPS00
SQLScriptIndex-based cell access for table variables
9PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Allows the developer to execute DML-like
statements on intermediate table variables
without involving the SQL layer
Leads to increased performance
Operations supported
– INSERT
– UPDATE
– DELETE
SQLScriptINSERT/UPDATE/DELETE operators for table variables
10PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
RECORD_COUNT
Function provides the number of rows of a
given table
Previously, SELECT COUNT* INTO a variable
or a combination of CARDINALITY and
ARRAY_AGG functions were used
Both physical tables and table
variables/parameters are supported
SQLScriptRECORD_COUNT operator
11PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
MAP_MERGE
Operator to apply each row of a
tabular input to a mapper function
and union all intermediate result
tables
SQLScriptMAP_MERGE operator
12PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Sequential Execution ( 759ms ) Parallel Execution ( 34ms )
SQLScriptMAP_MERGE operator – Example
13PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Hides the implementation of the
procedure or function from all users
The entire definition of the procedure or function
including its signature is saved as an encrypted
string that is not human-readable
Encrypting a procedure/function means hiding
the content, and this implies losing supportability
features and losing optimizations. Therefore,
encrypted procedures/functions will not be
supported by SQLScript Debugger, PlanViz,
traces, or any supportability tools that can reveal
the procedure/function definitions
SQLScriptProcedure/function encryption
14PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
SQLScript supports the spatial data
type ST_GEOMETRY and SQL spatial
functions to access and manipulate
the spatial data
SQLScript also supports the objective
style function calls, which are needed
for some SQL spatial functions
SQLScriptSupport for spatial types/functions
15PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Global session variables can be used in
SQLScript to share a scalar value between a
procedure and function that are running in
the same session.
Not visible from another session
SET <key> = <value> cannot be used within read-
only procedures and functions
<key> can be a constant string or variable
<value> can be any expression or scalar variable or
function which returns a variable which can be
converted to type string
Session variables are null by default, and can be
reset to null by using the UNSET statement
SQLScriptGlobal session variables
16PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
BIND_AS_<PARAMETER|VALUE>
Control the parametrization behavior of
scalar variables
Allows to manually override the optimizer’s
parameterization decision and general
configuration
SQLScriptParameterization control of scalar variables
17PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
select * from "MD.Products"
where typecode = ?
and category = ‘Notebooks’;
select * from "MD.Products"
where typecode = ‘PR’
and category = ‘Notebooks’;
select * from "MD.Products"
where typecode = ?
and category = ?;
Procedure Call Prepared Statement
SQLScriptParameterization control of scalar variables – Example
18PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
select * from "MD.Products"
where typecode = ‘PR’
and category = ? ;
select * from "MD.Products"
where typecode = ‘PR’
and category = ? ;
select * from "MD.Products"
where typecode = ‘PR’
and category = ? ;
SQLScriptParameterization control of scalar variables – Example
Procedure Call Prepared Statement
19PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Implemented in the new built-in library
SYS.SQLSCRIPT_SYNC
SLEEP_SECONDS – makes the current process
wait for the given number of seconds
WAKEUP_CONNECTION – resumes a process
waiting due to SLEEP_SECONDS
SQLScriptBuilt-in libraries and sleep/wake functions
20PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
The SQLScript code analyzer consists of two built-in procedures that scan CREATE
FUNCTION / CREATE PROCEDURE statements. By applying a selected set of rules, they
search for certain patterns that indicate problems regarding code quality, performance,
or security.
Rules are defined in view SQLSCRIPT_ANALYZER_RULES; currently 4 rules
Procedure ANALYZE_SQLSCRIPT_DEFINITION can be used to analyze the source code of a single
procedure or function which has yet to be created. Procedure ANALYZE_SQLSCRIPT_OBJECTS can be
used to analyze the source code of multiple already existing procedures or functions
The SQLScript code analyzer is currently deactivated by default. It can be activated with an ini parameter or
a session parameter:
alter system alter configuration ('indexserver.ini','SYSTEM') set
('sqlscript', 'enable_code_scanner') = 'true' with reconfigure;
set '__SQLSCRIPT_ENABLE_CODE_SCANNER' = 'true';
SQLScriptSQLScript code analyzer – Overview
21PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
UNNECESSARY_VARIABLE: Each variable is tested if it is used by any output parameter of the procedure
or if it influences the outcome of the procedure. Relevant statements for the outcome could be DML
statements, implicit result sets, conditions of control statements.
UNUSED_VARIABLE_VALUE: If a value assigned to a variable is not used in any other statement, the
assignment can be removed. In case of default assignments in DECLARE statements, the default is never
used.
UNCHECKED_SQL_INJECTION_SAFETY: Parameters of string type should always be checked for SQL
injection safety if they are used in dynamic SQL. This rule checks if for any such parameter the function
is_sql_injection_safe was called. For a simple conditional statement like IF is_sql_injection_safe(:var) = 0
THEN..., the control flow in the true branch is checked. The procedure should either end (by returning or by
throwing an error) or the unsafe parameter value should be escaped with the functions
escape_single_quotes or escape_double_quotes, depending on where the value is used. If the condition is
more complex (e.g. more than one variable checked in one condition), a warning will be displayed, as it
could only be checked if any execution of the dynamic SQL has passed the SQL injection check.
SINGLE_SPACE_LITERAL: This rule searches for string laterals consisting of only one space. If ABAP
VARCHAR MODE is used, such string literals are treated as empty strings. In this case, CHAR(32) can be
used instead of ' '.
SQLScriptSQLScript code analyzer – Rules
22PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Procedure expects 2 input parameters: a string containing the DDL of the procedure or function and the list
of rules
Procedure returns 1 output parameter: the list of findings
SQLScriptSQLScript code analyzer – ANALYZE_SQLSCRIPT_DEFINITION
23PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Procedure expects 2 input parameters: a list of objects which are to be scanned, and a list of rules
Procedure returns 2 output parameters: a list of objects which were scanned, and the findings
SQLScriptSQLScript code analyzer – ANALYZE_SQLSCRIPT_OBJECTS
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.
The information contained herein may be changed without prior notice. 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 or its affiliated
companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP 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,
and they should not be relied upon in making purchasing decisions.
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. All other product and service names mentioned are the trademarks of their respective companies.
See http://global.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
© 2017 SAP SE or an SAP affiliate company. All rights reserved.
2PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Purpose
Use XMLEXTRACT / XMLEXTRACTVALUE to extract an XML fragment or scalar value matching to given
XML path expression. The path expression conforms to XPath 1.0 standard specification.
Syntax
XMLEXTRACT(<XML string>, <XML path expression>)
XMLEXTRACTVALUE(<XML string>, <XML path expression>)
Example
SELECT XMLEXTRACT(
'<doc>
<item><id>1</id><name>Box</name></item>
<item><id>2</id><name>Jar</name></item>
</doc>',
'/doc/item[2]/name' -- defines path and return value
) FROM DUMMY;
-- returns <name>Jar</name>
XML and JSON Processing in the DatabaseXMLEXTRACT and XMLEXTRACTVALUE
3PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Purpose
Use Select FOR XML to retrieve table data in XML format
Syntax
SELECT * FROM <table name> FOR XML
SELECT * FROM <table name> FOR XML (<formatting options>)
Example
FOR XML default
SELECT * FROM Employer
FOR XML;
Normal selection
SELECT * FROM Employer;
FOR XML with formatting options
SELECT * FROM Employer FOR XML
(‘columnstyle’=‘attribute’, ‘header’=‘yes’);
XML and JSON Processing in the DatabaseSELECT FOR XML
4PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Returns multiple records of XML string data as
relational table records by calling a single
XMLTABLE function call
When <XML_namespace_clause> is defined, only
the corresponding XML with the same XML
namespace is returned
<row_pattern> represents the XPath to convert the
XML record to table format
<XML_argument> represents the XML data
COLUMNS <column_definitions> defines the
returning columns
<error_option> returns an error when ERROR ON
ERROR is set, otherwise returns an empty result
XMLTABLE (
[ <XML_namespace_clause>, ]
<row_pattern> PASSING <XML_argument>
COLUMNS <column_definitions> <error_option>
)
<Syntax>
ID NAME
1 Box
2 Jar
XML and JSON Processing in the DatabaseXMLTABLE
5PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Purpose
Use JSON_VALUE or JSON_QUERY to extract a scalar value or an object or an array from a JSON string
or a JSON object using a SQL/JSON path expression.
Syntax
JSON_VALUE(<JSON string>, <JSON path expression> [, <returning behavior> ] |
[, <error behavior>])
JSON_QUERY(<JSON string>, <JSON path expression> [, <returning behavior> ] |
[, <wrapper behavior>] | [, <error behavior>])
ExampleSELECT JSON_VALUE('{"item1":{"sub1":10}, "item2":{"sub2":5}, "item3":{"sub3":7}}',
'$.*.sub2') FROM DUMMY;
-- returns '5'
SELECT JSON_QUERY('{"item1":[1,2], "item2":2, "item3":3}', '$.item1' ) FROM DUMMY;
-- returns '[1, 2]'
XML and JSON Processing in the DatabaseJSON_VALUE and JSON_QUERY
6PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Purpose
Use JSON_TABLE to a relational view of JSON data. Users can query the result returned by this table
function using SQL.
Syntax
JSON_TABLE(<JSON string>, <JSON path expression>, <JSON table columns>] |
[, <error behavior>])
ExampleTable: T1, Column: JSON_Data
{ "PONumber": 1,
"Reference": "MSULLIVA-20141102",
"Requestor": "Martha Sullivan",
"User": "MSULLIVA",
"ShippingInstructions": { … },
"SpecialInstructions": "Surface Mail",
"LineItems": [
{"ItemNumber": 1, "Part": {"Description": "Run Lola Run", "UnitPrice": 19.95, "UPCCode":
43396040144}, "Quantity": 7},
{"ItemNumber": 2, "Part": {"Description": "Felicia's Journey", "UnitPrice": 19.95,
"UPCCode": 12236101345}, "Quantity": 1},
{"ItemNumber": 3, "Part": {"Description": "Lost and Found", "UnitPrice": 19.95, "UPCCode":
85391756323}, "Quantity": 8},
{"ItemNumber": 4, "Part": {"Description": "Karaoke: Rock & Roll Hits of 80's & 90's 8",
"UnitPrice": 19.95, "UPCCode": 13023009592}, "Quantity": 8},
{"ItemNumber": 5, "Part": {"Description": "Theremin: An Electronic Odyssey", "UnitPrice":
19.95, "UPCCode": 27616864451}, "Quantity": 8}
] }
SELECT JT.*
FROM JSON_TABLE(T1.JSON_Data, '$.LineItems[*]'
COLUMNS (
RN FOR ORDINALITY,
ITEM_NUMBER INT PATH '$.ItemNumber',
UPC_CODE BIGINT PATH '$.Part.UPCCode‘ )
) AS JT;
-- returnsRN ITEM_NUMBER UPC_CODE
1 1 43396040144
2 2 12236101345
3 3 85391756323
4 4 13023009592
5 5 27616864451
XML and JSON Processing in the DatabaseJSON_TABLE
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.
The information contained herein may be changed without prior notice. 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 or its affiliated
companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP 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,
and they should not be relied upon in making purchasing decisions.
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. All other product and service names mentioned are the trademarks of their respective companies.
See http://global.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
© 2017 SAP SE or an SAP affiliate company. All rights reserved.
2PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
An SAP HANA DI container is a database
schema
Database objects are deployed into the schema
Definitions have to be written in a schema-free way
Database objects are owned by
a container-specific technical object owner
Schema-external objects are referenced via
database synonyms (or table links)
Cross-ScenariosSAP HANA DI containers – Container schema
Container Schema S (S)
Container S Schema Owner (CSO-S)
Container S Runtime User (RU-S)Container S Deploy User (DU-S)
HDI Metadata Schema 1Other Schema, ERP
HANA DI Deployment API for S
(DA-S)
API Procedure
R
SQL
(CALL DA-S.WRITE(…),
CALL DA-S.MAKE(…), …)
R
SQL
(SELECT, INSERT, …)
View
Container S Object Owner (COO-S)
Table
Synonym
Table
HDI Metadata Schema 1HANA DI Metadata for S
(MD-S)
Container S Metadata Object Owner(s) (MOO-S)
Container S Metadata Schema Owner (MSO-S)
3PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Containers are isolated
Only deployed objects in the same
container can be accessed by default
Privileges for objects in other schemata
(e.g. ERP tables) or other container
schemata need to be explicitly granted to
the object owners
Cross-ScenariosSAP HANA DI containers – Multiple containers
Other Schema
Other Schema
Container Schema S
View
Container Object
Owner for S
Table
Synonym
Table
Owns the Objects
in Schema S
Needs Access to
Other Schemata
(e.g. ERP)
Container Schema T
Other Schema
View
Container Object
Owner for T
Table
Synonym
Table
Owns the Objects
in Schema T
Needs Access to
Other Schemata
(e.g. ERP)
4PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
Database-level container
A container is equal to a database schema
Database objects are deployed into the schema
Definitions have to be written in a schema-free way
Schema-external objects are referenced via
database synonyms
Technical user as object owner
Deployment API and storage schema
view Xas …
from Ytable Y( … )
proc Zas …
from X
CONTAINER
CONTAINER#OO
CONTAINER#DIAPIs Storage
Cross-Scenarios SAP HANA Deployment Infrastructure (HDI) – Container model
5PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
“Zero” privileges by default
Object owner is a restricted database user
Object owner has CREATE ANY on the schema
But, object owner has no external privileges
Schema-free objects
References to external objects are not allowed
view Xas …from Y
proc Zas …from X
CONTAINER
CONTAINER#OO
ERP
view Y( … )
Cross-ScenariosSAP HANA Deployment Infrastructure (HDI) – Container isolation
6PUBLIC© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ
“Zero” privileges by default
Explicitly grant SELECT ON ERP.Y
(w/ grant option) to the container’s object owner
Schema-free objects
Synonym artifacts can point to external objects
Deployment-specific configuration artifacts
can override target specifications
view Xas …
from Yproc Zas …
from X
CONTAINER
CONTAINER#OOview Y( … )
ERP
selectERP.Y
syn Y for ERP.Y
Cross-ScenariosSAP HANA Deployment Infrastructure (HDI) – Cross-container access
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.
The information contained herein may be changed without prior notice. 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 or its affiliated
companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP 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,
and they should not be relied upon in making purchasing decisions.
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. All other product and service names mentioned are the trademarks of their respective companies.
See http://global.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
© 2017 SAP SE or an SAP affiliate company. All rights reserved.