Beruflich Dokumente
Kultur Dokumente
SAP HANA smart data streaming enables you to create and run complex event processing applications to derive
continuous intelligence from streaming event data in real time.
Smart data streaming is a technique for analyzing information about events, in real time, for situational
awareness. When vast numbers of event messages are flooding in, it is difficult to see the big picture. With smart
data streaming, you can analyze events as they stream in and identify emerging threats and opportunities as they
happen. Smart data streaming filters, aggregates, and summarizes data to enable better decision making based
on more complete and timely information.
Smart data streaming does not replace databases. Unlike traditional databases, which are designed for on-
demand queries and transaction processing, smart data streaming is optimized for continuous queries. Thus, it
complements traditional databases to help solve new classes of problems where continuous, event-driven data
analysis is required.
Data flows into the SAP HANA smart data streaming server from external sources through built-in or custom
adapters, which translate incoming messages into a format that is accepted by the SAP HANA smart data
streaming server.
This figure shows a typical smart data streaming deployment. Continuous queries, developed and tested as
projects using the SAP HANA smart data streaming plugin for SAP HANA studio, are deployed to SAP HANA
smart data streaming server. Output adapters translate rows processed by SAP HANA smart data streaming
server into message formats that are compatible with external destinations such as SAP HANA, and send those
messages downstream. SAP ESP cockpit for streaming provides an operations console for configuring smart data
streaming.
Next Steps
SAP HANA smart data streaming is a specialized option that processes streams of incoming event data in real-
time, and collects and acts on incoming information.
It is ideally suited for any situation where data arrives as events happen, and where there is value in collecting,
understanding, and acting on this data right away. A few of the many examples of data sources that produce
streams of events in real-time include:
Sensors
Smart devices
Web sites (click streams)
IT systems (logs)
Financial markets (prices)
Social media
Data flows into streaming projects from any number of sources, typically through adapters, which connect the
sources to the smart data streaming server. The streaming projects contain the business logic that is applied to
the incoming data, typically in the form of continuous queries and rules. These streaming projects are entirely
An SAP HANA smart data streaming cluster consists of one or more nodes with one node per host. Streaming
cluster nodes run and manage the streaming projects you deploy. Streaming nodes must run on dedicated hosts,
one node per host. You can start with one or more streaming nodes, and add additional nodes as needed for
capacity.
Streaming Workspaces
Projects are deployed in workspaces on a streaming cluster. A workspace provides a namespace for the project
and also allows you to control permissions at the workspace level. A streaming cluster must have at least one
workspace.
Streaming Projects
A project defines one or more event streams and the business logic applied to incoming event data to produce
results. It may also include adapters to establish connections to event sources as well as destinations (including
SAP HANA tables). At its most basic level, a project consists of streams and/or windows, and adapters.
Events, projects, streams and windows, and continuous queries are the basics of data-flow programming in smart
data streaming.
A business event is a message that contains information about an actual business event that occurred. Many
business systems produce streams of such events as things happen.
With SAP HANA smart data streaming, you can use streams, windows, and keyed streams with adapters to create
complex projects. Streams, windows, and keyed streams allow you to consume and process input events and
generate output events.
Note
CCL allows you to use delta streams in your projects. SAP recommends delta streams for advanced users only.
Keyed streams support some of the same use cases as delta streams and are easier to work with.
Examples of business events that are often transmitted as streams of event messages include:
Financial market data feeds that transmit trade and quote events, where each event may consist of ticket
symbol, price, quantity, time, and so on.
Radio Frequency Identification System (RFID) sensors that transmit events indicating that an RFID tag was
sensed nearby.
Electronic sensors that transmit messages indicating the health of remote equipment and its components.
Click streams, which transmit a message (a click event) each time a user clicks a link, button, or control on a
website.
Database transaction events, which occur each time a record is added to a database or updated in a
database.
Event Blocks
Business events can be published into smart data streaming projects in collections called event blocks, improving
the performance of your smart data streaming projects. Event blocks come in two different types: envelopes and
transactions. As an event block is being processed by a window, resulting rows are not sent downstream
immediately. Instead, they are stored until the last event of the block is processed, and the resulting events are
then sent downstream. Event blocks have the following properties:
Envelopes: Each row in an envelope is treated atomically; a failure in an event does not discard the envelope.
This behavior is useful if a model's performance is important, but not necessarily the integrity of the data.
Transactions:
A transaction is discarded if any one event in the block fails. Use this behavior to guarantee that logical
blocks of events are completely error-free.
Before a transaction block is sent downstream, all events in the transaction are compressed as much as
possible. For example, an event with an insert and then an update will compress down to a single insert
with updated values.
The operation code (opcode) of an event record specifies the action to perform on the underlying store of a
window for that event.
In many smart data streaming use cases, events are independent of each other; each carries information about
something that happened. In these cases, a stream of events is a series of independent events. If you define a
window on this type of event stream, each incoming event is inserted into the window. If you think of a window as
a table, the new event is added to the window as a new row.
In other use cases, events deliver new information about previous events. Smart data streaming maintains a
current view of the set of information as the incoming events continuously update it. Two common examples are
ordering books for securities in capital markets, and opening orders in a fulfillment system. In both applications,
incoming events may indicate the need to:
To handle information sets that are updated by incoming events, smart data streaming recognizes the following
opcodes in incoming event records:
update Update the record with the specified key. If no such record exists, it is a runtime error.
delete Delete the record with the specified key. If no such record exists, it is a runtime error.
upsert If a record with a matching key exists, update it. If a record with a matching key does not exist, insert
this record.
safedelete If a record with a matching key exists, delete it. If a record with a matching key does not exist, do
nothing.
All event records include an opcode. Each stream or window in the project accepts incoming event records and
produces event records. Output events, including opcodes, are determined by their source (window, stream,
keyed stream, or delta stream) and the processing specified for it.
Refer to the SAP HANA Smart Data Streaming: Developer Guide for details on how windows and streams interpret
the opcodes on incoming event records and generate opcodes for output records.
Both streams and windows process events. The difference is that windows have state, meaning they can retain
and store data, while streams are stateless and cannot.
Streams process incoming events and produce output events according to the continuous query that is attached
to the stream, but no data is retained.
A window consists of a table where incoming events can add rows, update existing rows, or delete rows. You can
set the size of the window based on time, or on the number of events recorded. For example, a window might
retain all events over the past 20 minutes, or the most recent 1,000 events. A window can also retain all events. In
this case, the incoming event stream must be self-managing in that it contains events that both insert rows into
Smart data streaming projects are like applications, and consist of a set of event streams, any other required
datasources, and the business logic applied to incoming event data to produce results.
Table 1:
Element Description
Input streams and windows Receives input data flowing into the project. An input stream
can receive incoming event data on an event-driven basis, and
can also receive static or semistatic sets of data that are
loaded once or periodically refreshed. Input streams that have
statethat is, they can retain and store dataare called win
dows.
Derived streams and windows Takes data from one or more streams or windows and applies
a continuous query to produce a new stream or window. De
rived streams that have state are windows.
SAP HANA smart data streaming uses data-flow programming for processing event streams.
In data-flow programming, you define a set of event streams and the connections between them, and apply
operations to the data as it flows from sources to outputs.
Data-flow programming breaks a potentially complex computation into a sequence of operations with data
flowing from one operation to the next. This technique also provides scalability and potential parallelization, since
each operation is event-driven and independently applied. Each operation processes an event only when it is
received from another operation. No other coordination is needed between operations.
The sample project shown in the figure shows a simple example of this.
Each of the continuous queries in this simple example the VWAP aggregate, the IndividualPositions join object,
and the ValueByBook aggregate - is a type of derived stream, as its schema is derived from other inputs in the
PriceFeed Represents an input window, where incoming data from an external source complies
with a schema consisting of five columns, similar to a database table with columns. The
difference is that in smart data streaming, the streaming data is not stored in a data
base.
Positions Another input window, with data from a different external source. Both Positions and Pri
ceFeed are included as windows, rather than streams, so that the data can be aggre
gated.
VWAP Represents a simple continuous query that performs an aggregation, similar to a SQL
Select statement with a GROUP BY clause.
IndividualPositions Represents a simple continuous query that performs a join of Positions and VWAP, simi
lar to a SQL FROM clause that produces a join.
ValueByBook Another simple query that aggregates data from the stream Individual Positions.
Related Information
SAP HANA smart data streaming has four ways to get output from a running project.
Applications receive information automatically from output adapters attached to a stream when you build the
project. For example, you can load data into an SAP HANA database using an output adapter.
Applications can subscribe to data streams by means of an external subscriber, which users can create using
subscription APIs provided with the product.
You can start a new project that binds (connects) to a stream in a running project, without reconfiguring the
project.
You can run on-demand queries against output windows in a running smart data streaming project. This is
similar to querying a database table.
From the command line, using the streamingquery tool. For more information, see the SAP HANA
Smart Data Streaming: Utilities Guide.
In studio, using the SQL Query view tools.
From third-party applications, using the ODBC Driver for smart data streaming. For more information, see
the SAP HANA Smart Data Streaming: Utilities Guide.
SAP HANA is an in-memory, columnar, massively parallel processing platform that provides a common database
for online transactional processing (OLTP) and online analytical processing (OLAP), eliminating redundancy and
latency. It also unifies end-to-end data processing with search, text, geospatial and predictive analytics on top of
the in-memory columnar foundation, further extending the benefit of redundancy and latency elimination to all
data processing workloads.
SAP HANA can be deployed as a managed service in the cloud or as an optimized on-premise appliance with
tailored data center integration.
Application developers use the SAP HANA smart data streaming plugin for SAP HANA studio, including the visual
editor, text editor, and testing tools, to develop event-based applications. You can also develop custom adapters
using the the adapter toolkit or the SDKs, and monitor and manage your projects using the SAP HANA cockpit.
Adapter developer Create custom input and output adapters using the smart
data streaming adapter toolkit, or one of the SDKs provided
with smart data streaming.
Business analyst Respond to business events in real time, using smart data
streaming analytics and alerts in conjunction with SAP HANA
data.
Smart data streaming projects can take advantage of a broad set of features.
In addition to the basic elements of input streams, adapters, and output streams, a project may include:
Derived streams
References to database tables
CCLScript code
External C code
Custom adapters
Modules that can be developed independently and loaded into a project
Named schemas that store reusable schema definitions
See the SAP HANA Smart Data Streaming: Developer Guide and the SAP HANA Smart Data Streaming: CCL
Reference for code samples that demonstrate CCL and CCLScript.
See the SAP HANA Smart Data Streaming: Adapters Guide and the SAP HANA Smart Data Streaming: Building
Custom Adapters for sample code for custom adapters.
To begin developing a project, start the SAP HANA studio, review studio basics, and optionally step through an
example before creating your own project.
Accessing Smart Data Streaming in SAP HANA Studio [page 15]
Access SAP HANA smart data streaming functionality within the SAP HANA studio by opening the SAP HANA
Streaming Run-Test and SAP HANA Streaming Development perspectives.
Access SAP HANA smart data streaming functionality within the SAP HANA studio by opening the SAP HANA
Streaming Run-Test and SAP HANA Streaming Development perspectives.
Procedure
In SAP HANA studio, go to Window Open Perspective Other , then open the SAP HANA Streaming
Development or SAP HANA Streaming Run-Test perspective.
Related Information
Explore smart data streaming in SAP HANA studio perspectives and views to discover what you can do.
Context
Use the sample projects to see examples of different project structures and diagrams in the Visual editor.
Procedure
1. (Optional) If you are accessing SAP HANA smart data streaming functionality using the SAP HANA smart
data streaming plugin for SAP HANA studio, set up the SAP HANA studio Welcome screen to view various
resources.
a. Click the Customize Page icon to open the Customize dialog.
b. Select the Home tab.
c. In the Root Pages section, select the resources you would like to appear on the Welcome screen. Click OK
to save.
For example,
Click Overview to access SAP HANA smart data streaming documentation and an overview of the
features provided by Maven Integration for Eclipse.
Click Tutorials to access cheat sheet guides on how to create and run a project for streaming.
Click Samples to access examples of completed projects that you can explore and run.
2. To open smart data streaming perspectives, go to Window Open Perspective Other , then open the
SAP HANA Streaming Development perspective or the SAP HANA Streaming Run-Test perspective. To
switch to another perspective, click its tab just below the main menu bar.
a. Use the SAP HANA Streaming Development perspective to:
Create and edit projects
Develop projects and diagrams in the Visual editor, a graphical editing environment
Develop projects in the CCL editor, a text-oriented editing environment where you edit CCL code
Compile projects
b. Use the SAP HANA Streaming Run-Test perspective to:
Connect to servers
Results
For more information, see the SAP HANA Smart Data Streaming: Studio Users Guide.
Related Information
The visual editor, CCL editor, and other tools and views in the SAP HANA Streaming Development perspective
allow you to create, view, and edit a diagram or CCL file.
When viewing the SAP HANA Streaming Development perspective, its components are:
Editor (Center) Streaming Development perspective where you edit the diagram (in the visual editor)
or CCL (in the CCL editor). The Visual and CCL text editors are completely integrated. When
you save and switch to the other editor, your work is saved there as well.
Palette (Right side of Editor) Includes groups of tools used to create new CCL elements on the
diagram. Most shapes on the Palette correspond to a CCL statement.
Properties view (Bottom right) Displays the properties of the object selected in the diagram. You can also set
properties in this view, and edit expressions.
Overview (Right) Helps you understand the big picture, and navigate easily to different areas of a large,
complex diagram. For large diagrams you can scroll the editor by dragging the gray box in the
overview.
Search (Top center) Provides full-text search capability for finding text strings in the workspace. Useful
in navigating File Explorer, and project contents in the CCL editor. You can filter search results,
and copy, remove, or replace results found.
Problems (Below Editor, leftmost tab) Displays errors found when you compile a project.
Console (Below Editor, second tab) Displays messages generated when interacting with smart data
streaming components.
You can customize the arrangement of views in your perspectives. See Customizing the Studio Work Environment
in the SAP HANA Smart Data Streaming: Studio Users Guide.
Related Information
In the SAP HANA Streaming Run-Test perspective, you access tools to test, monitor, debug, and fine-tune a
project.
When viewing the SAP HANA Streaming Run-Test perspective, its components are:
(Upper left) Start and connect to available servers. Your first project is there, already
Server View
running.
(Below Server View, leftmost tab) Manually create and publish events as input to a stream
Manual Input view
or window.
Playback view (Below Server View, second tab) Record data flowing into a running project, or play back
recorded files.
File Upload view (Below Server View, third tab) Publish an existing data file to an input stream or window.
Console view (Lower right) Review log messages and other tracing and debugging information useful to
developers.
Stream view (Middle, leftmost tab) Show the events of an output stream or the retained events in an
output window of a running project.
Monitor view (Tabbed to the right of Stream view) Monitor performance of a running project.
Debugger view (Tabbed to the right of Stream view) Debug a project by setting breakpoints and
watchpoints.
Event Tracer view (Tabbed to the right of Stream view by default) Trace the flow of data through a project.
Run Project button, which is also in the SAP HANA Streaming Development perspective.
Related Information
2.5 Diagrams
In visual authoring, you use diagrams to create and manipulate the streams, windows, connections, and other
components of a project, and create simple queries.
When you open a project in the Visual editor, the project shows a collection of stream and window shapes that are
connected with arrows showing the flow of data. You develop the project by selecting new input and output
streams, windows, and other elements from the Palette, dropping them onto the diagram, connecting them, and
configuring their behavior.
Every project has at least one diagram. A diagram in the Visual editor is a projection of the associated CCL
statements in the project.
When you add a shape or other element to a diagram, it is automatically added to the project when you save. You
can delete an element from a diagram only, or from the project.
To expand or collapse all shapes in the diagram, use the All Verbose or All Iconic buttons on the main
toolbar.
To expand an individual shape, select it and click the "+" box in the shape toolbar.
To collapse an individual shape, select it and click the "-" box in the shape toolbar.
Related Information
Customize the Welcome page in SAP HANA studio to show samples of completed streaming projects. Click the
Customize Page icon in the top right corner of the Welcome page to open the Customize dialog. Select the Home
tab and in the Root Pages section, select the Samples option and click OK. The Welcome page now displays a
Samples subpage.
You can view the examples in studio and run them against sample data installed with the product. Stepping
through examples is an ideal way to watch a simplified set of event data flow through the system.
Indexes Shows how continuous computations can be applied to a stream of market prices to deliver
Calculation insight into the market. This example demonstrates reusable modules. Each of the market
calculations is defined in an external module, that is, a module defined in a separate CCL file, and
then imported into the project. Parameters (in this case, time and intervals) are set when the
module is called.
Pattern Provides a simple example of situation detection: watching for a pattern of events. The example
Matching demonstrates how to watch for employee fraud in a retail setting, based on transaction patterns
from a point-of-sale system. The example applies three Filter queries to an input stream of
transactions, and then uses a Pattern query (CCL MATCHING clause) to produce a Possible
Fraud Alert event when all of the criteria occur in the defined time interval.
Prepay Biller Loads call events (CDRs), such as those generated from a telephone carrier network, and
applies account and call plan information to create a billing record for each call, and maintain a
balance of prepaid minutes. The example demonstrates joins, aggregation, and using joins to
augment the events with reference data.
Top 3 Prices Creates a window showing the top three distinct trade prices for each symbol. The example uses
a Flex operator to create a custom operator with an embedded CCLScript script. A Flex operator
creates a single output stream or window, and allows greater flexibility and control than a simple
SELECT statement. The example also uses a named schema, which can be defined once and
shared by the input stream and output window.
VWAP Defines an input stream of stock market prices, as they might be reported from an exchange,
and computes a moving average price called the volume weighted average price (VWAP). Uses a
filter, and a simple aggregation (GROUP BY).
For details of each example, see the Samples subpage on the Welcome page.
See the SAP HANA Smart Data Streaming: Developer Guide and the SAP HANA Smart Data Streaming: CCL
Reference for code samples that demonstrate CCL and CCLScript.
Related Information
Load and run one of the example projects installed with SAP HANA smart data streaming, so that you can view
end-to-end project execution in your workspace.
Prerequisites
To run these examples, you may need to disable McAfee host intrusion prevention. See your McAfee
documentation for details.
First, click the Customize Page icon in the top right corner of the Welcome page to open the Customize dialog.
Select the Home tab and in the Root Pages section, select the Samples option and click OK. Now you can access
the example projects from the Samples subpage on the Welcome page.
Procedure
b. Double-click and open input windows and input streams to view input data.
Run a second sample project. Server View now shows both samples. Expand it to show all streams for each
projecte.
Run and test all aspects of a project using smart data streaming in SAP HANA studio.
During development, you can use studio to run any compiled project against a server, view data flowing through
the streams and windows defined in the project, execute queries, and use debugging tools. Your project
configuration and licensing determine the type of server connections you can use when running projects. Some
adapters also have special licensing requirements.
In studio you can connect immediately to a cluster to run projects, using default security established for studio
during installation. A cluster consists of a group of server nodes, which are processes that run on hosts. A cluster
can have a single node or multiple nodes.
In a production environment, you typically run projects on a server. Administrators monitor and manage smart
data streaming server nodes, clusters, and projects using SAP HANA cockpit, and configure them using SAP ESP
cockpit for streaming. Command-line utilities and procedures are also available, as discussed in the SAP HANA
Smart Data Streaming: Configuration and Administration Guide.
Related Information
Walk through this hands-on tutorial to create a simple project in the Visual editor.
Context
The sample project demonstrates how you can easily define event streams and windows by attaching a previously
configured adapter and discovering its schema, or by manually defining a window and its schema. It shows you
how to define continuous queriesaggregations, joins, and moreusing the visual tools.
Begin by reviewing background information that helps you understand the project. Then complete the tasks to
build the project.
Begin the tutorial by reading a description of the sample project, and concepts applied in it.
The portfolio valuation project that you build in this tutorial applies current prices to a portfolio of investments to
compute the value of each investment and of the portfolio. It uses simple queries to aggregate and join data from
two input windows, then outputs the refined data into SAP HANA using an output adapter.
The example:
1. Receives a stream of prices in an input window called PriceFeed. The schema for this window has five
columns: Id, Symbol, Price, Shares, and TradeTime. The window uses the Id field as a primary key, and is set
to keep the last 10 minutes of price events.
2. Applies an Aggregate simple query to create a 10-minute moving averagea volume weighted average price
(VWAP). With the VWAP, you can see the value of positions based on the average price, rather than see the
value of your positions change with every small price movement. The VWAP formula is calculated as:
sum(PriceFeed.Price *
PriceFeed.Shares) /
sum(PriceFeed.Shares)
3. Reads data from another input window, Positions, with three columns: BookId, Symbol, and SharesHeld.
4. Applies a Join simple query, joining the market price (from the VWAP aggregate) to your holdings (Positions),
so that you can see the value of your position in each stock:
FROM VWAP
RIGHT JOIN Positions
ON
VWAP.Symbol = Positions.Symbol
5. Applies one more aggregation to show the total value of each "book." This aggregate, ValueByBook, groups
current and average values for individual positions into different "books." Each book may comprise a set of
investment portfolios or funds. In the CCL, a GROUP BY clause performs the aggregation:
6. Attaches an output adapter to output the processed data to an SAP HANA table. This adapter requires an
existing connection to SAP HANA, created using the Data Services view.
Related Information
In the tutorial you use the schema discovery feature to discover an external schema and create a CCL schema
based on the format of the data from the datasource connected to an adapter.
An input adapter identifies the external source for the input stream or window, and translates it into a format that
smart data streaming accepts. You can add adapters to the diagram before or after adding input and output
streams or windows.
Smart data streaming provides a set of built in adapters for common databases, message bus, file systems,
sockets, and more. You can also develop custom adapters using an SDK. Most adapters provided can be used as
input or output adapters.
Every row in a stream or window must have the same structure, or schema including the column names, the
column datatypes, and the order in which the columns appear. Multiple streams or windows can use the same
schema, but each stream or window can only have one schema.
In the tutorial, you discover the schema for the PriceFeed input window from the File/Hadoop Event XML Input
adapter.
To discover a schema, you need to first configure the adapter properties. Each adapter that supports schema
discovery has unique properties that must be set to enable schema discovery. For a list of adapters that support
schema discovery and properties to configure, see the SAP HANA Smart Data Streaming: Studio Users Guide. For
property details, see your adapter type in the SAP HANA Smart Data Streaming: Adapters Guide.
Related Information
Accomplish most common querying tasks using a set of simple queries available in the Visual editor: filter,
aggregate, join, compute, union, and pattern.
The tools for these six queries are available as objects in the Palette, in Streams and Windows.
allows you to filter a stream down to only the events of interest, based on a filter expression.
Filter
Similar to SQL WHERE clause.
allows you to group events that have common values and compute summary statistics for the
Aggregate
group, such as an average. You can also define a window size, based on either time or number of
events. Uses the CCL GROUP BY clause, similar to SQL GROUP BY.
allows you to combine records from multiple streams or windows, forming a new record with
Join
information from each source. Comparable to a join in SQL, where you specify two or more
sources in the FROM clause.
Compute allows you to create a new event with a different schema, and compute the value to be contained
in each column (field) of the new event. Comparable to a projection in SQL, where you use a
SELECT statement to specify the column expressions, and FROM to specify a single source.
allows you to combine multiple streams or windows that all share a common schema into a single
Union
stream or window. Similar to SQL UNION operator.
lets you watch for patterns of events within a single stream or window or across multiple streams
Pattern
and windows. When smart data streaming detects an event pattern in a running project, it
produces an output event. This uses the CCL MATCHING clause.
Prerequisites
Procedure
1. Create a project:
In the SAP HANA Streaming Development perspective in SAP HANA studio, File New Project... ,
then select New Streaming Project
2. For the purposes of this tutorial, in the Name field, enter my_portfolio_valuation.
A valid project name:
Must start with a lowercase letter, underscore, or dollar sign.
All other characters must be lowercase letters, numbers, underscores, or dollar signs.
Must not contain spaces.
For your own projects you can use any name. To ensure that you can run the sample project you are creating,
use the values listed here.
3. In the Directory field, accept the default location or browse to a directory in which to store the new project
folder.
Smart data streaming creates three files in the named directory:
For example, for a project directory named "trades," smart data streaming creates a trades.ccl,
trades.cclnotation, and trades.ccr file in the trades directory.
4. Click Finish to create the project files.
Related Information
Edit projects in the Visual editor by adding shapes from the Palette to the project diagram, connecting them, and
completing the configuration of each shape.
Procedure
1. If the sample project diagram is not already open in the Visual editor, open it now:
a. In SAP HANA Streaming Development perspective, from Project Explorer, open the sample project,
my_portfolio_valuation.
b. Navigate to the .cclnotation file in your project folder and double-click
my_portfolio_valuation.cclnotation.
2. Click in the diagram to begin editing using the Palette.
Tip
To make the Visual editor window full-screen, double-click the <name>:Diagram tab at the top. Double-click
again to revert.
3. Select the input stream element NEWSTREAM that was added automatically when you created the project,
right-click, and choose Delete Element.
To run the sample project with example data, you must delete this element from the project before compiling.
Delete Element removes the element from the project.
Delete from Diagram removes the element from the diagram, but retains it in the project. When you run
the project, everything in the project runs, even elements that are not on the diagram.
4. (Optional) To toggle between the Visual editor and the CCL editor, choose Switch to Text or Switch to
Visual (F6).
Note
The Visual editor, like other graphical user interfaces, offers several ways to accomplish most tasks,
although this guide may not list all of them. For example, in many contexts you can carry out an action by:
Clicking a button or other icon in a shape, or on the main toolbar
Attach an adapter by inserting it in the diagram, connecting it to a stream or window, and setting properties.
Context
This tutorial shows you how to insert an adapter, enable it for schema discovery, then generate and attach the
input window and its schema automatically. This is the best practice for creating a schema when using an adapter
that supports schema discovery.
Alternatively, SAP HANA smart data streaming allows you to create the stream or window and then attach an
adapter. Use this method for adapters that do not support schema discovery, or where you want to explicitly
create an inline schema for input streams or windows.
Procedure
1. Open the Input Adapters compartment in the Palette (to the right of the diagram) and locate the adapter you
want.
For this example, choose the File/Hadoop Event XML Input adapter, which reads data from an XML file.
2. Click the adapter in the Palette, then click in the diagram.
The adapter shape is inserted but its border is red, indicating it is not complete, until you define its properties
and attach it to a stream or window.
3. In the adapter shape toolbar hovering outside the shape, click Edit Properties ( ).
4. (Optional) In the Adapter Properties dialog, change Name to identify your adapter.
5. Configure the adapter for schema discovery:
Required properties are in red.
Note
Leave Use named property set unchecked, as this option does not allow you to discover the schema for this
adapter.
a. Click in the Value column for Directory and click the Browse button ( ).
Property Value
c. Enter a wildcard (*) in the Value column for File (in Directory). Click OK.
Next Steps
Import the schema and create a connected input stream or window with the same schema as the data file.
Related Information
Use the Schema Discovery button in the Adapter shape to discover and automatically create a schema based on
the format of the data from the adapter.
Prerequisites
Create a new input stream Creates and attaches a new stream to the adapter, creates an inline schema
(with inline schema). for the stream, and populates the stream with the schema discovered from
the adapter.
Create a new input stream Creates and attaches a new stream to the adapter, creates and attaches a
(with attached schema). new named schema to the stream, and populates the stream with the schema
discovered from the adapter.
Create a new input window Creates and attaches a new window to the adapter, creates and attaches a
(with attached schema). new named schema to the window, and populates the window with the
schema discovered from the adapter.
Create new named schema. Creates a new named schema and populates it with the schema discovered
from the adapter.
4. Click Finish.
The new input window appears with the default name positions_xml_window1, and is automatically
connected to the File/Hadoop Event XML Input adapter.
The adapter file property is set. The red warning border disappears, indicating that the element is now
valid.
5. In the Schema compartment of the input window, click the Toggle Key buttons for the BookId and Symbol
columns to specify the primary key.
The button indicates primary key columns. With the primary key, the shape becomes valid.
6. Set a keep policy in the input window:
7. Click the input window Edit button and name it positions. Be sure to use lower case.
Create the PriceFeed input window manually, following steps in the next task, or,
Insert another File/Hadoop Event XML Input adapter and configure it for schema discovery. This time, when
you discover the schema, choose pricefeed.xml in the exampledata directory. Name the input window
PriceFeed, click the Id column to make it the primary key, and set the keep policy to 10 MIN.
Related Information
Context
These steps let you create an input window directly, and define the schema, without importing a schema.
If you used the input adapter to discover the schema and generated both input windows automatically, skip these
steps and go directly to the next task.
Procedure
1. In the Visual editor, in the Palette to the right of the diagram, open the Streams and Windows compartment.
In iconic mode, click once to select the shape, then click again to edit the name.
In verbose mode, click the edit icon next to the name.
5. Click the "plus" sign to expand the shape to verbose mode if necessary, and click Add Column ( ) on the
toolbar in the input window, to add each new column.
A new column is created with a default name, and default datatype of integer.
6. Specify additional columns.
a. Double-click each column name to edit it.
b. Then double-click each datatype to select the correct datatype.
For this example, enter these column names and datatypes:
Id integer
Symbol string
TradeTime seconddate
Price float
Shares integer
7. Click the button for the Id column to toggle it to the Key symbol.
Input windows require a primary key.
The Id column is now the primary key for the PriceFeed input window. The red warning border disappears,
indicating that the element is now valid.
8. Create a retention window.
Results
The input window and its schema (or deduced schema) are in the diagram.
Add an Aggregate simple query to the sample diagram to create a volume weighted average price (VWAP).
Context
An Aggregate query groups events that have common values, and computes summary statistics for the group.
Procedure
Indicator Meaning
Connection is allowed
a. Click Add Column Expressions ( ), then Copy Columns from Input ( ) in the shape toolbar to select the
columns to copy into the schema for the aggregate window.
For this example, copy these columns:
PriceFeed.Symbol
PriceFeed.TradeTime
PriceFeed.Price
b. Edit column names to clarify that these columns will hold the most recent price and time for the group:
Change TradeTime to LastTime
Change Price to LastPrice
c. Add additional columns by clicking Add Column Expression in the shape toolbar.
For this example, add another column and edit its name to VWAP.
sum ( PriceFeed.Price *
PriceFeed.Shares ) /
sum ( PriceFeed.Shares )
7. Click Add Group Clause ({ }) to edit the grouping of columns in the aggregate object.
Note
The Aggregate shape must have exactly one GROUP BY expression.
The red warning border disappears, indicating that the element is now valid.
8. Set a keep policy in the input window:
Results
By default, the Aggregate is created as Output, which allows external applications to subscribe to or query it, and
allows you to view it using the Stream View in the SAP HANA Streaming Run-Test perspective.
Related Information
Add a join to the sample project. A join combines events from two or more inputs to create a single stream or
window. It is similar to a join in SQL.
Context
Smart data streaming supports inner joins, left and right outer joins, and full outer joins, with join syntax
comparable to SQL ANSI join syntax and comma-separated syntax. For more information about joins, see the SAP
HANA Smart Data Streaming: Studio Users Guide or the SAP HANA Smart Data Streaming: Developer Guide.
Note
Streams, windows, keyed streams, and delta streams can participate in a join. But, only one stream can
participate in a join. A delta stream may participate in a join only if it has a KEEP clause specified. And, SAP
recommends that only expert users use delta streams: they cannot be added to a project using Studio,
they can only be defined in CCL.
For this example, connect the VWAP aggregate object and the Positions input window to the
IndividualPositions join object, in that order.
Tip
To add multiple connections, Shift+click and hold the Connector tool and add connections. To return to
normal selection, press Esc or click the Select tool in the Palette to release it.
4. Click Add Column Expressions ( ), then Copy Columns ( ) in the join shape toolbar and select columns to
copy.
Tip
If you get an error, or do not see all columns from both inputs listed, try reconnecting the new Join element
to the Positions or VWAP shapes as needed.
For this example, choose Select All, then clear the check box on VWAP.Symbol so that you don't get the
symbol field twice.
Double-click on the expression to open the inline editor, and either type directly or press Ctrl+Space for
syntax completion assistance, to pick from column names and functions, or,
Press Ctrl+F2 to open the expression editor. Press Ctrl+Space to display the available input columns and
built-in functions, or enter the desired expression manually, or,
Modify the expression in the Properties view.
d. Click Add. If a message displays indicating that datatypes for the selected columns should match, click
Yes to continue.
The columns chosen appear in Join Constraints, where you should now see:
ON VWAP.Symbol=positions.Symbol
9. In the join shape, click (Toggle Type to OUTPUT), if this option is available. (If it is not, the shape is already
set to OUTPUT).
Results
The IndividualPositions join shape now shows the completed join, as shown in the figure.
Add a new aggregate to finalize the data and prepare it for output into SAP HANA.
Procedure
b. Click Copy Columns ( ) in the shape toolbar and copy columns BookId, CurrentPosition, and
AveragePosition.
c. Set column expressions:
BookId IndividualPositions.BookId
CurrentPosition sum ( IndividualPositions.CurrentPosition )
AveragePosition sum ( IndividualPositions.AveragePosition )
Tip
Use the inline editor. Double-click on the column expression, and use the Home and End keys to quickly
edit the expression.
Next Steps
Set up a connection and add an output adapter to deposit data into an SAP HANA Studio table. .
Create a HANA service definition, and insert and configure a HANA Output adapter.
Procedure
1. In the Data Services view, right-click the server on which you want to create a new database service definition,
and select Add HANA Service.
2. Right-click the new database service and select Rename Data Service. For this tutorial, name it hanaservice.
3. In the Properties view, set the User parameter to the username necessary for communicating with the
database.
4. Set the Password parameter to the password for your username.
5. (Optional) Add a description of the database service in the Description parameter.
6. (Optional) Select Use Default HANA Server if you are connecting to the local HANA server.
If you choose to connect to the local HANA server, you do not have to provide a HANA hostname or instance
number.
7. (Required if not using local HANA) Specify a database type:
Select Single Tenant if the HANA system is the only database at the location, or;
Procedure
1. Delete any unused elements from the project so that you can run it.
For example, if you have not done so, remove the unused input stream element NEWSTREAM that was added
automatically when you created the project.
2. (Optional) Toggle to Iconic mode or Verbose mode.
Click the Toggle Image button in the upper left corner of a shape, or,
The completed diagram should look like this in Verbose mode. You might need to open some compartments and
click again to see details for all elements.
Next Steps
Follow the procedures Tutorial: Testing a Project, to compile and test the sample project in studio, using test data
provided in your installation.
Related Information
Compile, run, and test the project you have created by using tools in the SAP HANA Streaming Run-Test
perspective.
Related Information
Compile a project before running it to check for errors and make corrections.
Procedure
1. If the sample project is not already open in the Visual editor, open it now.
a. Go to SAP HANA Streaming Development perspective.
b. In Project Explorer, expand the my_portfolio_valuation folder.
c. Double-click my_portfolio_valuation.cclnotation.
2. To compile the project, either:
The project compiles and reports any errors found. Compilation errors are displayed in the Problems or Console
view, depending on the type of error.
Next Steps
Review and resolve any problems. If it compiles with no errors, you can skip Viewing Problems.
Use the Problems view to view error details when trying to validate, upload, and compile projects.
Prerequisites
Procedure
1. Click on a problem in Problems view, or expand the group to see individual errors.
By default, Problems view is at the bottom of the screen, and problems are grouped by severity.
Error details appear in Problems view and in the status bar at the bottom left side of the screen.
Tip
If you double-click on a problem in the problems view while the project is open in the Visual editor, the CCL
editor opens read-only to show you where the problem is. To fix the problem, either:
Return to the Visual editor and fix it there, or,
Close both the Visual editor and CCL editor for the project, and then reopen the project in the CCL
editor.
2. If the error message is too long to show the entire message, click it to read the full text in the status bar at the
bottom of the studio window.
3. Right-click an item to choose from the context menu:
Option Action
Go to Highlight the problem in the .ccl file. The CCL editor opens in read-only mode.
Copy Copy error details to the clipboard. When you exit studio, the contents of problems view are removed. Use
this option to save off errors.
Run the project and watch it open in the SAP HANA Streaming Run-Test perspective.
Prerequisites
Make sure the project compiles without errors. Correct any problems before you can run the project.
Procedure
1. With the diagram open in the editor, click in the main toolbar.
2. Review the running project in SAP HANA Streaming Run-Test perspective.
Test the sample project by loading reference data into the Positions window.
Context
If your project has the File/Hadoop Event XML Input adapter attached to the Positions input window, data is
loaded automatically when you start the project. If you removed or omitted the adapter, use this alternative
process to load the sample data.
1. In Server View, expand the my_portfolio_valuation project to show the list of windows and streams in the
project.
2. Double-click the Positions input window to open it in Stream View.
Stream View is in the upper right-hand portion of SAP HANA Streaming Run-Test perspective.
If your diagram has the File/Hadoop Event XML Input adapter connected to the Positions input window,
Stream View shows sample data for Positions, loaded automatically from the adapter.
If you removed the adapter, go to the next step to load the data manually.
3. Load positions data from a file into the Positions window.
a. Go to File Upload view.
b. Click the Select Project button in the view toolbar. If you only have one project open in Server View, no
dialog appears and smart data streaming automatically selects the project for you. Otherwise, select the
my_portfolio_valuation project in the dialog, and click OK.
c. Click the Browse button, navigate to your <SAP HANA studio workspace>\exampledata folder, and
select positions.xml.
When you install the SAP HANA smart data streaming package, you install the SAP_HANA_STREAMING/
examples/exampledata folder with it. If you have not done so already, copy the exampledata folder to
your SAP HANA studio workspace.
d. Click Open.
e. With positions.xml highlighted in File Upload view, click the Upload button.
Watch the data flow in Stream View, as studio loads the three positions for Book1 and Book2.
Play back the previously recorded price feed data, and view the continuous portfolio valuations in the sample
project.
Procedure
1. In Server View, double-click the IndividualPositions, VWAP, and ValueByBook output windows.
In the Server View list, a red arrow in the lower right corner of the window icon ( ) indicates the output
windows.
2. Click the Playback tab.
3. If necessary, click the Select Project button in the upper right corner of Playback view.
If you only have one project running, Studio selects it for you.
Otherwise, select the my_portfolio_valuation project in the dialog and click OK.
When you install the SAP HANA smart data streaming package, you install the SAP_HANA_STREAMING/
examples/exampledata folder with it. If you have not done so already, copy the exampledata folder to
your SAP HANA studio workspace.
6. In Playback view, in the Playback Mode frame, click the rec/ms button, then enter a rec/ms value of 1.
A value of 1 plays back at a rate of 1000 records per second.
7. Click the green Start Playback button to start playback of the price feed.
8. While the data plays back, click each of the output windows in Stream View to see the calculations revised in
real-time.
9. (Optional) Click Event Tracer view, choose Select Running Project, and click Initialize with Base Data.
In this example, Event Tracer shows the PriceFeed and Positions elements in green to indicate Insert
operations. VWAP, IndividualPositions, and ValueByBook are in blue, indicating Updates. Colors change as
different event types are processed.
Smart data streaming in SAP HANA studio includes other tools for testing projects.
For information beyond the scope of this guide on running, configuring, monitoring, querying, and debugging
projects, see the SAP HANA Smart Data Streaming: Studio Users Guide.
Related Information
Continuous Computation Language (CCL) is the primary event processing language of SAP HANA smart data
streaming. Projects are defined in CCL.
CCL is based on Structured Query Language (SQL), and adapted for stream processing.
CCL supports sophisticated data selection and calculation capabilities, including features such as data grouping,
aggregations, and joins. However, CCL also includes features that are required to manipulate data during real-
time continuous processing, such as windows on data streams, and pattern and event-matching.
A SQL query typically executes only once each time it is submitted to a database server and is resubmitted every
time a user or an application needs to reexecute the query. By contrast, a CCL query can continuously process
dynamic data, making it a key distinguishing feature. Once it is defined in the project, it is registered for
continuous execution and stays active indefinitely. When the project is running in the smart data streaming
server, a registered query executes each time an event arrives from one of its data sources.
Although CCL borrows SQL syntax to define continuous queries, the smart data streaming server does not use a
SQL query engine. Instead, it compiles CCL into a highly efficient byte code that is used by the smart data
streaming server to construct the continuous queries within the data-flow architecture.
CCL queries are converted to an executable form by the CCL compiler. Smart data streaming servers are
optimized for incremental processing, hence the query optimization is different than for databases. Compilation is
typically performed within studio, but it can also be performed by invoking the CCL compiler from the command
line.
CCLScript [page 51]
CCLScript is a scripting language that brings extensibility to CCL, allowing you to create custom operators and
functions that go beyond standard SQL.
CCLScript is a scripting language that brings extensibility to CCL, allowing you to create custom operators and
functions that go beyond standard SQL.
The ability to embed CCLScript scripts in CCL provides tremendous flexibility, and the ability to do it within the
CCL editor maximizes user productivity. CCLScript also allows you to define any complex computations using
procedural logic rather than a relational paradigm.
CCLScript is a simple scripting language consisting of expressions used to compute values from other values, as
well as variables and looping constructs, with the ability to organize instructions in functions. CCLScript syntax is
similar to C and Java, though it also has similarities to languages that solve relatively small programming
problems, such as AWK or Perl.
Related Information
The CCL editor is a text authoring environment within the smart data streaming plugin for SAP HANA studio
where you can edit CCL code.
You can work in the CCL editor exclusively, or use it as a supplement to the Visual editor. The CCL editor offers
syntax completion options, syntax checking, and error validation.
A single CCL file can be open in only one editor at a time. The Visual and CCL editors are completely integrated:
when you save and switch to the other editor, your work is saved there as well.
Most users new to smart data streaming find it easier to get started in the Visual editor. As you gain experience
with the product, and learn to successfully compile and run a simple project, you may want to use the CCL editor
to add advanced features to your projects.
The SAP HANA Smart Data Streaming: Studio Users Guide explains use of the CCL editor within studio.
For CCL language usage and reference details, see the SAP HANA Smart Data Streaming: Developer Guide.
Related Information
Procedure
Note
Advanced CCL users can include multiple CCL files in the same project, by using an IMPORT statement to
import shared schemas and module definitions from another file.
Tip
If you open a .ccl file in the CCL editor when the same project is open in the Visual editor, the CCL editor
opens in read-only mode and you cannot edit the file.
Close both the Visual editor and CCL editor for the project, and then reopen the project in the CCL editor.
Note
Backslashes within string literals are used as escape characters. Any Windows directory paths must
therefore be specified with two backslashes.
6. Choose File Save (Ctrl+S) to save the .ccl file and the project.
Related Information
The CCL for the Portfolio Valuation sample project created in the Studio Visual editor is shown here, with the
corresponding shape in the diagram for each element. Line breaks are added for readability.
/**@SIMPLEQUERY=AGGREGATE*/
CREATE OUTPUT WINDOW VWAP
PRIMARY KEY DEDUCED
KEEP ALL ROWS
AS
SELECT
PriceFeed.Symbol Symbol ,
PriceFeed.TradeTime LastTime ,
PriceFeed.Price LastPrice ,
sum ( PriceFeed.Price * PriceFeed.Shares ) /
sum ( PriceFeed.Shares ) VWAP
FROM PriceFeed
GROUP BY PriceFeed.Symbol ;
/**@SIMPLEQUERY=JOIN*/
CREATE OUTPUT WINDOW IndividualPositions
PRIMARY KEY DEDUCED
KEEP ALL ROWS
AS
SELECT
VWAP.LastTime LastTime ,
VWAP.LastPrice LastPrice ,
VWAP.VWAP VWAP ,
Positions.BookId BookId ,
Positions.Symbol Symbol ,
Positions.SharesHeld SharesHeld ,
VWAP.LastPrice *
Positions.SharesHeld CurrentPosition ,
VWAP.VWAP *
Positions.SharesHeld AveragePosition
FROM VWAP RIGHT JOIN Positions ON
VWAP.Symbol = Positions.Symbol ;
/**@SIMPLEQUERY=AGGREGATE*/
CREATE OUTPUT WINDOW ValueByBook
PRIMARY KEY DEDUCED
KEEP ALL ROWS
AS
SELECT
IndividualPositions.BookId BookId ,
sum ( IndividualPositions.CurrentPosition )
CurrentPosition ,
sum ( IndividualPositions.AveragePosition )
AveragePosition
FROM IndividualPositions
GROUP BY IndividualPositions.BookId ;
Related Information
This variation of the portfolio valuation project uses a defined module with a named schema to easily scale out the
application in a very high volume deployment. The SAP HANA Output adapter is not included in this module.
The module, valuation.ccl, computes the VWAP aggregate, and does the join to the Positions window. The
project uses the module to divide the moving data into smaller partitions, based on the first letter of the Symbol
column. This strategy spreads the load out to more cores, thereby increasing throughput. By using modules, with
very little coding you can easily double, quadruple, and so on, the number of partitions.
This example also implements the streaming tick data in PriceFeed as a stream rather than as an input window.
Because keeping every tick would use a lot of memory, and because the state is never updated or queried, a
stream is a more likely choice than a window in a real-world scenario for this event stream.
Example
Create Module valuation
DECLARE
PARAMETER STRING afrom;
PARAMETER STRING ato;
END;
Example
Create Named Schema TradesSchema
Example
Create Named Schema PortfolioSchema
Example
Import and Load the valuation Module
In the parent scope, the valuation module is loaded three times, as Valuation1, Valuation2, and Valuation3.
1. The IN clause binds the input streams in the module to streams in the parent scope. TradesIn is bound to
InputStream1, and Portfolio is bound to InputPositions.
2. The OUT clause binds the output window in the module, ValueBySymbol, with the three parameterized
output windows, VbySym1, VbySym2, and VbySym3, and partitions the VWAP aggregate as VWAP1,
VWAP2, and VWAP3.
IMPORT 'import.ccl';
IMPORT 'valuation.ccl';
DECLARE
PARAMETER STRING afrom :='A';
Note
Edit the default value for the dir property to the sandbox base directory. For example, change dir='../
exampledata to dir='<sandbox-base-directory>/exampledata'. Otherwise, the example does not
compile properly and you receive an error message.
Coding Samples
Any software coding and/or code lines / strings ("Code") included in this documentation are only examples and are not intended to be used in a productive system
environment. The Code is only intended to better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and
completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, unless damages were caused by SAP
intentionally or by SAP's gross negligence.
Accessibility
The information contained in the SAP documentation represents SAP's current view of accessibility criteria as of the date of publication; it is in no way intended to be a
binding guideline on how to ensure accessibility of software products. SAP in particular disclaims any liability in relation to this document. This disclaimer, however, does
not apply in cases of wilful misconduct or gross negligence of SAP. Furthermore, this document does not result in any direct or indirect contractual obligations of SAP.
Gender-Neutral Language
As far as possible, SAP documentation is gender neutral. Depending on the context, the reader is addressed directly with "you", or a gender-neutral noun (such as "sales
person" or "working days") is used. If when referring to members of both sexes, however, the third-person singular cannot be avoided or a gender-neutral noun does not
exist, SAP reserves the right to use the masculine form of the noun and pronoun. This is to ensure that the documentation remains comprehensible.
Internet Hyperlinks
The SAP documentation may contain hyperlinks to the Internet. These hyperlinks are intended to serve as a hint about where to find related information. SAP does not
warrant the availability and correctness of this related information or the ability of this information to serve a particular purpose. SAP shall not be liable for any damages
caused by the use of related information unless damages have been caused by SAP's gross negligence or willful misconduct. All links are categorized for transparency
(see: http://help.sap.com/disclaimer).