blob: 4de2e5301df30ad0de7214f377ae105bb4412e08 [file] [log] [blame]
Ian Maxonbf2c56b2017-01-24 14:14:49 -08001<!DOCTYPE html>
2<!--
Ian Maxond5b11d82017-01-25 10:48:05 -08003 | Generated by Apache Maven Doxia at 2017-01-25
Ian Maxonbf2c56b2017-01-24 14:14:49 -08004 | 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" />
Ian Maxond5b11d82017-01-25 10:48:05 -080010 <meta name="Date-Revision-yyyymmdd" content="20170125" />
Ian Maxonbf2c56b2017-01-24 14:14:49 -080011 <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
Ian Maxonbf2c56b2017-01-24 14:14:49 -080022
Ian Maxonbf2c56b2017-01-24 14:14:49 -080023
24 </head>
25 <body class="topBarDisabled">
26
27
28
29
30 <div class="container-fluid">
31 <div id="banner">
32 <div class="pull-left">
33 <a href=".././" id="bannerLeft">
34 <img src="../images/asterixlogo.png" alt="AsterixDB"/>
35 </a>
36 </div>
37 <div class="pull-right"> </div>
38 <div class="clear"><hr/></div>
39 </div>
40
41 <div id="breadcrumbs">
42 <ul class="breadcrumb">
43
44
Ian Maxond5b11d82017-01-25 10:48:05 -080045 <li id="publishDate">Last Published: 2017-01-25</li>
Ian Maxonbf2c56b2017-01-24 14:14:49 -080046
47
48
49 <li id="projectVersion" class="pull-right">Version: 0.9.0</li>
50
51 <li class="divider pull-right">|</li>
52
53 <li class="pull-right"> <a href="../index.html" title="Documentation Home">
54 Documentation Home</a>
55 </li>
56
57 </ul>
58 </div>
59
60
61 <div class="row-fluid">
62 <div id="leftColumn" class="span3">
63 <div class="well sidebar-nav">
64
65
66 <ul class="nav nav-list">
67 <li class="nav-header">Get Started - Installation</li>
68
69 <li>
70
71 <a href="../ncservice.html" title="Option 1: using NCService">
72 <i class="none"></i>
73 Option 1: using NCService</a>
74 </li>
75
76 <li>
77
78 <a href="../install.html" title="Option 2: using Managix">
79 <i class="none"></i>
80 Option 2: using Managix</a>
81 </li>
82
83 <li>
84
85 <a href="../yarn.html" title="Option 3: using YARN">
86 <i class="none"></i>
87 Option 3: using YARN</a>
88 </li>
89 <li class="nav-header">AsterixDB Primer</li>
90
91 <li>
92
93 <a href="../sqlpp/primer-sqlpp.html" title="Option 1: using SQL++">
94 <i class="none"></i>
95 Option 1: using SQL++</a>
96 </li>
97
98 <li>
99
100 <a href="../aql/primer.html" title="Option 2: using AQL">
101 <i class="none"></i>
102 Option 2: using AQL</a>
103 </li>
104 <li class="nav-header">Data Model</li>
105
106 <li>
107
108 <a href="../datamodel.html" title="The Asterix Data Model">
109 <i class="none"></i>
110 The Asterix Data Model</a>
111 </li>
112 <li class="nav-header">Queries - SQL++</li>
113
114 <li>
115
116 <a href="../sqlpp/manual.html" title="The SQL++ Query Language">
117 <i class="none"></i>
118 The SQL++ Query Language</a>
119 </li>
120
121 <li>
122
123 <a href="../sqlpp/builtins.html" title="Builtin Functions">
124 <i class="none"></i>
125 Builtin Functions</a>
126 </li>
127 <li class="nav-header">Queries - AQL</li>
128
129 <li>
130
131 <a href="../aql/manual.html" title="The Asterix Query Language (AQL)">
132 <i class="none"></i>
133 The Asterix Query Language (AQL)</a>
134 </li>
135
136 <li>
137
138 <a href="../aql/builtins.html" title="Builtin Functions">
139 <i class="none"></i>
140 Builtin Functions</a>
141 </li>
142 <li class="nav-header">Advanced Features</li>
143
144 <li>
145
146 <a href="../aql/similarity.html" title="Support of Similarity Queries">
147 <i class="none"></i>
148 Support of Similarity Queries</a>
149 </li>
150
151 <li>
152
153 <a href="../aql/fulltext.html" title="Support of Full-text Queries">
154 <i class="none"></i>
155 Support of Full-text Queries</a>
156 </li>
157
158 <li class="active">
159
160 <a href="#"><i class="none"></i>Accessing External Data</a>
161 </li>
162
163 <li>
164
165 <a href="../feeds/tutorial.html" title="Support for Data Ingestion">
166 <i class="none"></i>
167 Support for Data Ingestion</a>
168 </li>
169
170 <li>
171
172 <a href="../udf.html" title="User Defined Functions">
173 <i class="none"></i>
174 User Defined Functions</a>
175 </li>
176
177 <li>
178
179 <a href="../aql/filters.html" title="Filter-Based LSM Index Acceleration">
180 <i class="none"></i>
181 Filter-Based LSM Index Acceleration</a>
182 </li>
183 <li class="nav-header">API/SDK</li>
184
185 <li>
186
187 <a href="../api.html" title="HTTP API">
188 <i class="none"></i>
189 HTTP API</a>
190 </li>
191 </ul>
192
193
194
195 <hr class="divider" />
196
197 <div id="poweredBy">
198 <div class="clear"></div>
199 <div class="clear"></div>
200 <div class="clear"></div>
201 <a href=".././" title="AsterixDB" class="builtBy">
202 <img class="builtBy" alt="AsterixDB" src="../images/asterixlogo.png" />
203 </a>
204 </div>
205 </div>
206 </div>
207
208
209 <div id="bodyColumn" class="span9" >
210
211 <!-- ! Licensed to the Apache Software Foundation (ASF) under one
212 ! or more contributor license agreements. See the NOTICE file
213 ! distributed with this work for additional information
214 ! regarding copyright ownership. The ASF licenses this file
215 ! to you under the Apache License, Version 2.0 (the
216 ! "License"); you may not use this file except in compliance
217 ! with the License. You may obtain a copy of the License at
218 !
219 ! http://www.apache.org/licenses/LICENSE-2.0
220 !
221 ! Unless required by applicable law or agreed to in writing,
222 ! software distributed under the License is distributed on an
223 ! "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
224 ! KIND, either express or implied. See the License for the
225 ! specific language governing permissions and limitations
226 ! under the License.
227 ! --><h1>Accessing External Data in AsterixDB</h1>
228<div class="section">
229<h2><a name="Table_of_Contents"></a><a name="toc" id="toc">Table of Contents</a></h2>
230
231<ul>
232
233<li><a href="#Introduction">Introduction</a></li>
234
235<li><a href="#IntroductionAdapterForAnExternalDataset">Adapter for an External Dataset</a></li>
236
237<li><a href="#BuiltinAdapters">Builtin Adapters</a></li>
238
239<li><a href="#IntroductionCreatingAnExternalDataset">Creating an External Dataset</a></li>
240
241<li><a href="#WritingQueriesAgainstAnExternalDataset">Writing Queries against an External Dataset</a></li>
242
243<li><a href="#BuildingIndexesOverExternalDatasets">Building Indexes over External Datasets</a></li>
244
245<li><a href="#ExternalDataSnapshot">External Data Snapshots</a></li>
246
247<li><a href="#FAQ">Frequently Asked Questions</a></li>
248</ul></div>
249<div class="section">
250<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>
251<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>
252<div class="section">
253<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>
254<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>
255<div class="section">
256<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>
257<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>
258<p>Following is a listing of existing built-in adapters and their configuration parameters:</p>
259
260<ol style="list-style-type: decimal">
261
262<li><b><i>localfs</i></b>: used for reading data stored in a local filesystem in one or more of the node controllers
263
264<ul>
265
266<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>
267
268<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>
269 </ul></li>
270
271<li><b><i>hdfs</i></b>: used for reading data stored in an HDFS instance
272
273<ul>
274
275<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>
276
277<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>
278
279<li><tt>input-format</tt>: A fully qualified name or an alias for a class of HDFS input format</li>
280
281<li><tt>hdfs</tt>: The HDFS name node URL</li>
282 </ul></li>
283
284<li><b><i>socket</i></b>: used for listening to connections that sends data streams through one or more sockets
285
286<ul>
287
288<li><tt>sockets</tt>: comma separated list of sockets to listen to</li>
289
290<li><tt>address-type</tt>: either IP if the list uses IP addresses, or NC if the list uses NC names</li>
291 </ul></li>
292
293<li><b><i>socket_client</i></b>: used for connecting to one or more sockets and reading data streams
294
295<ul>
296
297<li><tt>sockets</tt>: comma separated list of sockets to connect to</li>
298 </ul></li>
299
300<li><b><i>twitter_push</i></b>: used for establishing a connection and subscribing to a twitter feed
301
302<ul>
303
304<li><tt>consumer.key</tt>: access parameter provided by twitter OAuth</li>
305
306<li><tt>consumer.secret</tt>: access parameter provided by twitter OAuth</li>
307
308<li><tt>access.token</tt>: access parameter provided by twitter OAuth</li>
309
310<li><tt>access.token.secret</tt>: access parameter provided by twitter OAuth</li>
311 </ul></li>
312
313<li><b><i>twitter_pull</i></b>: used for polling a twitter feed for tweets based on a configurable frequency
314
315<ul>
316
317<li><tt>consumer.key</tt>: access parameter provided by twitter OAuth</li>
318
319<li><tt>consumer.secret</tt>: access parameter provided by twitter OAuth</li>
320
321<li><tt>access.token</tt>: access parameter provided by twitter OAuth</li>
322
323<li><tt>access.token.secret</tt>: access parameter provided by twitter OAuth</li>
324
325<li><tt>query</tt>: twitter query string</li>
326
327<li><tt>interval</tt>: poll interval in seconds</li>
328 </ul></li>
329
330<li><b><i>rss</i></b>: used for reading RSS feed
331
332<ul>
333
334<li><tt>url</tt>: a comma separated list of RSS urls</li>
335 </ul></li>
336</ol></div>
337<div class="section">
338<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>
339<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>
340<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>
341
342<div class="source">
343<div class="source">
344<pre> create dataverse ExternalFileDemo;
345 use dataverse ExternalFileDemo;
346
347 create type LineitemType as closed {
348 l_orderkey:int32,
349 l_partkey: int32,
350 l_suppkey: int32,
351 l_linenumber: int32,
352 l_quantity: double,
353 l_extendedprice: double,
354 l_discount: double,
355 l_tax: double,
356 l_returnflag: string,
357 l_linestatus: string,
358 l_shipdate: string,
359 l_commitdate: string,
360 l_receiptdate: string,
361 l_shipinstruct: string,
362 l_shipmode: string,
363 l_comment: string}
364</pre></div></div>
365<p>Here, we describe two scenarios.</p>
366<div class="section">
367<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>
368<p>Prerequisite: The host is a part of the ASTERIX cluster.</p>
369<p>Earlier, we assumed a single machine ASTERIX setup. To satisfy the prerequisite, log-in to the machine running ASTERIX.</p>
370
371<ul>
372
373<li>Download the <a href="../data/lineitem.tbl">data file</a> to an appropriate location. We denote this location by SOURCE_PATH.</li>
374</ul>
375<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>
376
377<div class="source">
378<div class="source">
379<pre> create external dataset Lineitem(LineitemType)
380 using localfs
381</pre></div></div>
382<p>Above, the definition is not complete as we need to provide a set of parameters that are specific to the source file.</p>
383
384<table border="0" class="table table-striped">
385
386<tr class="a">
387
388<td> Parameter </td>
389
390<td> Description </td>
391</tr>
392
393<tr class="b">
394
395<td> path </td>
396
397<td> A fully qualified path of the form <tt>host://&lt;absolute path&gt;</tt>.
398 Use a comma separated list if there are multiple files.
399 E.g. <tt>host1://&lt;absolute path&gt;</tt>, <tt>host2://&lt;absolute path&gt;</tt> and so forth. </td>
400</tr>
401
402<tr class="a">
403
404<td> format </td>
405
406<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>
407
408<tr class="b">
409
410<td>delimiter</td>
411
412<td>The delimiting character in the source file if format is 'delimited text'</td>
413</tr>
414</table>
415<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>
416
417<div class="source">
418<div class="source">
419<pre> use dataverse ExternalFileDemo;
420
421 create external dataset Lineitem(LineitemType)
422 using localfs
423 ((&quot;path&quot;=&quot;127.0.0.1://SOURCE_PATH&quot;),
424 (&quot;format&quot;=&quot;delimited-text&quot;),
425 (&quot;delimiter&quot;=&quot;|&quot;));
426</pre></div></div>
427<p>Please substitute SOURCE_PATH with the absolute path to the source file on the local file system.</p></div>
428<div class="section">
429<h4><a name="Common_source_of_error"></a>Common source of error</h4>
430<p>An incorrect value for the path parameter will give the following exception message when the dataset is used in a query.</p>
431
432<div class="source">
433<div class="source">
434<pre> org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: org.apache.hyracks.api.exceptions.HyracksDataException: org.apache.hyracks.api.exceptions.HyracksDataException: Job failed.
435</pre></div></div>
436<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>
437
438<div class="source">
439<div class="source">
440<pre> 127.0.0.1:///home/joe/lineitem.tbl.
441</pre></div></div>
442<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>
443<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>
444<div class="section">
445<h4><a name="a2_Data_file_resides_on_an_HDFS_instance"></a>2) Data file resides on an HDFS instance</h4>
446<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>
447
448<div class="source">
449<div class="source">
450<pre> create external dataset Lineitem(LineitemType)
451 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;));
452</pre></div></div>
453<p>The expected parameters are described below:</p>
454
455<table border="0" class="table table-striped">
456
457<tr class="a">
458
459<td> Parameter </td>
460
461<td> Description </td>
462</tr>
463
464<tr class="b">
465
466<td> hdfs </td>
467
468<td> The HDFS URL </td>
469</tr>
470
471<tr class="a">
472
473<td> path </td>
474
475<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>
476
477<tr class="b">
478
479<td> input-format </td>
480
481<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>
482</tr>
483
484<tr class="a">
485
486<td> format </td>
487
488<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>
489</tr>
490
491<tr class="b">
492
493<td> delimiter </td>
494
495<td> The delimiting character in the source file if format is 'delimited text' </td>
496</tr>
497
498<tr class="a">
499
500<td> parser </td>
501
502<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>
503</tr>
504
505<tr class="b">
506
507<td> hive-serde </td>
508
509<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>
510</tr>
511
512<tr class="a">
513
514<td> local-socket-path </td>
515
516<td> The UNIX domain socket path if local short-circuit reads are enabled in the HDFS instance</td>
517</tr>
518</table>
519<p><i>Difference between &#x2018;input-format&#x2019; and &#x2018;format&#x2019;</i></p>
520<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>
521<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>
522<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>
523<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>
524<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>
525<div class="section">
526<h4><a name="Using_the_Hive_Parser"></a>Using the Hive Parser</h4>
527<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>
528
529<table border="0" class="table table-striped">
530
531<tr class="a">
532
533<td> Hive </td>
534
535<td> AsterixDB </td>
536</tr>
537
538<tr class="b">
539
540<td>BOOLEAN</td>
541
542<td>Boolean</td>
543</tr>
544
545<tr class="a">
546
547<td>BYTE(TINY INT)</td>
548
549<td>Int8</td>
550</tr>
551
552<tr class="b">
553
554<td>DOUBLE</td>
555
556<td>Double</td>
557</tr>
558
559<tr class="a">
560
561<td>FLOAT</td>
562
563<td>Float</td>
564</tr>
565
566<tr class="b">
567
568<td>INT</td>
569
570<td>Int32</td>
571</tr>
572
573<tr class="a">
574
575<td>LONG(BIG INT)</td>
576
577<td>Int64</td>
578</tr>
579
580<tr class="b">
581
582<td>SHORT(SMALL INT)</td>
583
584<td>Int16</td>
585</tr>
586
587<tr class="a">
588
589<td>STRING</td>
590
591<td>String</td>
592</tr>
593
594<tr class="b">
595
596<td>TIMESTAMP</td>
597
598<td>Datetime</td>
599</tr>
600
601<tr class="a">
602
603<td>DATE</td>
604
605<td>Date</td>
606</tr>
607
608<tr class="b">
609
610<td>STRUCT</td>
611
612<td>Nested Object</td>
613</tr>
614
615<tr class="a">
616
617<td>LIST</td>
618
619<td>OrderedList or UnorderedList</td>
620</tr>
621</table></div>
622<div class="section">
623<h4><a name="Examples_of_dataset_definitions_for_external_datasets"></a>Examples of dataset definitions for external datasets</h4>
624<p><i>Example 1</i>: We can modify the create external dataset statement as follows:</p>
625
626<div class="source">
627<div class="source">
628<pre> create external dataset Lineitem('LineitemType)
629 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;));
630</pre></div></div>
631<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>
632
633<div class="source">
634<div class="source">
635<pre> create external dataset Lineitem('LineitemType)
636 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;));
637</pre></div></div>
638<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>
639
640<div class="source">
641<div class="source">
642<pre> create external dataset Lineitem('LineitemType)
643 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;));
644</pre></div></div></div></div></div>
645<div class="section">
646<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>
647<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>
648
649<div class="source">
650<div class="source">
651<pre> use dataverse ExternalFileDemo;
652
653 for $c in dataset('Lineitem')
654 where $c.l_orderkey &lt;= 3
655 order by $c.l_orderkey, $c.l_linenumber
656 return $c
657</pre></div></div></div>
658<div class="section">
659<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>
660<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>
661
662<div class="source">
663<div class="source">
664<pre> create external dataset Lineitem(LineitemType)
665 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;));
666</pre></div></div>
667<p>You can then create a B-Tree index on this dataset instance as if the dataset was internally stored as follows:</p>
668
669<div class="source">
670<div class="source">
671<pre> create index PartkeyIdx on Lineitem(l_partkey);
672</pre></div></div>
673<p>You could also create an R-Tree index as follows:</p>
674
675<div class="source">
676<div class="source">
677<pre> &#xfffc;create index IndexName on DatasetName(attribute-name) type rtree;
678</pre></div></div>
679<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>
680<div class="section">
681<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>
682<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>
683
684<div class="source">
685<div class="source">
686<pre> refresh external dataset DatasetName;
687</pre></div></div>
688<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>
689<div class="section">
690<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>
691<p>Q. I added data to my dataset in HDFS, Will the dataset indexes in AsterixDB be updated automatically?</p>
692<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>
693<p>Q. Why doesn&#x2019;t AsterixDB update external indexes automatically?</p>
694<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>
695<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>
696<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>
697<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>
698<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>
699<p>Q. I submitted a refresh command on a an external dataset and a failure occurred, What has happened to my indexes?</p>
700<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>
701<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>
702<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>
703<p>Q. What happens when I try to create an additional index while a refresh operation is in progress or vice versa?</p>
704<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>
705 </div>
706 </div>
707 </div>
708
709 <hr/>
710
711 <footer>
712 <div class="container-fluid">
713 <div class="row span12">Copyright &copy; 2017
714 <a href="https://www.apache.org/">The Apache Software Foundation</a>.
715 All Rights Reserved.
716
717 </div>
718
719 <?xml version="1.0" encoding="UTF-8"?>
720<div class="row-fluid">Apache AsterixDB, AsterixDB, Apache, the Apache
721 feather logo, and the Apache AsterixDB project logo are either
722 registered trademarks or trademarks of The Apache Software
723 Foundation in the United States and other countries.
724 All other marks mentioned may be trademarks or registered
725 trademarks of their respective owners.</div>
726
727
728 </div>
729 </footer>
730 </body>
731</html>