blob: b39917dbf4f109cccb943b272282a2c7c53cf30c [file] [log] [blame]
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia at 2017-09-14
| Rendered using Apache Maven Fluido Skin 1.3.0
-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="Date-Revision-yyyymmdd" content="20170914" />
<meta http-equiv="Content-Language" content="en" />
<title>AsterixDB &#x2013; Support for Data Ingestion in AsterixDB</title>
<link rel="stylesheet" href="../css/apache-maven-fluido-1.3.0.min.css" />
<link rel="stylesheet" href="../css/site.css" />
<link rel="stylesheet" href="../css/print.css" media="print" />
<script type="text/javascript" src="../js/apache-maven-fluido-1.3.0.min.js"></script>
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-41536543-1', 'uci.edu');
ga('send', 'pageview');</script>
</head>
<body class="topBarDisabled">
<div class="container-fluid">
<div id="banner">
<div class="pull-left">
<a href=".././" id="bannerLeft">
<img src="../images/asterixlogo.png" alt="AsterixDB"/>
</a>
</div>
<div class="pull-right"> </div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate">Last Published: 2017-09-14</li>
<li id="projectVersion" class="pull-right">Version: 0.9.2</li>
<li class="divider pull-right">|</li>
<li class="pull-right"> <a href="../index.html" title="Documentation Home">
Documentation Home</a>
</li>
</ul>
</div>
<div class="row-fluid">
<div id="leftColumn" class="span3">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Get Started - Installation</li>
<li>
<a href="../ncservice.html" title="Option 1: using NCService">
<i class="none"></i>
Option 1: using NCService</a>
</li>
<li>
<a href="../ansible.html" title="Option 2: using Ansible">
<i class="none"></i>
Option 2: using Ansible</a>
</li>
<li>
<a href="../aws.html" title="Option 3: using Amazon Web Services">
<i class="none"></i>
Option 3: using Amazon Web Services</a>
</li>
<li>
<a href="../yarn.html" title="Option 4: using YARN">
<i class="none"></i>
Option 4: using YARN</a>
</li>
<li>
<a href="../install.html" title="Option 5: using Managix (deprecated)">
<i class="none"></i>
Option 5: using Managix (deprecated)</a>
</li>
<li class="nav-header">AsterixDB Primer</li>
<li>
<a href="../sqlpp/primer-sqlpp.html" title="Option 1: using SQL++">
<i class="none"></i>
Option 1: using SQL++</a>
</li>
<li>
<a href="../aql/primer.html" title="Option 2: using AQL">
<i class="none"></i>
Option 2: using AQL</a>
</li>
<li class="nav-header">Data Model</li>
<li>
<a href="../datamodel.html" title="The Asterix Data Model">
<i class="none"></i>
The Asterix Data Model</a>
</li>
<li class="nav-header">Queries - SQL++</li>
<li>
<a href="../sqlpp/manual.html" title="The SQL++ Query Language">
<i class="none"></i>
The SQL++ Query Language</a>
</li>
<li>
<a href="../sqlpp/builtins.html" title="Builtin Functions">
<i class="none"></i>
Builtin Functions</a>
</li>
<li class="nav-header">Queries - AQL</li>
<li>
<a href="../aql/manual.html" title="The Asterix Query Language (AQL)">
<i class="none"></i>
The Asterix Query Language (AQL)</a>
</li>
<li>
<a href="../aql/builtins.html" title="Builtin Functions">
<i class="none"></i>
Builtin Functions</a>
</li>
<li class="nav-header">API/SDK</li>
<li>
<a href="../api.html" title="HTTP API">
<i class="none"></i>
HTTP API</a>
</li>
<li>
<a href="../csv.html" title="CSV Output">
<i class="none"></i>
CSV Output</a>
</li>
<li class="nav-header">Advanced Features</li>
<li>
<a href="../aql/fulltext.html" title="Support of Full-text Queries">
<i class="none"></i>
Support of Full-text Queries</a>
</li>
<li>
<a href="../aql/externaldata.html" title="Accessing External Data">
<i class="none"></i>
Accessing External Data</a>
</li>
<li class="active">
<a href="#"><i class="none"></i>Support for Data Ingestion</a>
</li>
<li>
<a href="../udf.html" title="User Defined Functions">
<i class="none"></i>
User Defined Functions</a>
</li>
<li>
<a href="../aql/filters.html" title="Filter-Based LSM Index Acceleration">
<i class="none"></i>
Filter-Based LSM Index Acceleration</a>
</li>
<li>
<a href="../aql/similarity.html" title="Support of Similarity Queries">
<i class="none"></i>
Support of Similarity Queries</a>
</li>
</ul>
<hr class="divider" />
<div id="poweredBy">
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<a href=".././" title="AsterixDB" class="builtBy">
<img class="builtBy" alt="AsterixDB" src="../images/asterixlogo.png" />
</a>
</div>
</div>
</div>
<div id="bodyColumn" class="span9" >
<!-- ! Licensed to the Apache Software Foundation (ASF) under one
! or more contributor license agreements. See the NOTICE file
! distributed with this work for additional information
! regarding copyright ownership. The ASF licenses this file
! to you under the Apache License, Version 2.0 (the
! "License"); you may not use this file except in compliance
! with the License. You may obtain a copy of the License at
!
! http://www.apache.org/licenses/LICENSE-2.0
!
! Unless required by applicable law or agreed to in writing,
! software distributed under the License is distributed on an
! "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
! KIND, either express or implied. See the License for the
! specific language governing permissions and limitations
! under the License.
! --><h1>Support for Data Ingestion in AsterixDB</h1>
<div class="section">
<h2><a name="Table_of_Contents"></a><a name="atoc" id="#toc">Table of Contents</a></h2>
<ul>
<li><a href="#Introduction">Introduction</a></li>
<li><a href="#FeedAdapters">Feed Adapters</a> <!-- * [Feed Policies](#FeedPolicies) --></li>
</ul></div>
<div class="section">
<h2><a name="Introduction">Introduction</a></h2>
<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>
<div class="section">
<h2><a name="Feed_Adapters"></a><a name="FeedAdapters">Feed Adapters</a></h2>
<p>The functionality of establishing a connection with a data source and receiving, parsing and translating its data into ADM objects (for storage inside AsterixDB) is contained in a feed adapter. A feed adapter is an implementation of an interface and its details are specific to a given data source. An adapter may optionally be given parameters to configure its runtime behavior. Depending upon the data transfer protocol/APIs offered by the data source, a feed adapter may operate in a push or a pull mode. Push mode involves just one initial request by the adapter to the data source for setting up the connection. Once a connection is authorized, the data source &#x201c;pushes&#x201d; data to the adapter without any subsequent requests by the adapter. In contrast, when operating in a pull mode, the adapter makes a separate request each time to receive data. AsterixDB currently provides built-in adapters for several popular data sources such as Twitter and RSS feeds. AsterixDB additionally provides a generic socket-based adapter that can be used to ingest data that is directed at a prescribed socket.</p>
<p>In this tutorial, we shall describe building two example data ingestion pipelines that cover the popular scenarios of ingesting data from (a) Twitter (b) RSS (c) Socket Feed source.</p>
<div class="section">
<div class="section">
<h4><a name="Ingesting_Twitter_Stream"></a>Ingesting Twitter Stream</h4>
<p>We shall use the built-in push-based Twitter adapter. 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 definitions in AQL that create a Tweet datatype which is representative of a real tweet as obtained from Twitter.</p>
<div class="source">
<div class="source">
<pre> create dataverse feeds;
use dataverse feeds;
create type TwitterUser as closed {
screen_name: string,
lang: string,
friends_count: int32,
statuses_count: int32
};
create type Tweet as open {
id: int64,
user: TwitterUser
}
create dataset Tweets (Tweet)
primary key id;
</pre></div></div>
<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>
<div class="section">
<h5><a name="Using_the_push_twitter_feed_adapter"></a>Using the &#x201c;push_twitter&#x201d; feed adapter</h5>
<p>The &#x201c;push_twitter&#x201d; adapter requires setting up an application account with Twitter. To retrieve tweets, Twitter requires registering an application. Registration involves providing a name and a brief description for the application. Each application has associated OAuth authentication credentials that include 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>
<p>The &#x201c;push_twitter&#x201d; adapter 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; adapter. 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>
<p>Given below is an example AQL statement that creates a feed called &#x201c;TwitterFeed&#x201d; by using the &#x201c;push_twitter&#x201d; adapter.</p>
<div class="source">
<div class="source">
<pre> use dataverse feeds;
create feed TwitterFeed if not exists using &quot;push_twitter&quot;
((&quot;type-name&quot;=&quot;Tweet&quot;),
(&quot;format&quot;=&quot;twitter-status&quot;),
(&quot;consumer.key&quot;=&quot;************&quot;),
(&quot;consumer.secret&quot;=&quot;**************&quot;),
(&quot;access.token&quot;=&quot;**********&quot;),
(&quot;access.token.secret&quot;=&quot;*************&quot;));
</pre></div></div>
<p>It is required that the above authentication parameters are provided valid. Note that the <tt>create feed</tt> statement does not initiate the flow of data from Twitter into the AsterixDB instance. Instead, the <tt>create feed</tt> statement only results in registering the feed with the instance. The flow of data along a feed is initiated when it is connected to a target dataset using the connect feed statement and activated using the start feed statement.</p>
<p>The Twitter adapter also supports several Twitter streaming APIs as follow:</p>
<ol style="list-style-type: decimal">
<li>Track filter (&#x201c;keywords&#x201d;=&#x201c;AsterixDB, Apache&#x201d;)</li>
<li>Locations filter (&#x201c;locations&#x201d;=&#x201c;-29.7, 79.2, 36.7, 72.0; -124.848974,-66.885444, 24.396308, 49.384358&#x201d;)</li>
<li>Language filter (&#x201c;language&#x201d;=&#x201c;en&#x201d;)</li>
<li>Filter level (&#x201c;filter-level&#x201d;=&#x201c;low&#x201d;)</li>
</ol>
<p>An example of Twitter adapter tracking tweets with keyword &#x201c;news&#x201d; can be described using following ddl:</p>
<div class="source">
<div class="source">
<pre> use dataverse feeds;
create feed TwitterFeed if not exists using &quot;push_twitter&quot;
((&quot;type-name&quot;=&quot;Tweet&quot;),
(&quot;format&quot;=&quot;twitter-status&quot;),
(&quot;consumer.key&quot;=&quot;************&quot;),
(&quot;consumer.secret&quot;=&quot;**************&quot;),
(&quot;access.token&quot;=&quot;**********&quot;),
(&quot;access.token.secret&quot;=&quot;*************&quot;),
(&quot;keywords&quot;=&quot;news&quot;));
</pre></div></div>
<p>For more details about these APIs, please visit <a class="externalLink" href="https://dev.twitter.com/streaming/overview/request-parameters">https://dev.twitter.com/streaming/overview/request-parameters</a></p></div></div>
<div class="section">
<h4><a name="Lifecycle_of_a_Feed"></a>Lifecycle of a Feed</h4>
<p>A feed is a logical artifact that is brought to life (i.e., its data flow is initiated) only when it is activated using the <tt>start feed</tt> statement. Before we active a feed, we need to designate the dataset where the data to be persisted using <tt>connect feed</tt> statement. Subsequent to a <tt>connect feed</tt> statement, the feed is said to be in the connected state. After that, <tt>start feed</tt> statement will activate the feed, and start the dataflow from feed to its connected dataset. Multiple feeds can simultaneously be connected to a dataset such that the contents of the dataset represent the union of the connected feeds. Also one feed can be simultaneously connected to multiple target datasets.</p>
<div class="source">
<div class="source">
<pre> use dataverse feeds;
connect feed TwitterFeed to dataset Tweets;
start feed TwitterFeed;
</pre></div></div>
<p>The <tt>connect feed</tt> statement above directs AsterixDB to persist the data from <tt>TwitterFeed</tt> feed into the <tt>Tweets</tt> dataset. The <tt>start feed</tt> statement will activate the feed and start the dataflow. 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>
<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>
<div class="source">
<div class="source">
<pre> use dataverse feeds;
for $i in dataset Tweets limit 10 return $i;
</pre></div></div>
<p>The dataflow of data from a feed can be terminated explicitly by <tt>stop feed</tt> statement.</p>
<div class="source">
<div class="source">
<pre> use dataverse feeds;
stop feed TwitterFeed;
</pre></div></div>
<p>The <tt>disconnnect statement</tt> can be used to disconnect the feed from certain dataset.</p>
<div class="source">
<div class="source">
<pre> use dataverse feeds;
disconnect feed TwitterFeed from dataset Tweets;
</pre></div></div></div></div>
<div class="section">
<h3><a name="Ingesting_with_Other_Adapters"></a>Ingesting with Other Adapters</h3>
<p>AsterixDB has several builtin feed adapters for data ingestion. User can also implement their own adapters and plug them into AsterixDB. Here we introduce <tt>rss_feed</tt>, <tt>socket_adapter</tt> and <tt>localfs</tt> feed adapter that cover most of the common application scenarios.</p>
<div class="section">
<div class="section">
<h5><a name="Using_the_rss_feed_feed_adapter"></a>Using the &#x201c;rss_feed&#x201d; feed adapter</h5>
<p><tt>rss_feed</tt> adapter 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>
<div class="source">
<div class="source">
<pre> use dataverse feeds;
create type Rss if not exists as open {
id: string,
title: string,
description: string,
link: string
};
create dataset RssDataset (Rss)
primary key id;
</pre></div></div>
<p>Next, we define an RSS feed using our built-in adapter &#x201c;rss_feed&#x201d;.</p>
<div class="source">
<div class="source">
<pre> use dataverse feeds;
create feed my_feed using
rss_feed (
(&quot;type-name&quot;=&quot;Rss&quot;),
(&quot;format&quot;=&quot;rss&quot;),
(&quot;url&quot;=&quot;http://rss.cnn.com/rss/edition.rss&quot;)
);
</pre></div></div>
<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 an RSS feed. The &#x201c;rss_feed&#x201d; retrieves data from each of the specified RSS URLs (comma separated values) in parallel.</p>
<p>The following statements connect the feed into the <tt>RssDataset</tt>:</p>
<div class="source">
<div class="source">
<pre> use dataverse feeds;
connect feed my_feed to dataset RssDataset;
</pre></div></div>
<p>The following statements activate the feed and start the dataflow:</p>
<div class="source">
<div class="source">
<pre> use dataverse feeds;
start feed my_feed;
</pre></div></div>
<p>The following statements show the latest data from the data set, stop the feed, and disconnect the feed from the data set.</p>
<div class="source">
<div class="source">
<pre> use dataverse feeds;
for $i in dataset RssDataset limit 10 return $i;
stop feed my_feed
disconnect feed my_feed from dataset RssDataset;
</pre></div></div></div>
<div class="section">
<h5><a name="Using_the_socket_adapter_feed_adapter"></a>Using the &#x201c;socket_adapter&#x201d; feed adapter</h5>
<p><tt>socket_adapter</tt> feed opens a web socket on the given node which allows user to push data into AsterixDB directly. Here is an example:</p>
<div class="source">
<div class="source">
<pre> drop dataverse feeds if exists;
create dataverse feeds;
use dataverse feeds;
create type TestDataType as open {
screenName: string
}
create dataset TestDataset(TestDataType) primary key screenName;
create feed TestSocketFeed using socket_adapter
(
(&quot;sockets&quot;=&quot;127.0.0.1:10001&quot;),
(&quot;address-type&quot;=&quot;IP&quot;),
(&quot;type-name&quot;=&quot;TestDataType&quot;),
(&quot;format&quot;=&quot;adm&quot;)
);
connect feed TestSocketFeed to dataset TestDataset;
use dataverse feeds;
start feed TestSocketFeed;
</pre></div></div>
<p>The above statements create a socket feed which is listening to &#x201c;10001&#x201d; port of the host machine. This feed accepts data records in &#x201c;adm&#x201d; format. As an example, you can download the sample dataset <a href="../data/chu.adm">Chirp Users</a> and push them line by line into the socket feed using any socket client you like. Following is a socket client example in Python:</p>
<div class="source">
<div class="source">
<pre> from socket import socket
ip = '127.0.0.1'
port1 = 10001
filePath = 'chu.adm'
sock1 = socket()
sock1.connect((ip, port1))
with open(filePath) as inputData:
for line in inputData:
sock1.sendall(line)
sock1.close()
</pre></div></div></div></div>
<div class="section">
<h4><a name="Using_the_localfs_feed_adapter"></a>Using the &#x201c;localfs&#x201d; feed adapter</h4>
<p><tt>localfs</tt> adapter enables data ingestion from local file system. It allows user to feed data records on local disk into a dataset. A DDL example for creating a <tt>localfs</tt> feed is given as follow:</p>
<div class="source">
<div class="source">
<pre> use dataverse feeds;
create type TweetType as closed {
id: string,
username : string,
location : string,
text : string,
timestamp : string
}
create dataset Tweets(TweetType)
primary key id;
create feed TweetFeed
using localfs
((&quot;type-name&quot;=&quot;TweetType&quot;),(&quot;path&quot;=&quot;HOSTNAME://LOCAL_FILE_PATH&quot;),(&quot;format&quot;=&quot;adm&quot;))
</pre></div></div>
<p>Similar to previous examples, we need to define the datatype and dataset this feed uses. The &#x201c;path&#x201d; parameter refers to the local datafile that we want to ingest data from. <tt>HOSTNAME</tt> can either be the IP address or node name of the machine which holds the file. <tt>LOCAL_FILE_PATH</tt> indicates the absolute path to the file on that machine. Similarly to <tt>socket_adapter</tt>, this feed takes <tt>adm</tt> formatted data records.</p></div></div>
<div class="section">
<h3><a name="Datatype_for_feed_and_target_dataset"></a>Datatype for feed and target dataset</h3>
<p>The &#x201c;type-name&#x201d; parameter in create feed statement defines the <tt>datatype</tt> of the datasource. In most use cases, feed will have the same <tt>datatype</tt> as the target dataset. However, if we want to perform certain preprocess before the data records gets into the target dataset (append autogenerated key, apply user defined functions, etc.), we will need to define the datatypes for feed and dataset separately.</p>
<div class="section">
<h4><a name="Ingestion_with_autogenerated_key"></a>Ingestion with autogenerated key</h4>
<p>AsterixDB supports using autogenerated uuid as the primary key for dataset. When we use this feature, we will need to define a datatype with the primary key field, and specify that field to be autogenerated when creating the dataset. Use that same datatype in feed definition will cause a type discrepancy since there is no such field in the datasource. Thus, we will need to define two separate datatypes for feed and dataset:</p>
<div class="source">
<div class="source">
<pre> use dataverse feeds;
create type DBLPFeedType as closed {
dblpid: string,
title: string,
authors: string,
misc: string
}
create type DBLPDataSetType as open {
id: uuid,
dblpid: string,
title: string,
authors: string,
misc: string
}
create dataset DBLPDataset(DBLPDataSetType) primary key id autogenerated;
create feed DBLPFeed using socket_adapter
(
(&quot;sockets&quot;=&quot;127.0.0.1:10001&quot;),
(&quot;address-type&quot;=&quot;IP&quot;),
(&quot;type-name&quot;=&quot;DBLPFeedType&quot;),
(&quot;format&quot;=&quot;adm&quot;)
);
connect feed DBLPFeed to dataset DBLPDataset;
start feed DBLPFeed;
</pre></div></div></div></div></div>
<div class="section">
<h2><a name="Policies_for_Feed_Ingestion"></a><a name="FeedPolicies">Policies for Feed Ingestion</a></h2>
<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>
<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 set of policies that help customize the system&#x2019;s runtime behavior when handling excess objects.</p>
<div class="section">
<div class="section">
<h4><a name="Policies"></a>Policies</h4>
<ul>
<li>
<p><i>Spill</i>: Objects that cannot be processed by an operator for lack of resources (referred to as excess objects hereafter) should be persisted to the local disk for deferred processing.</p></li>
<li>
<p><i>Discard</i>: Excess objects should be discarded.</p></li>
</ul>
<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 objects 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.</p>
<div class="source">
<div class="source">
<pre> use dataverse feeds;
connect feed TwitterFeed to dataset Tweets
using policy Basic;
</pre></div></div></div></div></div>
</div>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row span12">Copyright &copy; 2017
<a href="https://www.apache.org/">The Apache Software Foundation</a>.
All Rights Reserved.
</div>
<?xml version="1.0" encoding="UTF-8"?>
<div class="row-fluid">Apache AsterixDB, AsterixDB, Apache, the Apache
feather logo, and the Apache AsterixDB project logo are either
registered trademarks or trademarks of The Apache Software
Foundation in the United States and other countries.
All other marks mentioned may be trademarks or registered
trademarks of their respective owners.</div>
</div>
</footer>
</body>
</html>