blob: bea59a6d2a753d52125d9c79b3262a0129c26f1b [file] [log] [blame]
Ian Maxone2b799e2015-11-24 18:20:03 -08001<!DOCTYPE html>
2<!--
3 | Generated by Apache Maven Doxia at 2015-11-24
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="20151124" />
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
Ian Maxone2b799e2015-11-24 18:20:03 -080022
Ian Maxone2b799e2015-11-24 18:20:03 -080023
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: 2015-11-24</li>
46
47
48
49 <li id="projectVersion" class="pull-right">Version: 0.8.7-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
99 <a href="../aql/js-sdk.html" title="AsterixDB Javascript SDK">
100 <i class="none"></i>
101 AsterixDB Javascript SDK</a>
102 </li>
103
104 <li>
105
106 <a href="../aql/datamodel.html" title="Asterix Data Model (ADM)">
107 <i class="none"></i>
108 Asterix Data Model (ADM)</a>
109 </li>
110
111 <li>
112
113 <a href="../aql/manual.html" title="Asterix Query Language (AQL)">
114 <i class="none"></i>
115 Asterix Query Language (AQL)</a>
116 </li>
117
118 <li>
119
120 <a href="../aql/functions.html" title="AQL Functions">
121 <i class="none"></i>
122 AQL Functions</a>
123 </li>
124
125 <li>
126
127 <a href="../aql/allens.html" title="AQL Allen's Relations Functions">
128 <i class="none"></i>
129 AQL Allen's Relations Functions</a>
130 </li>
131
132 <li>
133
134 <a href="../aql/similarity.html" title="AQL Support of Similarity Queries">
135 <i class="none"></i>
136 AQL Support of Similarity Queries</a>
137 </li>
138
139 <li>
140
141 <a href="../aql/externaldata.html" title="Accessing External Data">
142 <i class="none"></i>
143 Accessing External Data</a>
144 </li>
145
146 <li class="active">
147
148 <a href="#"><i class="none"></i>Support for Data Ingestion in AsterixDB</a>
149 </li>
150
151 <li>
152
153 <a href="../udf.html" title="Support for User Defined Functions in AsterixDB">
154 <i class="none"></i>
155 Support for User Defined Functions in AsterixDB</a>
156 </li>
157
158 <li>
159
160 <a href="../aql/filters.html" title="Filter-Based LSM Index Acceleration">
161 <i class="none"></i>
162 Filter-Based LSM Index Acceleration</a>
163 </li>
164
165 <li>
166
167 <a href="../api.html" title="HTTP API to AsterixDB">
168 <i class="none"></i>
169 HTTP API to AsterixDB</a>
170 </li>
171 </ul>
172
173
174
175 <hr class="divider" />
176
177 <div id="poweredBy">
178 <div class="clear"></div>
179 <div class="clear"></div>
180 <div class="clear"></div>
181 <a href="https://code.google.com/p/hyracks/" title="Hyracks" class="builtBy">
182 <img class="builtBy" alt="Hyracks" src="../images/hyrax_ts.png" />
183 </a>
184 </div>
185 </div>
186 </div>
187
188
189 <div id="bodyColumn" class="span9" >
190
191 <!-- ! Licensed to the Apache Software Foundation (ASF) under one
192 ! or more contributor license agreements. See the NOTICE file
193 ! distributed with this work for additional information
194 ! regarding copyright ownership. The ASF licenses this file
195 ! to you under the Apache License, Version 2.0 (the
196 ! "License"); you may not use this file except in compliance
197 ! with the License. You may obtain a copy of the License at
198 !
199 ! http://www.apache.org/licenses/LICENSE-2.0
200 !
201 ! Unless required by applicable law or agreed to in writing,
202 ! software distributed under the License is distributed on an
203 ! "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
204 ! KIND, either express or implied. See the License for the
205 ! specific language governing permissions and limitations
206 ! under the License.
207 ! --><h1>Support for Data Ingestion in AsterixDB</h1>
208<div class="section">
209<h2><a name="Table_of_Contents"></a><a name="atoc" id="#toc">Table of Contents</a></h2>
210
211<ul>
212
213<li><a href="#Introduction">Introduction</a></li>
214
215<li><a href="#FeedAdaptors">Feed Adaptors</a></li>
216
217<li><a href="#FeedPolicies">Feed Policies</a></li>
218</ul></div>
219<div class="section">
220<h2><a name="Introduction">Introduction</a></h2>
221<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>
222<div class="section">
223<h2><a name="Feed_Adaptors"></a><a name="FeedAdaptors">Feed Adaptors</a></h2>
224<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>
225<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>
226<div class="section">
227<div class="section">
228<h4><a name="Ingesting_Twitter_Stream"></a>Ingesting Twitter Stream</h4>
229<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>
230
231<div class="source">
232<div class="source">
233<pre> create dataverse feeds;
234 use dataverse feeds;
235
236 create type TwitterUser if not exists as open{
237 screen_name: string,
238 language: string,
239 friends_count: int32,
240 status_count: int32,
241 name: string,
242 followers_count: int32
243 };
244 create type Tweet if not exists as open{
245 id: string,
246 user: TwitterUser,
247 latitude:double,
248 longitude:double,
249 created_at:string,
250 message_text:string
251 };
252
253 create dataset Tweets (Tweet)
254 primary key id;
255</pre></div></div>
256<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>
257<div class="section">
258<h5><a name="Using_the_push_twitter_feed_adapter"></a>Using the &#x201c;push_twitter&#x201d; feed adapter</h5>
259<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>
260<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>
261<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>
262
263<div class="source">
264<div class="source">
265<pre> use dataverse feeds;
266
267 create feed TwitterFeed if not exists using &quot;push_twitter&quot;
268 ((&quot;type-name&quot;=&quot;Tweet&quot;),
269 (&quot;consumer.key&quot;=&quot;************&quot;),
270 (&quot;consumer.secret&quot;=&quot;**************&quot;),
271 (&quot;access.token&quot;=&quot;**********&quot;),
272 (&quot;access.token.secret&quot;=&quot;*************&quot;));
273</pre></div></div>
274<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>
275<div class="section">
276<h4><a name="Lifecycle_of_a_Feed"></a>Lifecycle of a Feed</h4>
277<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
278feed</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>
279
280<div class="source">
281<div class="source">
282<pre> use dataverse feeds;
283
284 connect feed TwitterFeed to dataset Tweets;
285</pre></div></div>
286<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>
287<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>
288
289<div class="source">
290<div class="source">
291<pre> use dataverse feeds;
292
293 for $i in dataset Tweets limit 10 return $i;
294</pre></div></div>
295<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>
296
297<div class="source">
298<div class="source">
299<pre> use dataverse feeds;
300
301 disconnect feed TwitterFeed from dataset Tweets;
302</pre></div></div></div>
303<div class="section">
304<h4><a name="Ingesting_an_RSS_Feed"></a>Ingesting an RSS Feed</h4>
305<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>
306<div class="section">
307<h5><a name="Using_the_rss_feed_feed_adapter"></a>Using the &#x201c;rss_feed&#x201d; feed adapter</h5>
308<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>
309
310<div class="source">
311<div class="source">
312<pre> use dataverse feeds;
313
314 create type Rss if not exists as open {
315 id: string,
316 title: string,
317 description: string,
318 link: string
319 };
320
321 create dataset RssDataset (Rss)
322 primary key id;
323</pre></div></div>
324<p>Next, we define an RSS feed using our built-in adaptor &#x201c;rss_feed&#x201d;.</p>
325
326<div class="source">
327<div class="source">
328<pre> use dataverse feeds;
329
330 create feed my_feed using
331 rss_feed (
332 (&quot;type-name&quot;=&quot;Rss&quot;),
333 (&quot;url&quot;=&quot;http://rss.cnn.com/rss/edition.rss&quot;)
334 );
335</pre></div></div>
336<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>
337<p>The following statements connect the feed into the <tt>RssDataset</tt>:</p>
338
339<div class="source">
340<div class="source">
341<pre> use dataverse feeds;
342
343 connect feed my_feed to dataset RssDataset;
344</pre></div></div>
345<p>The following statements show the latest data from the data set, and disconnect the feed from the data set.</p>
346
347<div class="source">
348<div class="source">
349<pre> use dataverse feeds;
350
351 for $i in dataset RssDataset limit 10 return $i;
352
353 disconnect feed my_feed from dataset RssDataset;
354</pre></div></div>
355<p>AsterixDB also allows multiple feeds to be connected to form a cascade network to process data.</p></div></div></div></div>
356<div class="section">
357<h2><a name="Policies_for_Feed_Ingestion"></a><a name="FeedPolicies">Policies for Feed Ingestion</a></h2>
358<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>
359<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>
360<div class="section">
361<div class="section">
362<h4><a name="Policy_Parameters"></a>Policy Parameters</h4>
363
364<ul>
365
366<li>
367<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>
368
369<li>
370<p><i>excess.records.discard</i>: Set to true if excess records should be discarded. (Default: false)</p></li>
371
372<li>
373<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>
374
375<li>
376<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>
377
378<li>
379<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>
380
381<li>
382<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>
383</ul>
384<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>
385
386<div class="source">
387<div class="source">
388<pre> use dataverse feeds;
389
390 connect feed TwitterFeed to dataset Tweets
391 using policy Basic ;
392</pre></div></div></div></div></div>
393 </div>
394 </div>
395 </div>
396
397 <hr/>
398
399 <footer>
400 <div class="container-fluid">
401 <div class="row span12">Copyright &copy; 2015
402 <a href="http://www.apache.org/">The Apache Software Foundation</a>.
403 All Rights Reserved.
404
405 </div>
406
407 <?xml version="1.0" encoding="UTF-8"?>
408<div class="row-fluid">Apache AsterixDB, AsterixDB, Apache, the Apache
409 feather logo, and the Apache AsterixDB project logo are either
410 registered trademarks or trademarks of The Apache Software
411 Foundation in the United States and other countries.
412 All other marks mentioned may be trademarks or registered
413 trademarks of their respective owners.</div>
414
415
416 </div>
417 </footer>
418 </body>
419</html>