blob: c065ab392e585a2b15a088ddfe71fbed253f7508 [file] [log] [blame]
Ian Maxonbf2c56b2017-01-24 14:14:49 -08001<!DOCTYPE html>
2<!--
3 | Generated by Apache Maven Doxia at 2017-01-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="20170124" />
11 <meta http-equiv="Content-Language" content="en" />
12 <title>AsterixDB &#x2013; Accessing External Data 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=".././" 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: 2017-01-24</li>
52
53
54
55 <li id="projectVersion" class="pull-right">Version: 0.9.0</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">Get Started - Installation</li>
74
75 <li>
76
77 <a href="../ncservice.html" title="Option 1: using NCService">
78 <i class="none"></i>
79 Option 1: using NCService</a>
80 </li>
81
82 <li>
83
84 <a href="../install.html" title="Option 2: using Managix">
85 <i class="none"></i>
86 Option 2: using Managix</a>
87 </li>
88
89 <li>
90
91 <a href="../yarn.html" title="Option 3: using YARN">
92 <i class="none"></i>
93 Option 3: using YARN</a>
94 </li>
95 <li class="nav-header">AsterixDB Primer</li>
96
97 <li>
98
99 <a href="../sqlpp/primer-sqlpp.html" title="Option 1: using SQL++">
100 <i class="none"></i>
101 Option 1: using SQL++</a>
102 </li>
103
104 <li>
105
106 <a href="../aql/primer.html" title="Option 2: using AQL">
107 <i class="none"></i>
108 Option 2: using AQL</a>
109 </li>
110 <li class="nav-header">Data Model</li>
111
112 <li>
113
114 <a href="../datamodel.html" title="The Asterix Data Model">
115 <i class="none"></i>
116 The Asterix Data Model</a>
117 </li>
118 <li class="nav-header">Queries - SQL++</li>
119
120 <li>
121
122 <a href="../sqlpp/manual.html" title="The SQL++ Query Language">
123 <i class="none"></i>
124 The SQL++ Query Language</a>
125 </li>
126
127 <li>
128
129 <a href="../sqlpp/builtins.html" title="Builtin Functions">
130 <i class="none"></i>
131 Builtin Functions</a>
132 </li>
133 <li class="nav-header">Queries - AQL</li>
134
135 <li>
136
137 <a href="../aql/manual.html" title="The Asterix Query Language (AQL)">
138 <i class="none"></i>
139 The Asterix Query Language (AQL)</a>
140 </li>
141
142 <li>
143
144 <a href="../aql/builtins.html" title="Builtin Functions">
145 <i class="none"></i>
146 Builtin Functions</a>
147 </li>
148 <li class="nav-header">Advanced Features</li>
149
150 <li>
151
152 <a href="../aql/similarity.html" title="Support of Similarity Queries">
153 <i class="none"></i>
154 Support of Similarity Queries</a>
155 </li>
156
157 <li>
158
159 <a href="../aql/fulltext.html" title="Support of Full-text Queries">
160 <i class="none"></i>
161 Support of Full-text Queries</a>
162 </li>
163
164 <li class="active">
165
166 <a href="#"><i class="none"></i>Accessing External Data</a>
167 </li>
168
169 <li>
170
171 <a href="../feeds/tutorial.html" title="Support for Data Ingestion">
172 <i class="none"></i>
173 Support for Data Ingestion</a>
174 </li>
175
176 <li>
177
178 <a href="../udf.html" title="User Defined Functions">
179 <i class="none"></i>
180 User Defined Functions</a>
181 </li>
182
183 <li>
184
185 <a href="../aql/filters.html" title="Filter-Based LSM Index Acceleration">
186 <i class="none"></i>
187 Filter-Based LSM Index Acceleration</a>
188 </li>
189 <li class="nav-header">API/SDK</li>
190
191 <li>
192
193 <a href="../api.html" title="HTTP API">
194 <i class="none"></i>
195 HTTP API</a>
196 </li>
197 </ul>
198
199
200
201 <hr class="divider" />
202
203 <div id="poweredBy">
204 <div class="clear"></div>
205 <div class="clear"></div>
206 <div class="clear"></div>
207 <a href=".././" title="AsterixDB" class="builtBy">
208 <img class="builtBy" alt="AsterixDB" src="../images/asterixlogo.png" />
209 </a>
210 </div>
211 </div>
212 </div>
213
214
215 <div id="bodyColumn" class="span9" >
216
217 <!-- ! Licensed to the Apache Software Foundation (ASF) under one
218 ! or more contributor license agreements. See the NOTICE file
219 ! distributed with this work for additional information
220 ! regarding copyright ownership. The ASF licenses this file
221 ! to you under the Apache License, Version 2.0 (the
222 ! "License"); you may not use this file except in compliance
223 ! with the License. You may obtain a copy of the License at
224 !
225 ! http://www.apache.org/licenses/LICENSE-2.0
226 !
227 ! Unless required by applicable law or agreed to in writing,
228 ! software distributed under the License is distributed on an
229 ! "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
230 ! KIND, either express or implied. See the License for the
231 ! specific language governing permissions and limitations
232 ! under the License.
233 ! --><h1>Accessing External Data in AsterixDB</h1>
234<div class="section">
235<h2><a name="Table_of_Contents"></a><a name="toc" id="toc">Table of Contents</a></h2>
236
237<ul>
238
239<li><a href="#Introduction">Introduction</a></li>
240
241<li><a href="#IntroductionAdapterForAnExternalDataset">Adapter for an External Dataset</a></li>
242
243<li><a href="#BuiltinAdapters">Builtin Adapters</a></li>
244
245<li><a href="#IntroductionCreatingAnExternalDataset">Creating an External Dataset</a></li>
246
247<li><a href="#WritingQueriesAgainstAnExternalDataset">Writing Queries against an External Dataset</a></li>
248
249<li><a href="#BuildingIndexesOverExternalDatasets">Building Indexes over External Datasets</a></li>
250
251<li><a href="#ExternalDataSnapshot">External Data Snapshots</a></li>
252
253<li><a href="#FAQ">Frequently Asked Questions</a></li>
254</ul></div>
255<div class="section">
256<h2><a name="Introduction_Back_to_TOC"></a><a name="Introduction" id="Introduction">Introduction</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h2>
257<p>Data that needs to be processed by AsterixDB could be residing outside AsterixDB storage. Examples include data files on a distributed file system such as HDFS or on the local file system of a machine that is part of an AsterixDB cluster. For AsterixDB to process such data, an end-user may create a regular dataset in AsterixDB (a.k.a. an internal dataset) and load the dataset with the data. AsterixDB also supports &#x2018;&#x2018;external datasets&#x2019;&#x2019; so that it is not necessary to &#x201c;load&#x201d; all data prior to using it. This also avoids creating multiple copies of data and the need to keep the copies in sync.</p>
258<div class="section">
259<h3><a name="Adapter_for_an_External_Dataset_Back_to_TOC"></a><a name="IntroductionAdapterForAnExternalDataset" id="IntroductionAdapterForAnExternalDataset">Adapter for an External Dataset</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h3>
260<p>External data is accessed using wrappers (adapters in AsterixDB) that abstract away the mechanism of connecting with an external service, receiving its data and transforming the data into ADM objects that are understood by AsterixDB. AsterixDB comes with built-in adapters for common storage systems such as HDFS or the local file system.</p></div>
261<div class="section">
262<h3><a name="Builtin_Adapters_Back_to_TOC"></a><a name="BuiltinAdapters" id="BuiltinAdapters">Builtin Adapters</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h3>
263<p>AsterixDB offers a set of builtin adapters that can be used to query external data or for loading data into an internal dataset using a load statement or a data feed. Each adapter requires specifying the <tt>format</tt> of the data in order to be able to parse objects correctly. Using adapters with feeds, the parameter <tt>output-type</tt> must also be specified.</p>
264<p>Following is a listing of existing built-in adapters and their configuration parameters:</p>
265
266<ol style="list-style-type: decimal">
267
268<li><b><i>localfs</i></b>: used for reading data stored in a local filesystem in one or more of the node controllers
269
270<ul>
271
272<li><tt>path</tt>: A fully qualified path of the form <tt>host://absolute_path</tt>. Comma separated list if there are multiple directories or files</li>
273
274<li><tt>expression</tt>: A <a class="externalLink" href="https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html">regular expression</a> to match and filter against file names</li>
275 </ul></li>
276
277<li><b><i>hdfs</i></b>: used for reading data stored in an HDFS instance
278
279<ul>
280
281<li><tt>path</tt>: A fully qualified path of the form <tt>host://absolute_path</tt>. Comma separated list if there are multiple directories or files</li>
282
283<li><tt>expression</tt>: A <a class="externalLink" href="https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html">regular expression</a> to match and filter against file names</li>
284
285<li><tt>input-format</tt>: A fully qualified name or an alias for a class of HDFS input format</li>
286
287<li><tt>hdfs</tt>: The HDFS name node URL</li>
288 </ul></li>
289
290<li><b><i>socket</i></b>: used for listening to connections that sends data streams through one or more sockets
291
292<ul>
293
294<li><tt>sockets</tt>: comma separated list of sockets to listen to</li>
295
296<li><tt>address-type</tt>: either IP if the list uses IP addresses, or NC if the list uses NC names</li>
297 </ul></li>
298
299<li><b><i>socket_client</i></b>: used for connecting to one or more sockets and reading data streams
300
301<ul>
302
303<li><tt>sockets</tt>: comma separated list of sockets to connect to</li>
304 </ul></li>
305
306<li><b><i>twitter_push</i></b>: used for establishing a connection and subscribing to a twitter feed
307
308<ul>
309
310<li><tt>consumer.key</tt>: access parameter provided by twitter OAuth</li>
311
312<li><tt>consumer.secret</tt>: access parameter provided by twitter OAuth</li>
313
314<li><tt>access.token</tt>: access parameter provided by twitter OAuth</li>
315
316<li><tt>access.token.secret</tt>: access parameter provided by twitter OAuth</li>
317 </ul></li>
318
319<li><b><i>twitter_pull</i></b>: used for polling a twitter feed for tweets based on a configurable frequency
320
321<ul>
322
323<li><tt>consumer.key</tt>: access parameter provided by twitter OAuth</li>
324
325<li><tt>consumer.secret</tt>: access parameter provided by twitter OAuth</li>
326
327<li><tt>access.token</tt>: access parameter provided by twitter OAuth</li>
328
329<li><tt>access.token.secret</tt>: access parameter provided by twitter OAuth</li>
330
331<li><tt>query</tt>: twitter query string</li>
332
333<li><tt>interval</tt>: poll interval in seconds</li>
334 </ul></li>
335
336<li><b><i>rss</i></b>: used for reading RSS feed
337
338<ul>
339
340<li><tt>url</tt>: a comma separated list of RSS urls</li>
341 </ul></li>
342</ol></div>
343<div class="section">
344<h3><a name="Creating_an_External_Dataset_Back_to_TOC"></a><a name="IntroductionCreatingAnExternalDataset" id="IntroductionCreatingAnExternalDataset">Creating an External Dataset</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h3>
345<p>As an example we consider the Lineitem dataset from the <a class="externalLink" href="http://www.openlinksw.com/dataspace/doc/dav/wiki/Main/VOSTPCHLinkedData/tpch.sql">TPCH schema</a>. We assume that you have successfully created an AsterixDB instance following the instructions at <a href="../install.html">Installing AsterixDB Using Managix</a>. <i>For constructing an example, we assume a single machine setup..</i></p>
346<p>Similar to a regular dataset, an external dataset has an associated datatype. We shall first create the datatype associated with each object in Lineitem data. Paste the following in the query textbox on the webpage at <a class="externalLink" href="http://127.0.0.1:19001">http://127.0.0.1:19001</a> and hit &#x2018;Execute&#x2019;.</p>
347
348<div class="source">
349<div class="source">
350<pre> create dataverse ExternalFileDemo;
351 use dataverse ExternalFileDemo;
352
353 create type LineitemType as closed {
354 l_orderkey:int32,
355 l_partkey: int32,
356 l_suppkey: int32,
357 l_linenumber: int32,
358 l_quantity: double,
359 l_extendedprice: double,
360 l_discount: double,
361 l_tax: double,
362 l_returnflag: string,
363 l_linestatus: string,
364 l_shipdate: string,
365 l_commitdate: string,
366 l_receiptdate: string,
367 l_shipinstruct: string,
368 l_shipmode: string,
369 l_comment: string}
370</pre></div></div>
371<p>Here, we describe two scenarios.</p>
372<div class="section">
373<h4><a name="a1_Data_file_resides_on_the_local_file_system_of_a_host"></a>1) Data file resides on the local file system of a host</h4>
374<p>Prerequisite: The host is a part of the ASTERIX cluster.</p>
375<p>Earlier, we assumed a single machine ASTERIX setup. To satisfy the prerequisite, log-in to the machine running ASTERIX.</p>
376
377<ul>
378
379<li>Download the <a href="../data/lineitem.tbl">data file</a> to an appropriate location. We denote this location by SOURCE_PATH.</li>
380</ul>
381<p>ASTERIX provides a built-in adapter for data residing on the local file system. The adapter is referred by its alias- &#x2018;localfs&#x2019;. We create an external dataset named Lineitem and use the &#x2018;localfs&#x2019; adapter.</p>
382
383<div class="source">
384<div class="source">
385<pre> create external dataset Lineitem(LineitemType)
386 using localfs
387</pre></div></div>
388<p>Above, the definition is not complete as we need to provide a set of parameters that are specific to the source file.</p>
389
390<table border="0" class="table table-striped">
391
392<tr class="a">
393
394<td> Parameter </td>
395
396<td> Description </td>
397</tr>
398
399<tr class="b">
400
401<td> path </td>
402
403<td> A fully qualified path of the form <tt>host://&lt;absolute path&gt;</tt>.
404 Use a comma separated list if there are multiple files.
405 E.g. <tt>host1://&lt;absolute path&gt;</tt>, <tt>host2://&lt;absolute path&gt;</tt> and so forth. </td>
406</tr>
407
408<tr class="a">
409
410<td> format </td>
411
412<td> The format for the content. Use 'adm' for data in ADM (ASTERIX Data Model) or <a class="externalLink" href="http://www.json.org/">JSON</a> format. Use 'delimited-text' if fields are separated by a delimiting character (eg., CSV). </td></tr>
413
414<tr class="b">
415
416<td>delimiter</td>
417
418<td>The delimiting character in the source file if format is 'delimited text'</td>
419</tr>
420</table>
421<p>As we are using a single single machine ASTERIX instance, we use 127.0.0.1 as host in the path parameter. We <i>complete the create dataset statement</i> as follows.</p>
422
423<div class="source">
424<div class="source">
425<pre> use dataverse ExternalFileDemo;
426
427 create external dataset Lineitem(LineitemType)
428 using localfs
429 ((&quot;path&quot;=&quot;127.0.0.1://SOURCE_PATH&quot;),
430 (&quot;format&quot;=&quot;delimited-text&quot;),
431 (&quot;delimiter&quot;=&quot;|&quot;));
432</pre></div></div>
433<p>Please substitute SOURCE_PATH with the absolute path to the source file on the local file system.</p></div>
434<div class="section">
435<h4><a name="Common_source_of_error"></a>Common source of error</h4>
436<p>An incorrect value for the path parameter will give the following exception message when the dataset is used in a query.</p>
437
438<div class="source">
439<div class="source">
440<pre> org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: org.apache.hyracks.api.exceptions.HyracksDataException: org.apache.hyracks.api.exceptions.HyracksDataException: Job failed.
441</pre></div></div>
442<p>Verify the correctness of the path parameter provided to the localfs adapter. Note that the path parameter must be an absolute path to the data file. For e.g. if you saved your file in your home directory (assume it to be /home/joe), then the path value should be</p>
443
444<div class="source">
445<div class="source">
446<pre> 127.0.0.1:///home/joe/lineitem.tbl.
447</pre></div></div>
448<p>In your web-browser, navigate to 127.0.0.1:19001 and paste the above to the query text box. Finally hit &#x2018;Execute&#x2019;.</p>
449<p>Next we move over to the the section <a href="#Writing_Queries_against_an_External_Dataset">Writing Queries against an External Dataset</a> and try a sample query against the external dataset.</p></div>
450<div class="section">
451<h4><a name="a2_Data_file_resides_on_an_HDFS_instance"></a>2) Data file resides on an HDFS instance</h4>
452<p>rerequisite: It is required that the Namenode and HDFS Datanodes are reachable from the hosts that form the AsterixDB cluster. AsterixDB provides a built-in adapter for data residing on HDFS. The HDFS adapter can be referred (in AQL) by its alias - &#x2018;hdfs&#x2019;. We can create an external dataset named Lineitem and associate the HDFS adapter with it as follows;</p>
453
454<div class="source">
455<div class="source">
456<pre> create external dataset Lineitem(LineitemType)
457 using hdfs((&#x201c;hdfs&#x201d;:&#x201d;hdfs://localhost:54310&#x201d;),(&#x201c;path&#x201d;:&#x201d;/asterix/Lineitem.tbl&#x201d;),...,(&#x201c;input- format&#x201d;:&#x201d;rc-format&#x201d;));
458</pre></div></div>
459<p>The expected parameters are described below:</p>
460
461<table border="0" class="table table-striped">
462
463<tr class="a">
464
465<td> Parameter </td>
466
467<td> Description </td>
468</tr>
469
470<tr class="b">
471
472<td> hdfs </td>
473
474<td> The HDFS URL </td>
475</tr>
476
477<tr class="a">
478
479<td> path </td>
480
481<td> The absolute path to the source HDFS file or directory. Use a comma separated list if there are multiple files or directories. </td></tr>
482
483<tr class="b">
484
485<td> input-format </td>
486
487<td> The associated input format. Use 'text-input-format' for text files , 'sequence-input-format' for hadoop sequence files, 'rc-input-format' for Hadoop Object Columnar files, or a fully qualified name of an implementation of org.apache.hadoop.mapred.InputFormat. </td>
488</tr>
489
490<tr class="a">
491
492<td> format </td>
493
494<td> The format of the input content. Use 'adm' for text data in ADM (ASTERIX Data Model) or <a class="externalLink" href="http://www.json.org/">JSON</a> format, 'delimited-text' for text delimited data that has fields separated by a delimiting character, 'binary' for other data.</td>
495</tr>
496
497<tr class="b">
498
499<td> delimiter </td>
500
501<td> The delimiting character in the source file if format is 'delimited text' </td>
502</tr>
503
504<tr class="a">
505
506<td> parser </td>
507
508<td> The parser used to parse HDFS objects if the format is 'binary'. Use 'hive- parser' for data deserialized by a Hive Serde (AsterixDB can understand deserialized Hive objects) or a fully qualified class name of user- implemented parser that implements the interface org.apache.asterix.external.input.InputParser. </td>
509</tr>
510
511<tr class="b">
512
513<td> hive-serde </td>
514
515<td> The Hive serde is used to deserialize HDFS objects if format is binary and the parser is hive-parser. Use a fully qualified name of a class implementation of org.apache.hadoop.hive.serde2.SerDe. </td>
516</tr>
517
518<tr class="a">
519
520<td> local-socket-path </td>
521
522<td> The UNIX domain socket path if local short-circuit reads are enabled in the HDFS instance</td>
523</tr>
524</table>
525<p><i>Difference between &#x2018;input-format&#x2019; and &#x2018;format&#x2019;</i></p>
526<p><i>input-format</i>: Files stored under HDFS have an associated storage format. For example, TextInputFormat represents plain text files. SequenceFileInputFormat indicates binary compressed files. RCFileInputFormat corresponds to objects stored in a object columnar fashion. The parameter &#x2018;input-format&#x2019; is used to distinguish between these and other HDFS input formats.</p>
527<p><i>format</i>: The parameter &#x2018;format&#x2019; refers to the type of the data contained in the file. For example, data contained in a file could be in json or ADM format, could be in delimited-text with fields separated by a delimiting character or could be in binary format.</p>
528<p>As an example. consider the <a href="../data/lineitem.tbl">data file</a>. The file is a text file with each line representing a object. The fields in each object are separated by the &#x2018;|&#x2019; character.</p>
529<p>We assume the HDFS URL to be <a class="externalLink" href="hdfs://localhost:54310">hdfs://localhost:54310</a>. We further assume that the example data file is copied to HDFS at a path denoted by &#x201c;/asterix/Lineitem.tbl&#x201d;.</p>
530<p>The complete set of parameters for our example file are as follows. ((&#x201c;hdfs&#x201d;=&#x201c;hdfs://localhost:54310&#x201d;,(&#x201c;path&#x201d;=&#x201c;/asterix/Lineitem.tbl&#x201d;),(&#x201c;input-format&#x201d;=&#x201c;text- input-format&#x201d;),(&#x201c;format&#x201d;=&#x201c;delimited-text&#x201d;),(&#x201c;delimiter&#x201d;=&#x201c;|&#x201d;))</p></div>
531<div class="section">
532<h4><a name="Using_the_Hive_Parser"></a>Using the Hive Parser</h4>
533<p>if a user wants to create an external dataset that uses hive-parser to parse HDFS objects, it is important that the datatype associated with the dataset matches the actual data in the Hive table for the correct initialization of the Hive SerDe. Here is the conversion from the supported Hive data types to AsterixDB data types:</p>
534
535<table border="0" class="table table-striped">
536
537<tr class="a">
538
539<td> Hive </td>
540
541<td> AsterixDB </td>
542</tr>
543
544<tr class="b">
545
546<td>BOOLEAN</td>
547
548<td>Boolean</td>
549</tr>
550
551<tr class="a">
552
553<td>BYTE(TINY INT)</td>
554
555<td>Int8</td>
556</tr>
557
558<tr class="b">
559
560<td>DOUBLE</td>
561
562<td>Double</td>
563</tr>
564
565<tr class="a">
566
567<td>FLOAT</td>
568
569<td>Float</td>
570</tr>
571
572<tr class="b">
573
574<td>INT</td>
575
576<td>Int32</td>
577</tr>
578
579<tr class="a">
580
581<td>LONG(BIG INT)</td>
582
583<td>Int64</td>
584</tr>
585
586<tr class="b">
587
588<td>SHORT(SMALL INT)</td>
589
590<td>Int16</td>
591</tr>
592
593<tr class="a">
594
595<td>STRING</td>
596
597<td>String</td>
598</tr>
599
600<tr class="b">
601
602<td>TIMESTAMP</td>
603
604<td>Datetime</td>
605</tr>
606
607<tr class="a">
608
609<td>DATE</td>
610
611<td>Date</td>
612</tr>
613
614<tr class="b">
615
616<td>STRUCT</td>
617
618<td>Nested Object</td>
619</tr>
620
621<tr class="a">
622
623<td>LIST</td>
624
625<td>OrderedList or UnorderedList</td>
626</tr>
627</table></div>
628<div class="section">
629<h4><a name="Examples_of_dataset_definitions_for_external_datasets"></a>Examples of dataset definitions for external datasets</h4>
630<p><i>Example 1</i>: We can modify the create external dataset statement as follows:</p>
631
632<div class="source">
633<div class="source">
634<pre> create external dataset Lineitem('LineitemType)
635 using hdfs((&quot;hdfs&quot;=&quot;hdfs://localhost:54310&quot;),(&quot;path&quot;=&quot;/asterix/Lineitem.tbl&quot;),(&quot;input-format&quot;=&quot;text- input-format&quot;),(&quot;format&quot;=&quot;delimited-text&quot;),(&quot;delimiter&quot;=&quot;|&quot;));
636</pre></div></div>
637<p><i>Example 2</i>: Here, we create an external dataset of lineitem objects stored in sequence files that has content in ADM format:</p>
638
639<div class="source">
640<div class="source">
641<pre> create external dataset Lineitem('LineitemType)
642 using hdfs((&quot;hdfs&quot;=&quot;hdfs://localhost:54310&quot;),(&quot;path&quot;=&quot;/asterix/SequenceLineitem.tbl&quot;),(&quot;input- format&quot;=&quot;sequence-input-format&quot;),(&quot;format&quot;=&quot;adm&quot;));
643</pre></div></div>
644<p><i>Example 3</i>: Here, we create an external dataset of lineitem objects stored in object-columnar files that has content in binary format parsed using hive-parser with hive ColumnarSerde:</p>
645
646<div class="source">
647<div class="source">
648<pre> create external dataset Lineitem('LineitemType)
649 using hdfs((&quot;hdfs&quot;=&quot;hdfs://localhost:54310&quot;),(&quot;path&quot;=&quot;/asterix/RCLineitem.tbl&quot;),(&quot;input-format&quot;=&quot;rc-input-format&quot;),(&quot;format&quot;=&quot;binary&quot;),(&quot;parser&quot;=&quot;hive-parser&quot;),(&quot;hive- serde&quot;=&quot;org.apache.hadoop.hive.serde2.columnar.ColumnarSerde&quot;));
650</pre></div></div></div></div></div>
651<div class="section">
652<h2><a name="Writing_Queries_against_an_External_Dataset_Back_to_TOC"></a><a name="WritingQueriesAgainstAnExternalDataset" id="WritingQueriesAgainstAnExternalDataset">Writing Queries against an External Dataset</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h2>
653<p>You may write AQL queries against an external dataset in exactly the same way that queries are written against internal datasets. The following is an example of an AQL query that applies a filter and returns an ordered result.</p>
654
655<div class="source">
656<div class="source">
657<pre> use dataverse ExternalFileDemo;
658
659 for $c in dataset('Lineitem')
660 where $c.l_orderkey &lt;= 3
661 order by $c.l_orderkey, $c.l_linenumber
662 return $c
663</pre></div></div></div>
664<div class="section">
665<h2><a name="Building_Indexes_over_External_Datasets_Back_to_TOC"></a><a name="BuildingIndexesOverExternalDatasets" id="BuildingIndexesOverExternalDatasets">Building Indexes over External Datasets</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h2>
666<p>AsterixDB supports building B-Tree and R-Tree indexes over static data stored in the Hadoop Distributed File System. To create an index, first create an external dataset over the data as follows</p>
667
668<div class="source">
669<div class="source">
670<pre> create external dataset Lineitem(LineitemType)
671 using hdfs((&quot;hdfs&quot;=&quot;hdfs://localhost:54310&quot;),(&quot;path&quot;=&quot;/asterix/Lineitem.tbl&quot;),(&quot;input-format&quot;=&quot;text-input- format&quot;),(&quot;format&quot;=&quot;delimited-text&quot;),(&quot;delimiter&quot;=&quot;|&quot;));
672</pre></div></div>
673<p>You can then create a B-Tree index on this dataset instance as if the dataset was internally stored as follows:</p>
674
675<div class="source">
676<div class="source">
677<pre> create index PartkeyIdx on Lineitem(l_partkey);
678</pre></div></div>
679<p>You could also create an R-Tree index as follows:</p>
680
681<div class="source">
682<div class="source">
683<pre> &#xfffc;create index IndexName on DatasetName(attribute-name) type rtree;
684</pre></div></div>
685<p>After building the indexes, the AsterixDB query compiler can use them to access the dataset and answer queries in a more cost effective manner. AsterixDB can read all HDFS input formats, but indexes over external datasets can currently be built only for HDFS datasets with &#x2018;text-input-format&#x2019;, &#x2018;sequence-input-format&#x2019; or &#x2018;rc-input-format&#x2019;.</p></div>
686<div class="section">
687<h2><a name="External_Data_Snapshots_Back_to_TOC"></a><a name="ExternalDataSnapshots" id="ExternalDataSnapshots">External Data Snapshots</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h2>
688<p>An external data snapshot represents the status of a dataset&#x2019;s files in HDFS at a point in time. Upon creating the first index over an external dataset, AsterixDB captures and stores a snapshot of the dataset in HDFS. Only objects present at the snapshot capture time are indexed, and any additional indexes created afterwards will only contain data that was present at the snapshot capture time thus preserving consistency across all indexes of a dataset. To update all indexes of an external dataset and advance the snapshot time to be the present time, a user can use the refresh external dataset command as follows:</p>
689
690<div class="source">
691<div class="source">
692<pre> refresh external dataset DatasetName;
693</pre></div></div>
694<p>After a refresh operation commits, all of the dataset&#x2019;s indexes will reflect the status of the data as of the new snapshot capture time.</p></div>
695<div class="section">
696<h2><a name="Frequently_Asked_Questions_Back_to_TOC"></a><a name="FAQ" id="FAQ">Frequently Asked Questions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h2>
697<p>Q. I added data to my dataset in HDFS, Will the dataset indexes in AsterixDB be updated automatically?</p>
698<p>A. No, you must use the refresh external dataset statement to make the indexes aware of any changes in the dataset files in HDFS.</p>
699<p>Q. Why doesn&#x2019;t AsterixDB update external indexes automatically?</p>
700<p>A. Since external data is managed by other users/systems with mechanisms that are system dependent, AsterixDB has no way of knowing exactly when data is added or deleted in HDFS, so the responsibility of refreshing indexes are left to the user. A user can use internal datasets for which AsterixDB manages the data and its indexes.</p>
701<p>Q. I created an index over an external dataset and then added some data to my HDFS dataset. Will a query that uses the index return different results from a query that doesn&#x2019;t use the index?</p>
702<p>A. No, queries&#x2019; results are access path independent and the stored snapshot is used to determines which data are going to be included when processing queries.</p>
703<p>Q. I created an index over an external dataset and then deleted some of my dataset&#x2019;s files in HDFS, Will indexed data access still return the objects in deleted files?</p>
704<p>A. No. When AsterixDB accesses external data, with or without the use of indexes, it only access files present in the file system at runtime.</p>
705<p>Q. I submitted a refresh command on a an external dataset and a failure occurred, What has happened to my indexes?</p>
706<p>A. External Indexes Refreshes are treated as a single transaction. In case of a failure, a rollback occurs and indexes are restored to their previous state. An error message with the cause of failure is returned to the user.</p>
707<p>Q. I was trying to refresh an external dataset while some queries were accessing the data using index access method. Will the queries be affected by the refresh operation?</p>
708<p>A. Queries have access to external dataset indexes state at the time where the queries are submitted. A query that was submitted before a refresh commits will only access data under the snapshot taken before the refresh; queries that are submitted after the refresh commits will access data under the snapshot taken after the refresh.</p>
709<p>Q. What happens when I try to create an additional index while a refresh operation is in progress or vice versa?</p>
710<p>A. The create index operation will wait until the refresh commits or aborts and then the index will be built according to the external data snapshot at the end of the refresh operation. Creating indexes and refreshing datasets are mutually exclusive operations and will not be run in parallel. Multiple indexes can be created in parallel, but not multiple refresh operations.</p></div>
711 </div>
712 </div>
713 </div>
714
715 <hr/>
716
717 <footer>
718 <div class="container-fluid">
719 <div class="row span12">Copyright &copy; 2017
720 <a href="https://www.apache.org/">The Apache Software Foundation</a>.
721 All Rights Reserved.
722
723 </div>
724
725 <?xml version="1.0" encoding="UTF-8"?>
726<div class="row-fluid">Apache AsterixDB, AsterixDB, Apache, the Apache
727 feather logo, and the Apache AsterixDB project logo are either
728 registered trademarks or trademarks of The Apache Software
729 Foundation in the United States and other countries.
730 All other marks mentioned may be trademarks or registered
731 trademarks of their respective owners.</div>
732
733
734 </div>
735 </footer>
736 </body>
737</html>