Update site for release
Change-Id: I8aa5dce0b9a9c51df2fcafa91d2e4f47d9fa4cf3
Reviewed-on: https://asterix-gerrit.ics.uci.edu/3254
Reviewed-by: Ian Maxon <imaxon@uci.edu>
diff --git a/content/docs/0.9.4/udf.html b/content/docs/0.9.4/udf.html
index 65bc7bb..e5816d4 100644
--- a/content/docs/0.9.4/udf.html
+++ b/content/docs/0.9.4/udf.html
@@ -1,15 +1,15 @@
<!DOCTYPE html>
<!--
- | Generated by Apache Maven Doxia Site Renderer 1.8.1 from target/generated-site/markdown/udf.md at 2018-10-12
+ | Generated by Apache Maven Doxia Site Renderer 1.8.1 from src/site/markdown/udf.md at 2019-03-07
| Rendered using Apache Maven Fluido Skin 1.7
-->
<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="20181012" />
+ <meta name="Date-Revision-yyyymmdd" content="20190307" />
<meta http-equiv="Content-Language" content="en" />
- <title>AsterixDB – User-defined Functions</title>
+ <title>AsterixDB – Support for User Defined Functions in AsterixDB</title>
<link rel="stylesheet" href="./css/apache-maven-fluido-1.7.min.css" />
<link rel="stylesheet" href="./css/site.css" />
<link rel="stylesheet" href="./css/print.css" media="print" />
@@ -26,7 +26,7 @@
<div id="breadcrumbs">
<ul class="breadcrumb">
- <li id="publishDate">Last Published: 2018-10-12</li>
+ <li id="publishDate">Last Published: 2019-03-07</li>
<li id="projectVersion" class="pull-right">Version: 0.9.4</li>
<li class="pull-right"><a href="index.html" title="Documentation Home">Documentation Home</a></li>
</ul>
@@ -40,26 +40,26 @@
<li><a href="ansible.html" title="Option 2: using Ansible"><span class="none"></span>Option 2: using Ansible</a></li>
<li><a href="aws.html" title="Option 3: using Amazon Web Services"><span class="none"></span>Option 3: using Amazon Web Services</a></li>
<li class="nav-header">AsterixDB Primer</li>
- <li><a href="sqlpp/primer-sqlpp.html" title="Using SQL++"><span class="none"></span>Using SQL++</a></li>
+ <li><a href="sqlpp/primer-sqlpp.html" title="Option 1: using SQL++"><span class="none"></span>Option 1: using SQL++</a></li>
+ <li><a href="aql/primer.html" title="Option 2: using AQL"><span class="none"></span>Option 2: using AQL</a></li>
<li class="nav-header">Data Model</li>
<li><a href="datamodel.html" title="The Asterix Data Model"><span class="none"></span>The Asterix Data Model</a></li>
- <li class="nav-header">Queries</li>
+ <li class="nav-header">Queries - SQL++</li>
<li><a href="sqlpp/manual.html" title="The SQL++ Query Language"><span class="none"></span>The SQL++ Query Language</a></li>
<li><a href="sqlpp/builtins.html" title="Builtin Functions"><span class="none"></span>Builtin Functions</a></li>
+ <li class="nav-header">Queries - AQL</li>
+ <li><a href="aql/manual.html" title="The Asterix Query Language (AQL)"><span class="none"></span>The Asterix Query Language (AQL)</a></li>
+ <li><a href="aql/builtins.html" title="Builtin Functions"><span class="none"></span>Builtin Functions</a></li>
<li class="nav-header">API/SDK</li>
<li><a href="api.html" title="HTTP API"><span class="none"></span>HTTP API</a></li>
<li><a href="csv.html" title="CSV Output"><span class="none"></span>CSV Output</a></li>
<li class="nav-header">Advanced Features</li>
+ <li><a href="aql/fulltext.html" title="Support of Full-text Queries"><span class="none"></span>Support of Full-text Queries</a></li>
<li><a href="aql/externaldata.html" title="Accessing External Data"><span class="none"></span>Accessing External Data</a></li>
- <li><a href="feeds.html" title="Data Ingestion with Feeds"><span class="none"></span>Data Ingestion with Feeds</a></li>
+ <li><a href="feeds/tutorial.html" title="Support for Data Ingestion"><span class="none"></span>Support for Data Ingestion</a></li>
<li class="active"><a href="#"><span class="none"></span>User Defined Functions</a></li>
- <li><a href="sqlpp/filters.html" title="Filter-Based LSM Index Acceleration"><span class="none"></span>Filter-Based LSM Index Acceleration</a></li>
- <li><a href="sqlpp/fulltext.html" title="Support of Full-text Queries"><span class="none"></span>Support of Full-text Queries</a></li>
- <li><a href="sqlpp/similarity.html" title="Support of Similarity Queries"><span class="none"></span>Support of Similarity Queries</a></li>
- <li class="nav-header">Deprecated</li>
- <li><a href="aql/primer.html" title="AsterixDB Primer: Using AQL"><span class="none"></span>AsterixDB Primer: Using AQL</a></li>
- <li><a href="aql/manual.html" title="Queries: The Asterix Query Language (AQL)"><span class="none"></span>Queries: The Asterix Query Language (AQL)</a></li>
- <li><a href="aql/builtins.html" title="Queries: Builtin Functions (AQL)"><span class="none"></span>Queries: Builtin Functions (AQL)</a></li>
+ <li><a href="aql/filters.html" title="Filter-Based LSM Index Acceleration"><span class="none"></span>Filter-Based LSM Index Acceleration</a></li>
+ <li><a href="aql/similarity.html" title="Support of Similarity Queries"><span class="none"></span>Support of Similarity Queries</a></li>
</ul>
<hr />
<div id="poweredBy">
@@ -90,173 +90,160 @@
! specific language governing permissions and limitations
! under the License.
!-->
-<h1>User-defined Functions</h1>
+<h1>Support for User Defined Functions 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="#installingUDF">Installing an UDF Library</a></li>
-<li><a href="#UDFOnFeeds">Attaching an UDF on Data Feeds</a></li>
-<li><a href="#udfConfiguration">A quick look of the UDF configuration</a></li>
-<li><a href="#uninstall">Unstalling an UDF Library</a><!--
-! 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.
-!--></li>
-</ul></div>
+<li><a href="#PreprocessingCollectedData">Using UDF to preprocess feed-collected data</a></li>
+<li><a href="#WritingAnExternalUDF">Writing an External UDF</a></li>
+<li><a href="#CreatingAnAsterixDBLibrary">Creating an AsterixDB Library</a></li>
+<li><a href="#installingUDF">Installing an AsterixDB Library</a></li>
+</ul>
+<p>In this document, we describe the support for implementing, using, and installing user-defined functions (UDF) in AsterixDB. We will explain how we can use UDFs to preprocess, e.g., data collected using feeds (see the <a href="feeds/tutorial.html">feeds tutorial</a>).</p>
<div class="section">
-<h2><a name="Introduction"></a><a name="introduction">Introduction</a></h2>
-<p>Apache AsterixDB supports two languages for writing user-defined functions (UDFs): SQL++ and Java. A user can encapsulate data processing logic into a UDF and invoke it later repeatedly. For SQL++ functions, a user can refer to <a href="sqlpp/manual.html#Functions">SQL++ Functions</a> for their usages. In this document, we focus on how to install/invoke/uninstall a Java function library using the Ansible script that we provide.</p></div>
-<div class="section">
-<h2><a name="Installing_an_UDF_Library"></a><a name="installingUDF">Installing an UDF Library</a></h2>
-<p>UDFs have to be installed offline. This section describes the process assuming that you have followed the preceding <a href="ansible.html">ansible installation instructions</a> to deploy an AsterixDB instance on your local machine or cluster. Here are the instructions to install an UDF library:</p>
+<h3><a name="Installing_an_AsterixDB_Library"></a><a name="installingUDF">Installing an AsterixDB Library</a></h3>
+<p>We assume you have followed the <a href="../install.html">installation instructions</a> to set up a running AsterixDB instance. Let us refer your AsterixDB instance by the name “my_asterix”.</p>
<ul>
<li>
-<p>Step 1: Stop the AsterixDB instance if it is ACTIVE.</p>
+<p>Step 1: Stop the AsterixDB instance if it is in the ACTIVE state.</p>
<div>
<div>
-<pre class="source">$ bin/stop.sh
+<pre class="source">$ managix stop -n my_asterix
</pre></div></div>
</li>
<li>
-<p>Step 2: Deploy the UDF package.</p>
+<p>Step 2: Install the library using Managix install command. Just to illustrate, we use the help command to look up the syntax</p>
<div>
<div>
-<pre class="source">$ bin/udf.sh -m i -d DATAVERSE_NAME -l LIBRARY_NAME -p UDF_PACKAGE_PATH
-</pre></div></div>
-</li>
-<li>
-
-<p>Step 3: Start AsterixDB</p>
-
-<div>
-<div>
-<pre class="source">$ bin/start.sh
+<pre class="source">$ managix help -cmd install
+Installs a library to an asterix instance.
+Options
+n Name of Asterix Instance
+d Name of the dataverse under which the library will be installed
+l Name of the library
+p Path to library zip bundle
</pre></div></div>
</li>
</ul>
-<p>After AsterixDB starts, you can use the following query to check whether your UDFs have been sucessfully registered with the system.</p>
+<p>Above is a sample output and explains the usage and the required parameters. Each library has a name and is installed under a dataverse. Recall that we had created a dataverse by the name - “feeds” prior to creating our datatypes and dataset. We shall name our library - “testlib”.</p>
+<p>We assume you have a library zip bundle that needs to be installed. To install the library, use the Managix install command. An example is shown below.</p>
<div>
<div>
-<pre class="source"> SELECT * FROM Metadata.`Function`;
+<pre class="source"> $ managix install -n my_asterix -d feeds -l testlib -p extlibs/asterix-external-data-0.8.7-binary-assembly.zip
</pre></div></div>
-<p>In the AsterixDB source release, we provide several sample UDFs that you can try out. You need to build the AsterixDB source to get the compiled UDF package. It can be found under the <tt>asterixdb-external</tt> sub-project. Assuming that these UDFs have been installed into the <tt>udfs</tt> dataverse and <tt>testlib</tt> library, here is an example that uses the sample UDF <tt>mysum</tt> to compute the sum of two input integers.</p>
+<p>You should see the following message:</p>
<div>
<div>
-<pre class="source"> use udfs;
-
- testlib#mysum(3,4);
+<pre class="source"> INFO: Installed library testlib
</pre></div></div>
-</div>
+
+<p>We shall next start our AsterixDB instance using the start command as shown below.</p>
+
+<div>
+<div>
+<pre class="source"> $ managix start -n my_asterix
+</pre></div></div>
+
+<p>You may now use the AsterixDB library in AQL statements and queries. To look at the installed artifacts, you may execute the following query at the AsterixDB web-console.</p>
+
+<div>
+<div>
+<pre class="source"> for $x in dataset Metadata.Function
+ return $x
+
+ for $x in dataset Metadata.Library
+ return $x
+</pre></div></div>
+
+<p>Our library is now installed and is ready to be used.</p></div></div>
<div class="section">
-<h2><a name="Attaching_a_UDF_on_Data_Feeds"></a><a name="UDFOnFeeds" id="UDFOnFeeds">Attaching a UDF on Data Feeds</a></h2>
-<p>In <a href="feeds.html">Data Ingestion using feeds</a>, we introduced an efficient way for users to get data into AsterixDB. In some use cases, users may want to pre-process the incoming data before storing it into the dataset. To meet this need, AsterixDB allows the user to attach a UDF onto the ingestion pipeline. Following the example in <a href="feeds.html">Data Ingestion</a>, here we show an example of how to attach a UDF that extracts the user names mentioned from the incoming Tweet text, storing the processed Tweets into a dataset.</p>
-<p>We start by creating the datatype and dataset that will be used for the feed and UDF. One thing to keep in mind is that data flows from the feed to the UDF and then to the dataset. This means that the feed’s datatype should be the same as the input type of the UDF, and the output datatype of the UDF should be the same as the dataset’s datatype. Thus, users should make sure that their datatypes are consistent in the UDF configuration. Users can also take advantage of open datatypes in AsterixDB by creating a minimum description of the data for simplicity. Here we use open datatypes:</p>
+<h2><a name="Preprocessing_Collected_Data"></a><a name="PreprocessingCollectedData" id="PreprocessingCollectedData">Preprocessing Collected Data</a></h2>
+<p>In the following we assume that you already created the <tt>TwitterFeed</tt> and its corresponding data types and dataset following the instruction explained in the <a href="feeds/tutorial.html">feeds tutorial</a>.</p>
+<p>A feed definition may optionally include the specification of a user-defined function that is to be applied to each feed object prior to persistence. Examples of pre-processing might include adding attributes, filtering out objects, sampling, sentiment analysis, feature extraction, etc. We can express a UDF, which can be defined in AQL or in a programming language such as Java, to perform such pre-processing. An AQL UDF is a good fit when pre-processing a object requires the result of a query (join or aggregate) over data contained in AsterixDB datasets. More sophisticated processing such as sentiment analysis of text is better handled by providing a Java UDF. A Java UDF has an initialization phase that allows the UDF to access any resources it may need to initialize itself prior to being used in a data flow. It is assumed by the AsterixDB compiler to be stateless and thus usable as an embarrassingly parallel black box. In contrast, the AsterixDB compiler can reason about an AQL UDF and involve the use of indexes during its invocation.</p>
+<p>We consider an example transformation of a raw tweet into its lightweight version called <tt>ProcessedTweet</tt>, which is defined next.</p>
<div>
<div>
-<pre class="source"> use udfs;
+<pre class="source"> use dataverse feeds;
- create type TweetType if not exists as open {
- id: int64
+ create type ProcessedTweet if not exists as open {
+ id: string,
+ user_name:string,
+ location:point,
+ created_at:string,
+ message_text:string,
+ country: string,
+ topics: {{string}}
};
- create dataset ProcessedTweets(TweetType) primary key id;
+ create dataset ProcessedTweets(ProcessedTweet)
+ primary key id;
</pre></div></div>
-<p>As the <tt>TweetType</tt> is an open datatype, processed Tweets can be stored into the dataset after they are annotated with an extra attribute. Given the datatype and dataset above, we can create a Twitter Feed with the same datatype. Please refer to section <a href="feeds.html">Data Ingestion</a> if you have any trouble in creating feeds.</p>
+<p>The processing required in transforming a collected tweet to its lighter version of type <tt>ProcessedTweet</tt> involves extracting the topics or hash-tags (if any) in a tweet and collecting them in the referred “topics” attribute for the tweet. Additionally, the latitude and longitude values (doubles) are combined into the spatial point type. Note that spatial data types are considered as first-class citizens that come with the support for creating indexes. Next we show a revised version of our example TwitterFeed that involves the use of a UDF. We assume that the UDF that contains the transformation logic into a “ProcessedTweet” is available as a Java UDF inside an AsterixDB library named ‘testlib’. We defer the writing of a Java UDF and its installation as part of an AsterixDB library to a later section of this document.</p>
<div>
<div>
-<pre class="source"> use udfs;
+<pre class="source"> use dataverse feeds;
- create feed TwitterFeed with {
- "adapter-name": "push_twitter",
- "type-name": "TweetType",
- "format": "twitter-status",
- "consumer.key": "************",
- "consumer.secret": "************",
- "access.token": "**********",
- "access.token.secret": "*************"
- };
+ create feed ProcessedTwitterFeed if not exists
+ using "push_twitter"
+ (("type-name"="Tweet"),
+ ("consumer.key"="************"),
+ ("consumer.secret"="**************"),
+ ("access.token"="**********"),
+ ("access.token.secret"="*************"))
+
+ apply function testlib#addHashTagsInPlace;
</pre></div></div>
-<p>After creating the feed, we attach the UDF onto the feed pipeline and start the feed with following statements:</p>
-
-<div>
-<div>
-<pre class="source"> use udfs;
-
- connect feed TwitterFeed to dataset ProcessedTweets apply function udfs#addMentionedUsers;
-
- start feed TwitterFeed;
-</pre></div></div>
-
-<p>You can check the annotated Tweets by querying the <tt>ProcessedTweets</tt> dataset:</p>
-
-<div>
-<div>
-<pre class="source"> SELECT * FROM ProcessedTweets LIMIT 10;
-</pre></div></div>
-</div>
+<p>Note that a feed adaptor and a UDF act as pluggable components. These contribute towards providing a generic “plug-and-play” model where custom implementations can be provided to cater to specific requirements.</p>
<div class="section">
-<h2><a name="A_quick_look_of_the_UDF_configuration"></a><a name="udfConfiguration">A quick look of the UDF configuration</a></h2>
-<p>AsterixDB uses an XML configuration file to describe the UDFs. A user can use it to define and reuse their compiled UDFs for different purposes. Here is a snippet of the configuration used in our <a href="#UDFOnFeeds">previous example</a>:</p>
-
-<div>
-<div>
-<pre class="source"> <libraryFunction>
- <name>addMentionedUsers</name>
- <function_type>SCALAR</function_type>
- <argument_type>TweetType</argument_type>
- <return_type>TweetType</return_type>
- <definition>org.apache.asterix.external.library.AddMentionedUsersFactory</definition>
- <parameters>text</parameters>
- </libraryFunction>
-</pre></div></div>
-
-<p>Here are the explanations of the fields in the configuration file:</p>
-
-<div>
-<div>
-<pre class="source"> name: The proper name that is used for invoke the function.
- function_type: The type of the function.
- argument_type: The datatype of the arguments passed in. If there is more than one parameter, separate them with comma(s), e.g., `AINT32,AINT32`.
- return_type: The datatype of the returning value.
- definition: A reference to the function factory.
- parameters: The parameters passed into the function.
-</pre></div></div>
-
-<p>In our feeds example, we passed in <tt>"text"</tt> as a parameter to the function so it knows which field to look at to get the Tweet text. If the Twitter API were to change its field names in the future, we can accommodate that change by simply modifying the configuration file instead of recompiling the whole UDF package. This feature can be further utilized in use cases where a user has a Machine Learning algorithm with different trained model files. If you are interested, You can find more examples <a class="externalLink" href="https://github.com/apache/asterixdb/tree/master/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library">here</a></p></div>
<div class="section">
-<h2><a name="Unstalling_an_UDF_Library"></a><a name="uninstall">Unstalling an UDF Library</a></h2>
-<p>If you want to uninstall the UDF library, put AsterixDB into <tt>INACTVIVE</tt> mode and run following command:</p>
+<h4><a name="Building_a_Cascade_Network_of_Feeds"></a>Building a Cascade Network of Feeds</h4>
+<p>Multiple high-level applications may wish to consume the data ingested from a data feed. Each such application might perceive the feed in a different way and require the arriving data to be processed and/or persisted differently. Building a separate flow of data from the external source for each application is wasteful of resources as the pre-processing or transformations required by each application might overlap and could be done together in an incremental fashion to avoid redundancy. A single flow of data from the external source could provide data for multiple applications. To achieve this, we introduce the notion of primary and secondary feeds in AsterixDB.</p>
+<p>A feed in AsterixDB is considered to be a primary feed if it gets its data from an external data source. The objects contained in a feed (subsequent to any pre-processing) are directed to a designated AsterixDB dataset. Alternatively or additionally, these objects can be used to derive other feeds known as secondary feeds. A secondary feed is similar to its parent feed in every other aspect; it can have an associated UDF to allow for any subsequent processing, can be persisted into a dataset, and/or can be made to derive other secondary feeds to form a cascade network. A primary feed and a dependent secondary feed form a hierarchy. As an example, we next show an example AQL statement that redefines the previous feed “ProcessedTwitterFeed” in terms of their respective parent feed (TwitterFeed).</p>
<div>
<div>
-<pre class="source"> $ bin/udf.sh -m u -d DATAVERSE_NAME -l LIBRARY_NAME
+<pre class="source"> use dataverse feeds;
+
+ drop feed ProcessedTwitterFeed if exists;
+
+ create secondary feed ProcessedTwitterFeed from feed TwitterFeed
+ apply function testlib#addHashTags;
+
+ connect feed ProcessedTwitterFeed to dataset ProcessedTweets;
+</pre></div></div>
+
+<p>The <tt>addHashTags</tt> function is already provided in the example UDF.To see what objects are being inserted into the dataset, we can perform a simple dataset scan after allowing a few moments for the feed to start ingesting data:</p>
+
+<div>
+<div>
+<pre class="source"> use dataverse feeds;
+
+ for $i in dataset ProcessedTweets limit 10 return $i;
+</pre></div></div>
+
+<p>For an example of how to write a Java UDF from scratch, the source for the example UDF that has been used in this tutorial is available [here] (<a class="externalLink" href="https://github.com/apache/asterixdb/tree/master/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library">https://github.com/apache/asterixdb/tree/master/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library</a>)</p></div></div></div>
+<div class="section">
+<h2><a name="Unstalling_an_AsterixDB_Library"></a><a name="installingUDF">Unstalling an AsterixDB Library</a></h2>
+<p>To uninstall a library, use the Managix uninstall command as follows:</p>
+
+<div>
+<div>
+<pre class="source"> $ managix stop -n my_asterix
+
+ $ managix uninstall -n my_asterix -d feeds -l testlib
</pre></div></div></div>
</div>
</div>