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