blob: fbb3381409adaac3ec5bc8c09d2c5b1032012eae [file] [log] [blame]
Yingyi Bu08953b22016-03-25 15:23:26 -07001<!DOCTYPE html>
2<!--
3 | Generated by Apache Maven Doxia at 2016-03-25
4 | Rendered using Apache Maven Fluido Skin 1.3.0
5-->
6<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7 <head>
8 <meta charset="UTF-8" />
9 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
10 <meta name="Date-Revision-yyyymmdd" content="20160325" />
11 <meta http-equiv="Content-Language" content="en" />
12 <title>AsterixDB &#x2013; Support for Data Ingestion in AsterixDB</title>
13 <link rel="stylesheet" href="../css/apache-maven-fluido-1.3.0.min.css" />
14 <link rel="stylesheet" href="../css/site.css" />
15 <link rel="stylesheet" href="../css/print.css" media="print" />
16
17
18 <script type="text/javascript" src="../js/apache-maven-fluido-1.3.0.min.js"></script>
19
20
21
Yingyi Bu08953b22016-03-25 15:23:26 -070022
Yingyi Bu08953b22016-03-25 15:23:26 -070023
24 </head>
25 <body class="topBarDisabled">
26
27
28
29
30 <div class="container-fluid">
31 <div id="banner">
32 <div class="pull-left">
33 <a href="http://asterixdb.apache.org/" id="bannerLeft">
34 <img src="../images/asterixlogo.png" alt="AsterixDB"/>
35 </a>
36 </div>
37 <div class="pull-right"> </div>
38 <div class="clear"><hr/></div>
39 </div>
40
41 <div id="breadcrumbs">
42 <ul class="breadcrumb">
43
44
45 <li id="publishDate">Last Published: 2016-03-25</li>
46
47
48
49 <li id="projectVersion" class="pull-right">Version: 0.8.8-incubating</li>
50
51 <li class="divider pull-right">|</li>
52
53 <li class="pull-right"> <a href="../index.html" title="Documentation Home">
54 Documentation Home</a>
55 </li>
56
57 </ul>
58 </div>
59
60
61 <div class="row-fluid">
62 <div id="leftColumn" class="span3">
63 <div class="well sidebar-nav">
64
65
66 <ul class="nav nav-list">
67 <li class="nav-header">Documentation</li>
68
69 <li>
70
71 <a href="../install.html" title="Installing and Managing AsterixDB using Managix">
72 <i class="none"></i>
73 Installing and Managing AsterixDB using Managix</a>
74 </li>
75
76 <li>
77
78 <a href="../yarn.html" title="Deploying AsterixDB using YARN">
79 <i class="none"></i>
80 Deploying AsterixDB using YARN</a>
81 </li>
82
83 <li>
84
85 <a href="../aql/primer.html" title="AsterixDB 101: An ADM and AQL Primer">
86 <i class="none"></i>
87 AsterixDB 101: An ADM and AQL Primer</a>
88 </li>
89
90 <li>
91
92 <a href="../aql/primer-sql-like.html" title="AsterixDB 101: An ADM and AQL Primer (For SQL Fans)">
93 <i class="none"></i>
94 AsterixDB 101: An ADM and AQL Primer (For SQL Fans)</a>
95 </li>
96
97 <li>
98
Yingyi Bu08953b22016-03-25 15:23:26 -070099 <a href="../aql/datamodel.html" title="Asterix Data Model (ADM)">
100 <i class="none"></i>
101 Asterix Data Model (ADM)</a>
102 </li>
103
104 <li>
105
106 <a href="../aql/manual.html" title="Asterix Query Language (AQL)">
107 <i class="none"></i>
108 Asterix Query Language (AQL)</a>
109 </li>
110
111 <li>
112
113 <a href="../aql/functions.html" title="AQL Functions">
114 <i class="none"></i>
115 AQL Functions</a>
116 </li>
117
118 <li>
119
120 <a href="../aql/allens.html" title="AQL Allen's Relations Functions">
121 <i class="none"></i>
122 AQL Allen's Relations Functions</a>
123 </li>
124
125 <li>
126
127 <a href="../aql/similarity.html" title="AQL Support of Similarity Queries">
128 <i class="none"></i>
129 AQL Support of Similarity Queries</a>
130 </li>
131
132 <li>
133
134 <a href="../aql/externaldata.html" title="Accessing External Data">
135 <i class="none"></i>
136 Accessing External Data</a>
137 </li>
138
139 <li class="active">
140
141 <a href="#"><i class="none"></i>Support for Data Ingestion in AsterixDB</a>
142 </li>
143
144 <li>
145
146 <a href="../udf.html" title="Support for User Defined Functions in AsterixDB">
147 <i class="none"></i>
148 Support for User Defined Functions in AsterixDB</a>
149 </li>
150
151 <li>
152
153 <a href="../aql/filters.html" title="Filter-Based LSM Index Acceleration">
154 <i class="none"></i>
155 Filter-Based LSM Index Acceleration</a>
156 </li>
157
158 <li>
159
160 <a href="../api.html" title="HTTP API to AsterixDB">
161 <i class="none"></i>
162 HTTP API to AsterixDB</a>
163 </li>
164 </ul>
165
166
167
168 <hr class="divider" />
169
170 <div id="poweredBy">
171 <div class="clear"></div>
172 <div class="clear"></div>
173 <div class="clear"></div>
174 <a href="https://code.google.com/p/hyracks/" title="Hyracks" class="builtBy">
175 <img class="builtBy" alt="Hyracks" src="../images/hyrax_ts.png" />
176 </a>
177 </div>
178 </div>
179 </div>
180
181
182 <div id="bodyColumn" class="span9" >
183
184 <!-- ! Licensed to the Apache Software Foundation (ASF) under one
185 ! or more contributor license agreements. See the NOTICE file
186 ! distributed with this work for additional information
187 ! regarding copyright ownership. The ASF licenses this file
188 ! to you under the Apache License, Version 2.0 (the
189 ! "License"); you may not use this file except in compliance
190 ! with the License. You may obtain a copy of the License at
191 !
192 ! http://www.apache.org/licenses/LICENSE-2.0
193 !
194 ! Unless required by applicable law or agreed to in writing,
195 ! software distributed under the License is distributed on an
196 ! "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
197 ! KIND, either express or implied. See the License for the
198 ! specific language governing permissions and limitations
199 ! under the License.
200 ! --><h1>Support for Data Ingestion in AsterixDB</h1>
201<div class="section">
202<h2><a name="Table_of_Contents"></a><a name="atoc" id="#toc">Table of Contents</a></h2>
203
204<ul>
205
206<li><a href="#Introduction">Introduction</a></li>
207
208<li><a href="#FeedAdaptors">Feed Adaptors</a></li>
209
210<li><a href="#FeedPolicies">Feed Policies</a></li>
211</ul></div>
212<div class="section">
213<h2><a name="Introduction">Introduction</a></h2>
214<p>In this document, we describe the support for data ingestion in AsterixDB. Data feeds are a new mechanism for having continuous data arrive into a BDMS from external sources and incrementally populate a persisted dataset and associated indexes. We add a new BDMS architectural component, called a data feed, that makes a Big Data system the caretaker for functionality that used to live outside, and we show how it improves users&#x2019; lives and system performance.</p></div>
215<div class="section">
216<h2><a name="Feed_Adaptors"></a><a name="FeedAdaptors">Feed Adaptors</a></h2>
217<p>The functionality of establishing a connection with a data source and receiving, parsing and translating its data into ADM records (for storage inside AsterixDB) is contained in a feed adaptor. A feed adaptor is an implementation of an interface and its details are specific to a given data source. An adaptor may optionally be given parameters to configure its runtime behavior. Depending upon the data transfer protocol/APIs offered by the data source, a feed adaptor may operate in a push or a pull mode. Push mode involves just one initial request by the adaptor to the data source for setting up the connection. Once a connection is authorized, the data source &#x201c;pushes&#x201d; data to the adaptor without any subsequent requests by the adaptor. In contrast, when operating in a pull mode, the adaptor makes a separate request each time to receive data. AsterixDB currently provides built-in adaptors for several popular data sources such as Twitter, CNN, and RSS feeds. AsterixDB additionally provides a generic socket-based adaptor that can be used to ingest data that is directed at a prescribed socket.</p>
218<p>In this tutorial, we shall describe building two example data ingestion pipelines that cover the popular scenario of ingesting data from (a) Twitter and (b) RSS Feed source.</p>
219<div class="section">
220<div class="section">
221<h4><a name="Ingesting_Twitter_Stream"></a>Ingesting Twitter Stream</h4>
222<p>We shall use the built-in push-based Twitter adaptor. As a pre-requisite, we must define a Tweet using the AsterixDB Data Model (ADM) and the AsterixDB Query Language (AQL). Given below are the type definition in AQL that create a Tweet datatype which is representative of a real tweet as obtained from Twitter.</p>
223
224<div class="source">
225<div class="source">
226<pre> create dataverse feeds;
227 use dataverse feeds;
228
229 create type TwitterUser if not exists as open{
230 screen_name: string,
231 language: string,
232 friends_count: int32,
233 status_count: int32,
234 name: string,
235 followers_count: int32
236 };
237 create type Tweet if not exists as open{
238 id: string,
239 user: TwitterUser,
240 latitude:double,
241 longitude:double,
242 created_at:string,
243 message_text:string
244 };
245
246 create dataset Tweets (Tweet)
247 primary key id;
248</pre></div></div>
249<p>We also create a dataset that we shall use to persist the tweets in AsterixDB. Next we make use of the <tt>create feed</tt> AQL statement to define our example data feed.</p>
250<div class="section">
251<h5><a name="Using_the_push_twitter_feed_adapter"></a>Using the &#x201c;push_twitter&#x201d; feed adapter</h5>
252<p>The &#x201c;push_twitter&#x201d; adaptor requires setting up an application account with Twitter. To retrieve tweets, Twitter requires registering an application with Twitter. Registration involves providing a name and a brief description for the application. Each application has an associated OAuth authentication credential that includes OAuth keys and tokens. Accessing the Twitter API requires providing the following. 1. Consumer Key (API Key) 2. Consumer Secret (API Secret) 3. Access Token 4. Access Token Secret</p>
253<p>The &#x201c;push_twitter&#x201d; adaptor takes as configuration the above mentioned parameters. End users are required to obtain the above authentication credentials prior to using the &#x201c;push_twitter&#x201d; adaptor. For further information on obtaining OAuth keys and tokens and registering an application with Twitter, please visit <a class="externalLink" href="http://apps.twitter.com">http://apps.twitter.com</a></p>
254<p>Given below is an example AQL statement that creates a feed called &#x201c;TwitterFeed&#x201d; by using the &#x201c;push_twitter&#x201d; adaptor.</p>
255
256<div class="source">
257<div class="source">
258<pre> use dataverse feeds;
259
260 create feed TwitterFeed if not exists using &quot;push_twitter&quot;
261 ((&quot;type-name&quot;=&quot;Tweet&quot;),
262 (&quot;consumer.key&quot;=&quot;************&quot;),
263 (&quot;consumer.secret&quot;=&quot;**************&quot;),
264 (&quot;access.token&quot;=&quot;**********&quot;),
265 (&quot;access.token.secret&quot;=&quot;*************&quot;));
266</pre></div></div>
267<p>It is required that the above authentication parameters are provided valid values. Note that the <tt>create feed</tt> statement does not initiate the flow of data from Twitter into our AsterixDB instance. Instead, the <tt>create feed</tt> statement only results in registering the feed with AsterixDB. The flow of data along a feed is initiated when it is connected to a target dataset using the connect feed statement (which we shall revisit later).</p></div></div>
268<div class="section">
269<h4><a name="Lifecycle_of_a_Feed"></a>Lifecycle of a Feed</h4>
270<p>A feed is a logical artifact that is brought to life (i.e., its data flow is initiated) only when it is connected to a dataset using the <tt>connect
271feed</tt> AQL statement. Subsequent to a <tt>connect feed</tt> statement, the feed is said to be in the connected state. Multiple feeds can simultaneously be connected to a dataset such that the contents of the dataset represent the union of the connected feeds. In a supported but unlikely scenario, one feed may also be simultaneously connected to different target datasets. Note that connecting a secondary feed does not require the parent feed (or any ancestor feed) to be in the connected state; the order in which feeds are connected to their respective datasets is not important. Furthermore, additional (secondary) feeds can be added to an existing hierarchy and connected to a dataset at any time without impeding/interrupting the flow of data along a connected ancestor feed.</p>
272
273<div class="source">
274<div class="source">
275<pre> use dataverse feeds;
276
277 connect feed TwitterFeed to dataset Tweets;
278</pre></div></div>
279<p>The <tt>connect feed</tt> statement above directs AsterixDB to persist the <tt>TwitterFeed</tt> feed in the <tt>Tweets</tt> dataset. If it is required (by the high-level application) to also retain the raw tweets obtained from Twitter, the end user may additionally choose to connect TwitterFeed to a different dataset.</p>
280<p>Let the feed run for a minute, then run the following query to see the latest tweets that are stored into the data set.</p>
281
282<div class="source">
283<div class="source">
284<pre> use dataverse feeds;
285
286 for $i in dataset Tweets limit 10 return $i;
287</pre></div></div>
288<p>The flow of data from a feed into a dataset can be terminated explicitly by use of the <tt>disconnect feed</tt> statement. Disconnecting a feed from a particular dataset does not interrupt the flow of data from the feed to any other dataset(s), nor does it impact other connected feeds in the lineage.</p>
289
290<div class="source">
291<div class="source">
292<pre> use dataverse feeds;
293
294 disconnect feed TwitterFeed from dataset Tweets;
295</pre></div></div></div>
296<div class="section">
297<h4><a name="Ingesting_an_RSS_Feed"></a>Ingesting an RSS Feed</h4>
298<p>RSS (Rich Site Summary), originally RDF Site Summary and often called Really Simple Syndication, uses a family of standard web feed formats to publish frequently updated information: blog entries, news headlines, audio, video. An RSS document (called &#x201c;feed&#x201d;, &#x201c;web feed&#x201d;, or &#x201c;channel&#x201d;) includes full or summarized text, and metadata, like publishing date and author&#x2019;s name. RSS feeds enable publishers to syndicate data automatically.</p>
299<div class="section">
300<h5><a name="Using_the_rss_feed_feed_adapter"></a>Using the &#x201c;rss_feed&#x201d; feed adapter</h5>
301<p>AsterixDB provides a built-in feed adaptor that allows retrieving data given a collection of RSS end point URLs. As observed in the case of ingesting tweets, it is required to model an RSS data item using AQL.</p>
302
303<div class="source">
304<div class="source">
305<pre> use dataverse feeds;
306
307 create type Rss if not exists as open {
308 id: string,
309 title: string,
310 description: string,
311 link: string
312 };
313
314 create dataset RssDataset (Rss)
315 primary key id;
316</pre></div></div>
317<p>Next, we define an RSS feed using our built-in adaptor &#x201c;rss_feed&#x201d;.</p>
318
319<div class="source">
320<div class="source">
321<pre> use dataverse feeds;
322
323 create feed my_feed using
324 rss_feed (
325 (&quot;type-name&quot;=&quot;Rss&quot;),
326 (&quot;url&quot;=&quot;http://rss.cnn.com/rss/edition.rss&quot;)
327 );
328</pre></div></div>
329<p>In the above definition, the configuration parameter &#x201c;url&#x201d; can be a comma-separated list that reflects a collection of RSS URLs, where each URL corresponds to an RSS endpoint or a RSS feed. The &#x201c;rss_adaptor&#x201d; retrieves data from each of the specified RSS URLs (comma separated values) in parallel.</p>
330<p>The following statements connect the feed into the <tt>RssDataset</tt>:</p>
331
332<div class="source">
333<div class="source">
334<pre> use dataverse feeds;
335
336 connect feed my_feed to dataset RssDataset;
337</pre></div></div>
338<p>The following statements show the latest data from the data set, and disconnect the feed from the data set.</p>
339
340<div class="source">
341<div class="source">
342<pre> use dataverse feeds;
343
344 for $i in dataset RssDataset limit 10 return $i;
345
346 disconnect feed my_feed from dataset RssDataset;
347</pre></div></div>
348<p>AsterixDB also allows multiple feeds to be connected to form a cascade network to process data.</p></div></div></div></div>
349<div class="section">
350<h2><a name="Policies_for_Feed_Ingestion"></a><a name="FeedPolicies">Policies for Feed Ingestion</a></h2>
351<p>Multiple feeds may be concurrently operational on an AsterixDB cluster, each competing for resources (CPU cycles, network bandwidth, disk IO) to maintain pace with their respective data sources. As a data management system, AsterixDB is able to manage a set of concurrent feeds and make dynamic decisions related to the allocation of resources, resolving resource bottlenecks and the handling of failures. Each feed has its own set of constraints, influenced largely by the nature of its data source and the applications that intend to consume and process the ingested data. Consider an application that intends to discover the trending topics on Twitter by analyzing tweets that are being processed. Losing a few tweets may be acceptable. In contrast, when ingesting from a data source that provides a click-stream of ad clicks, losing data would translate to a loss of revenue for an application that tracks revenue by charging advertisers per click.</p>
352<p>AsterixDB allows a data feed to have an associated ingestion policy that is expressed as a collection of parameters and associated values. An ingestion policy dictates the runtime behavior of the feed in response to resource bottlenecks and failures. AsterixDB provides a list of policy parameters that help customize the system&#x2019;s runtime behavior when handling excess records. AsterixDB provides a set of built-in policies, each constructed by setting appropriate value(s) for the policy parameter(s) from the table below.</p>
353<div class="section">
354<div class="section">
355<h4><a name="Policy_Parameters"></a>Policy Parameters</h4>
356
357<ul>
358
359<li>
360<p><i>excess.records.spill</i>: Set to true if records that cannot be processed by an operator for lack of resources (referred to as excess records hereafter) should be persisted to the local disk for deferred processing. (Default: false)</p></li>
361
362<li>
363<p><i>excess.records.discard</i>: Set to true if excess records should be discarded. (Default: false)</p></li>
364
365<li>
366<p><i>excess.records.throttle</i>: Set to true if rate of arrival of records is required to be reduced in an adaptive manner to prevent having any excess records (Default: false)</p></li>
367
368<li>
369<p><i>excess.records.elastic</i>: Set to true if the system should attempt to resolve resource bottlenecks by re-structuring and/or rescheduling the feed ingestion pipeline. (Default: false)</p></li>
370
371<li>
372<p><i>recover.soft.failure</i>: Set to true if the feed must attempt to survive any runtime exception. A false value permits an early termination of a feed in such an event. (Default: true)</p></li>
373
374<li>
375<p><i>recover.soft.failure</i>: Set to true if the feed must attempt to survive a hardware failures (loss of AsterixDB node(s)). A false value permits the early termination of a feed in the event of a hardware failure (Default: false)</p></li>
376</ul>
377<p>Note that the end user may choose to form a custom policy. For example, it is possible in AsterixDB to create a custom policy that spills excess records to disk and subsequently resorts to throttling if the spillage crosses a configured threshold. In all cases, the desired ingestion policy is specified as part of the <tt>connect feed</tt> statement or else the &#x201c;Basic&#x201d; policy will be chosen as the default. It is worth noting that a feed can be connected to a dataset at any time, which is independent from other related feeds in the hierarchy.</p>
378
379<div class="source">
380<div class="source">
381<pre> use dataverse feeds;
382
383 connect feed TwitterFeed to dataset Tweets
384 using policy Basic ;
385</pre></div></div></div></div></div>
386 </div>
387 </div>
388 </div>
389
390 <hr/>
391
392 <footer>
393 <div class="container-fluid">
394 <div class="row span12">Copyright &copy; 2016
395 <a href="http://www.apache.org/">The Apache Software Foundation</a>.
396 All Rights Reserved.
397
398 </div>
399
400 <?xml version="1.0" encoding="UTF-8"?>
401<div class="row-fluid">Apache AsterixDB, AsterixDB, Apache, the Apache
402 feather logo, and the Apache AsterixDB project logo are either
403 registered trademarks or trademarks of The Apache Software
404 Foundation in the United States and other countries.
405 All other marks mentioned may be trademarks or registered
406 trademarks of their respective owners.</div>
407
408
409 </div>
410 </footer>
411 </body>
412</html>