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