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