blob: 6c1e8f34fb6871f992b1592a0f13e7ee9d0d6fa1 [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
22<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
23 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
24 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
25 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
26
27 ga('create', 'UA-41536543-1', 'uci.edu');
28 ga('send', 'pageview');</script>
29
30 </head>
31 <body class="topBarDisabled">
32
33
34
35
36 <div class="container-fluid">
37 <div id="banner">
38 <div class="pull-left">
39 <a href="http://asterixdb.apache.org/" id="bannerLeft">
40 <img src="../images/asterixlogo.png" alt="AsterixDB"/>
41 </a>
42 </div>
43 <div class="pull-right"> </div>
44 <div class="clear"><hr/></div>
45 </div>
46
47 <div id="breadcrumbs">
48 <ul class="breadcrumb">
49
50
51 <li id="publishDate">Last Published: 2016-03-25</li>
52
53
54
55 <li id="projectVersion" class="pull-right">Version: 0.8.8-incubating</li>
56
57 <li class="divider pull-right">|</li>
58
59 <li class="pull-right"> <a href="../index.html" title="Documentation Home">
60 Documentation Home</a>
61 </li>
62
63 </ul>
64 </div>
65
66
67 <div class="row-fluid">
68 <div id="leftColumn" class="span3">
69 <div class="well sidebar-nav">
70
71
72 <ul class="nav nav-list">
73 <li class="nav-header">Documentation</li>
74
75 <li>
76
77 <a href="../install.html" title="Installing and Managing AsterixDB using Managix">
78 <i class="none"></i>
79 Installing and Managing AsterixDB using Managix</a>
80 </li>
81
82 <li>
83
84 <a href="../yarn.html" title="Deploying AsterixDB using YARN">
85 <i class="none"></i>
86 Deploying AsterixDB using YARN</a>
87 </li>
88
89 <li>
90
91 <a href="../aql/primer.html" title="AsterixDB 101: An ADM and AQL Primer">
92 <i class="none"></i>
93 AsterixDB 101: An ADM and AQL Primer</a>
94 </li>
95
96 <li>
97
98 <a href="../aql/primer-sql-like.html" title="AsterixDB 101: An ADM and AQL Primer (For SQL Fans)">
99 <i class="none"></i>
100 AsterixDB 101: An ADM and AQL Primer (For SQL Fans)</a>
101 </li>
102
103 <li>
104
Yingyi Bu08953b22016-03-25 15:23:26 -0700105 <a href="../aql/datamodel.html" title="Asterix Data Model (ADM)">
106 <i class="none"></i>
107 Asterix Data Model (ADM)</a>
108 </li>
109
110 <li>
111
112 <a href="../aql/manual.html" title="Asterix Query Language (AQL)">
113 <i class="none"></i>
114 Asterix Query Language (AQL)</a>
115 </li>
116
117 <li>
118
119 <a href="../aql/functions.html" title="AQL Functions">
120 <i class="none"></i>
121 AQL Functions</a>
122 </li>
123
124 <li>
125
126 <a href="../aql/allens.html" title="AQL Allen's Relations Functions">
127 <i class="none"></i>
128 AQL Allen's Relations Functions</a>
129 </li>
130
131 <li>
132
133 <a href="../aql/similarity.html" title="AQL Support of Similarity Queries">
134 <i class="none"></i>
135 AQL Support of Similarity Queries</a>
136 </li>
137
138 <li>
139
140 <a href="../aql/externaldata.html" title="Accessing External Data">
141 <i class="none"></i>
142 Accessing External Data</a>
143 </li>
144
145 <li class="active">
146
147 <a href="#"><i class="none"></i>Support for Data Ingestion in AsterixDB</a>
148 </li>
149
150 <li>
151
152 <a href="../udf.html" title="Support for User Defined Functions in AsterixDB">
153 <i class="none"></i>
154 Support for User Defined Functions in AsterixDB</a>
155 </li>
156
157 <li>
158
159 <a href="../aql/filters.html" title="Filter-Based LSM Index Acceleration">
160 <i class="none"></i>
161 Filter-Based LSM Index Acceleration</a>
162 </li>
163
164 <li>
165
166 <a href="../api.html" title="HTTP API to AsterixDB">
167 <i class="none"></i>
168 HTTP API to AsterixDB</a>
169 </li>
170 </ul>
171
172
173
174 <hr class="divider" />
175
176 <div id="poweredBy">
177 <div class="clear"></div>
178 <div class="clear"></div>
179 <div class="clear"></div>
180 <a href="https://code.google.com/p/hyracks/" title="Hyracks" class="builtBy">
181 <img class="builtBy" alt="Hyracks" src="../images/hyrax_ts.png" />
182 </a>
183 </div>
184 </div>
185 </div>
186
187
188 <div id="bodyColumn" class="span9" >
189
190 <!-- ! Licensed to the Apache Software Foundation (ASF) under one
191 ! or more contributor license agreements. See the NOTICE file
192 ! distributed with this work for additional information
193 ! regarding copyright ownership. The ASF licenses this file
194 ! to you under the Apache License, Version 2.0 (the
195 ! "License"); you may not use this file except in compliance
196 ! with the License. You may obtain a copy of the License at
197 !
198 ! http://www.apache.org/licenses/LICENSE-2.0
199 !
200 ! Unless required by applicable law or agreed to in writing,
201 ! software distributed under the License is distributed on an
202 ! "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
203 ! KIND, either express or implied. See the License for the
204 ! specific language governing permissions and limitations
205 ! under the License.
206 ! --><h1>Support for Data Ingestion in AsterixDB</h1>
207<div class="section">
208<h2><a name="Table_of_Contents"></a><a name="atoc" id="#toc">Table of Contents</a></h2>
209
210<ul>
211
212<li><a href="#Introduction">Introduction</a></li>
213
214<li><a href="#FeedAdaptors">Feed Adaptors</a></li>
215
216<li><a href="#FeedPolicies">Feed Policies</a></li>
217</ul></div>
218<div class="section">
219<h2><a name="Introduction">Introduction</a></h2>
220<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>
221<div class="section">
222<h2><a name="Feed_Adaptors"></a><a name="FeedAdaptors">Feed Adaptors</a></h2>
223<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>
224<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>
225<div class="section">
226<div class="section">
227<h4><a name="Ingesting_Twitter_Stream"></a>Ingesting Twitter Stream</h4>
228<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>
229
230<div class="source">
231<div class="source">
232<pre> create dataverse feeds;
233 use dataverse feeds;
234
235 create type TwitterUser if not exists as open{
236 screen_name: string,
237 language: string,
238 friends_count: int32,
239 status_count: int32,
240 name: string,
241 followers_count: int32
242 };
243 create type Tweet if not exists as open{
244 id: string,
245 user: TwitterUser,
246 latitude:double,
247 longitude:double,
248 created_at:string,
249 message_text:string
250 };
251
252 create dataset Tweets (Tweet)
253 primary key id;
254</pre></div></div>
255<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>
256<div class="section">
257<h5><a name="Using_the_push_twitter_feed_adapter"></a>Using the &#x201c;push_twitter&#x201d; feed adapter</h5>
258<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>
259<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>
260<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>
261
262<div class="source">
263<div class="source">
264<pre> use dataverse feeds;
265
266 create feed TwitterFeed if not exists using &quot;push_twitter&quot;
267 ((&quot;type-name&quot;=&quot;Tweet&quot;),
268 (&quot;consumer.key&quot;=&quot;************&quot;),
269 (&quot;consumer.secret&quot;=&quot;**************&quot;),
270 (&quot;access.token&quot;=&quot;**********&quot;),
271 (&quot;access.token.secret&quot;=&quot;*************&quot;));
272</pre></div></div>
273<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>
274<div class="section">
275<h4><a name="Lifecycle_of_a_Feed"></a>Lifecycle of a Feed</h4>
276<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
277feed</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>
278
279<div class="source">
280<div class="source">
281<pre> use dataverse feeds;
282
283 connect feed TwitterFeed to dataset Tweets;
284</pre></div></div>
285<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>
286<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>
287
288<div class="source">
289<div class="source">
290<pre> use dataverse feeds;
291
292 for $i in dataset Tweets limit 10 return $i;
293</pre></div></div>
294<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>
295
296<div class="source">
297<div class="source">
298<pre> use dataverse feeds;
299
300 disconnect feed TwitterFeed from dataset Tweets;
301</pre></div></div></div>
302<div class="section">
303<h4><a name="Ingesting_an_RSS_Feed"></a>Ingesting an RSS Feed</h4>
304<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>
305<div class="section">
306<h5><a name="Using_the_rss_feed_feed_adapter"></a>Using the &#x201c;rss_feed&#x201d; feed adapter</h5>
307<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>
308
309<div class="source">
310<div class="source">
311<pre> use dataverse feeds;
312
313 create type Rss if not exists as open {
314 id: string,
315 title: string,
316 description: string,
317 link: string
318 };
319
320 create dataset RssDataset (Rss)
321 primary key id;
322</pre></div></div>
323<p>Next, we define an RSS feed using our built-in adaptor &#x201c;rss_feed&#x201d;.</p>
324
325<div class="source">
326<div class="source">
327<pre> use dataverse feeds;
328
329 create feed my_feed using
330 rss_feed (
331 (&quot;type-name&quot;=&quot;Rss&quot;),
332 (&quot;url&quot;=&quot;http://rss.cnn.com/rss/edition.rss&quot;)
333 );
334</pre></div></div>
335<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>
336<p>The following statements connect the feed into the <tt>RssDataset</tt>:</p>
337
338<div class="source">
339<div class="source">
340<pre> use dataverse feeds;
341
342 connect feed my_feed to dataset RssDataset;
343</pre></div></div>
344<p>The following statements show the latest data from the data set, and disconnect the feed from the data set.</p>
345
346<div class="source">
347<div class="source">
348<pre> use dataverse feeds;
349
350 for $i in dataset RssDataset limit 10 return $i;
351
352 disconnect feed my_feed from dataset RssDataset;
353</pre></div></div>
354<p>AsterixDB also allows multiple feeds to be connected to form a cascade network to process data.</p></div></div></div></div>
355<div class="section">
356<h2><a name="Policies_for_Feed_Ingestion"></a><a name="FeedPolicies">Policies for Feed Ingestion</a></h2>
357<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>
358<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>
359<div class="section">
360<div class="section">
361<h4><a name="Policy_Parameters"></a>Policy Parameters</h4>
362
363<ul>
364
365<li>
366<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>
367
368<li>
369<p><i>excess.records.discard</i>: Set to true if excess records should be discarded. (Default: false)</p></li>
370
371<li>
372<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>
373
374<li>
375<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>
376
377<li>
378<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>
379
380<li>
381<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>
382</ul>
383<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>
384
385<div class="source">
386<div class="source">
387<pre> use dataverse feeds;
388
389 connect feed TwitterFeed to dataset Tweets
390 using policy Basic ;
391</pre></div></div></div></div></div>
392 </div>
393 </div>
394 </div>
395
396 <hr/>
397
398 <footer>
399 <div class="container-fluid">
400 <div class="row span12">Copyright &copy; 2016
401 <a href="http://www.apache.org/">The Apache Software Foundation</a>.
402 All Rights Reserved.
403
404 </div>
405
406 <?xml version="1.0" encoding="UTF-8"?>
407<div class="row-fluid">Apache AsterixDB, AsterixDB, Apache, the Apache
408 feather logo, and the Apache AsterixDB project logo are either
409 registered trademarks or trademarks of The Apache Software
410 Foundation in the United States and other countries.
411 All other marks mentioned may be trademarks or registered
412 trademarks of their respective owners.</div>
413
414
415 </div>
416 </footer>
417 </body>
418</html>