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