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