Return-Path: X-Original-To: apmail-asterixdb-commits-archive@minotaur.apache.org Delivered-To: apmail-asterixdb-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7641F18384 for ; Fri, 25 Mar 2016 23:32:16 +0000 (UTC) Received: (qmail 53291 invoked by uid 500); 25 Mar 2016 23:32:16 -0000 Delivered-To: apmail-asterixdb-commits-archive@asterixdb.apache.org Received: (qmail 53251 invoked by uid 500); 25 Mar 2016 23:32:16 -0000 Mailing-List: contact commits-help@asterixdb.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@asterixdb.incubator.apache.org Delivered-To: mailing list commits@asterixdb.incubator.apache.org Received: (qmail 53242 invoked by uid 99); 25 Mar 2016 23:32:16 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Mar 2016 23:32:16 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id BB632C021F for ; Fri, 25 Mar 2016 23:32:15 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.22 X-Spam-Level: X-Spam-Status: No, score=-1.22 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_BADIPHTTP=2, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, WEIRD_PORT=0.001] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id WVZhvz3OK0h7 for ; Fri, 25 Mar 2016 23:32:02 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with SMTP id 42B8D5FB2A for ; Fri, 25 Mar 2016 23:31:57 +0000 (UTC) Received: (qmail 51984 invoked by uid 99); 25 Mar 2016 23:31:55 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Mar 2016 23:31:55 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D68A5DFBA3; Fri, 25 Mar 2016 23:31:55 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: buyingyi@apache.org To: commits@asterixdb.incubator.apache.org Date: Fri, 25 Mar 2016 23:32:09 -0000 Message-Id: <3777e599e8a948549f24d167ad6c2779@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [15/30] incubator-asterixdb-site git commit: Add the documentation for release-0.8.8. http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-site/blob/08953b2e/docs/0.8.8-incubating/aql/allens.html ---------------------------------------------------------------------- diff --git a/docs/0.8.8-incubating/aql/allens.html b/docs/0.8.8-incubating/aql/allens.html new file mode 100644 index 0000000..b4dbbb3 --- /dev/null +++ b/docs/0.8.8-incubating/aql/allens.html @@ -0,0 +1,660 @@ + + + + + + + + + AsterixDB – AsterixDB Temporal Functions: Allens Relations + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + + +
+ +

AsterixDB Temporal Functions: Allen’s Relations

+ +
+

About Allen’s Relations [Back to TOC]

+

AsterixDB supports Allen’s relations over interval types. Allen’s relations are also called Allen’s interval algebra. There are totally 13 base relations described by this algebra, and all of them are supported in AsterixDB (note that interval-equals is supported by the = comparison symbol so there is no extra function for it).

+

A detailed description of Allen’s relations can be found from its wikipedia entry.

+
+

Allen’s Relations Functions [Back to TOC]

+
+

interval-before, interval-after

+ +
    + +
  • +

    Syntax:

    + +
    +
    +
    interval-before(interval1, interval2)
    +interval-after(interval1, interval2)
    +
  • + +
  • +

    These two functions check whether an interval happens before/after another interval.

  • + +
  • Arguments: + +
      + +
    • interval1, interval2: two intervals to be compared
    • +
  • + +
  • +

    Return Value:

    +

    A boolean value. Specifically, interval-before(interval1, interval2) is true if and only if interval1.end < interval2.start, and interval-after(interval1, interval2) is true if and only if interval1.start > interval2.end. If any of the two inputs is null, null is returned.

  • + +
  • +

    Examples:

    + +
    +
    +
    let $itv1 := interval-from-date("2000-01-01", "2005-01-01")
    +let $itv2 := interval-from-date("2005-05-01", "2012-09-09")
    +return {"interval-before": interval-before($itv1, $itv2), "interval-after": interval-after($itv2, $itv1)}
    +
  • + +
  • +

    The expected result is:

    + +
    +
    +
    { "interval-before": true, "interval-after": true }
    +
  • +
+
+

interval-covers, interval-covered-by

+ +
    + +
  • +

    Syntax:

    + +
    +
    +
    interval-covers(interval1, interval2)
    +interval-covered-by(interval1, interval2)
    +
  • + +
  • +

    These two functions check whether one interval covers the other interval.

  • + +
  • Arguments: + +
      + +
    • interval1, interval2: two intervals to be compared
    • +
  • + +
  • +

    Return Value:

    +

    A boolean value. Specifically, interval-covers(interval1, interval2) is true if and only if

    + +
    +
    +
    interval1.start <= interval2.start
    +AND interval1.end >= interval2.end
    +
    +

    interval-covered-by(interval1, interval2) is true if and only if

    + +
    +
    +
    interval2.start <= interval1.start
    +AND interval2.end >= interval1.end
    +
    +

    For both functions, if any of the two inputs is null, null is returned.

  • + +
  • +

    Examples:

    + +
    +
    +
    let $itv1 := interval-from-date("2000-01-01", "2005-01-01")
    +let $itv2 := interval-from-date("2000-03-01", "2004-09-09")
    +let $itv3 := interval-from-date("2006-08-01", "2007-03-01")
    +let $itv4 := interval-from-date("2004-09-10", "2012-08-01")
    +return {"interval-covers": interval-covers($itv1, $itv2), "interval-covered-by": interval-covered-by($itv3, $itv4)}
    +
  • + +
  • +

    The expected result is:

    + +
    +
    +
    { "interval-covers": true, "interval-covered-by": true }
    +
  • +
+
+

interval-overlaps, interval-overlapped-by

+ +
    + +
  • +

    Syntax:

    + +
    +
    +
    interval-overlaps(interval1, interval2)
    +interval-overlapped-by(interval1, interval2)
    +
  • + +
  • +

    These functions check whether two intervals overlap with each other.

  • + +
  • Arguments: + +
      + +
    • interval1, interval2: two intervals to be compared
    • +
  • + +
  • +

    Return Value:

    +

    A boolean value. Specifically, interval-overlaps(interval1, interval2) is true if and only if

    + +
    +
    +
    interval1.start < interval2.start
    +AND interval2.end > interval1.end
    +AND interval1.end > interval2.start
    +
    +

    interval-overlapped-by(interval1, interval2) is true if and only if

    + +
    +
    +
    interval2.start < interval1.start
    +AND interval1.end > interval2.end
    +AND interval2.end > interval1.start
    +
    +

    For all these functions, if any of the two inputs is null, null is returned.

    +

    Note that interval-overlaps and interval-overlapped-by are following the Allen’s relations on the definition of overlap.

  • + +
  • +

    Examples:

    + +
    +
    +
    let $itv1 := interval-from-date("2000-01-01", "2005-01-01")
    +let $itv2 := interval-from-date("2004-05-01", "2012-09-09")
    +let $itv3 := interval-from-date("2006-08-01", "2007-03-01")
    +let $itv4 := interval-from-date("2004-09-10", "2006-12-31")
    +return {"overlaps": interval-overlaps($itv1, $itv2), 
    +        "overlapped-by": interval-overlapped-by($itv3, $itv4)}
    +
  • + +
  • +

    The expected result is:

    + +
    +
    +
    { "overlaps": true, "overlapped-by": true }
    +
  • +
+
+

interval-overlapping

+

Note that interval-overlapping is not an Allen’s Relation, but syntactic sugar we added for the case that the intersect of two intervals is not empty. Basically this function returns true if any of these functions return true: interval-overlaps, interval-overlapped-by, interval-covers, or interval-covered-by.

+ +
    + +
  • +

    Syntax:

    + +
    +
    +
    interval-overlapping(interval1, interval2)
    +
  • + +
  • +

    This functions check whether two intervals share any points with each other.

  • + +
  • Arguments: + +
      + +
    • interval1, interval2: two intervals to be compared
    • +
  • + +
  • +

    Return Value:

    +

    A boolean value. Specifically, interval-overlapping(interval1, interval2) is true if

    + +
    +
    +
    (interval2.start >= interval1.start
    +AND interval2.start < interval1.end)
    +OR
    +(interval2.end > interval1.start
    +AND interval2.end <= interval1.end)
    +
    +

    If any of the two inputs is null, null is returned.

  • + +
  • +

    Examples:

    + +
    +
    +
    let $itv1 := interval-from-date("2000-01-01", "2005-01-01")
    +let $itv2 := interval-from-date("2004-05-01", "2012-09-09")
    +let $itv3 := interval-from-date("2006-08-01", "2007-03-01")
    +let $itv4 := interval-from-date("2004-09-10", "2006-12-31")
    +return {"overlapping1": interval-overlapping($itv1, $itv2), 
    +        "overlapping2": interval-overlapping($itv3, $itv4)}
    +
  • + +
  • +

    The expected result is:

    + +
    +
    +
    { "overlapping1": true, "overlapping2": true }
    +
  • +
+
+

interval-meets, interval-met-by

+ +
    + +
  • +

    Syntax:

    + +
    +
    +
    interval-meets(interval1, interval2)
    +interval-met-by(interval1, interval2)
    +
  • + +
  • +

    These two functions check whether an interval meets with another interval.

  • + +
  • Arguments: + +
      + +
    • interval1, interval2: two intervals to be compared
    • +
  • + +
  • +

    Return Value:

    +

    A boolean value. Specifically, interval-meets(interval1, interval2) is true if and only if interval1.end = interval2.start, and interval-met-by(interval1, interval2) is true if and only if interval1.start = interval2.end. If any of the two inputs is null, null is returned.

  • + +
  • +

    Examples:

    + +
    +
    +
    let $itv1 := interval-from-date("2000-01-01", "2005-01-01")
    +let $itv2 := interval-from-date("2005-01-01", "2012-09-09")
    +let $itv3 := interval-from-date("2006-08-01", "2007-03-01")
    +let $itv4 := interval-from-date("2004-09-10", "2006-08-01")
    +return {"meets": interval-meets($itv1, $itv2), "metby": interval-met-by($itv3, $itv4)}
    +
  • + +
  • +

    The expected result is:

    + +
    +
    +
    { "meets": true, "metby": true }
    +
  • +
+
+

interval-starts, interval-started-by

+ +
    + +
  • +

    Syntax:

    + +
    +
    +
    interval-starts(interval1, interval2)
    +interval-started-by(interval1, interval2)
    +
  • + +
  • +

    These two functions check whether one interval starts with the other interval.

  • + +
  • Arguments: + +
      + +
    • interval1, interval2: two intervals to be compared
    • +
  • + +
  • +

    Return Value:

    +

    A boolean value. Specifically, interval-starts(interval1, interval2) returns true if and only if

    + +
    +
    +
    interval1.start = interval2.start
    +AND interval1.end <= interval2.end
    +
    +

    interval-started-by(interval1, interval2) returns true if and only if

    + +
    +
    +
    interval1.start = interval2.start
    +AND interval2.end <= interval1.end
    +
    +

    For both functions, if any of the two inputs is null, null is returned.

  • + +
  • +

    Examples:

    + +
    +
    +
    let $itv1 := interval-from-date("2000-01-01", "2005-01-01")
    +let $itv2 := interval-from-date("2000-01-01", "2012-09-09")
    +let $itv3 := interval-from-date("2006-08-01", "2007-03-01")
    +let $itv4 := interval-from-date("2006-08-01", "2006-08-01")
    +return {"interval-starts": interval-starts($itv1, $itv2), "interval-started-by": interval-started-by($itv3, $itv4)}
    +
  • + +
  • +

    The expected result is:

    + +
    +
    +
    { "interval-starts": true, "interval-started-by": true }
    +
  • +
+
+

interval-ends, interval-ended-by

+ +
    + +
  • +

    Syntax:

    + +
    +
    +
    interval-ends(interval1, interval2)
    +interval-ended-by(interval1, interval2)
    +
  • + +
  • +

    These two functions check whether one interval ends with the other interval.

  • + +
  • Arguments: + +
      + +
    • interval1, interval2: two intervals to be compared
    • +
  • + +
  • +

    Return Value:

    +

    A boolean value. Specifically, interval-ends(interval1, interval2) returns true if and only if

    + +
    +
    +
    interval1.end = interval2.end
    +AND interval1.start >= interval2.start
    +
    +

    interval-ended-by(interval1, interval2) returns true if and only if

    + +
    +
    +
    interval2.end = interval1.end
    +AND interval2.start >= interval1.start
    +
    +

    For both functions, if any of the two inputs is null, null is returned.

  • + +
  • +

    Examples:

    + +
    +
    +
    let $itv1 := interval-from-date("2000-01-01", "2005-01-01")
    +let $itv2 := interval-from-date("1998-01-01", "2005-01-01")
    +let $itv3 := interval-from-date("2006-08-01", "2007-03-01")
    +let $itv4 := interval-from-date("2006-09-10", "2007-03-01")
    +return {"interval-ends": interval-ends($itv1, $itv2), "interval-ended-by": interval-ended-by($itv3, $itv4) }
    +
  • + +
  • +

    The expected result is:

    + +
    +
    +
    { "interval-ends": true, "interval-ended-by": true }
    +
  • +
+
+
+
+ +
+ +
+
+
Copyright © 2016 + The Apache Software Foundation. + All Rights Reserved. + +
+ + +
Apache AsterixDB, AsterixDB, Apache, the Apache + feather logo, and the Apache AsterixDB project logo are either + registered trademarks or trademarks of The Apache Software + Foundation in the United States and other countries. + All other marks mentioned may be trademarks or registered + trademarks of their respective owners.
+ + +
+
+ + http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-site/blob/08953b2e/docs/0.8.8-incubating/aql/datamodel.html ---------------------------------------------------------------------- diff --git a/docs/0.8.8-incubating/aql/datamodel.html b/docs/0.8.8-incubating/aql/datamodel.html new file mode 100644 index 0000000..b72617f --- /dev/null +++ b/docs/0.8.8-incubating/aql/datamodel.html @@ -0,0 +1,783 @@ + + + + + + + + + AsterixDB – Asterix Data Model (ADM) + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + + +
+ +

Asterix Data Model (ADM)

+
+

Table of Contents

+ + +

An instance of Asterix data model (ADM) can be a primitive type (int32, int64, string, float, double, date, time, datetime, etc. or null) or a derived type.

+
+

Primitive Types [Back to TOC]

+
+

Boolean[Back to TOC]

+

boolean data type can have one of the two values: true or false.

+ +
    + +
  • +

    Example:

    + +
    +
    +
    let $t := true
    +let $f := false
    +return { "true": $t, "false": $f }
    +
  • +
+ +
    + +
  • +

    The expected result is:

    + +
    +
    +
    { "true": true, "false": false }
    +
  • +
+
+

Int8 / Int16 / Int32 / Int64 [Back to TOC]

+

Integer types using 8, 16, 32, or 64 bits. The ranges of these types are:

+ +
    + +
  • int8: -127 to 127
  • + +
  • int16: -32767 to 32767
  • + +
  • int32: -2147483647 to 2147483647
  • + +
  • int64: -9223372036854775808 to 9223372036854775807
  • + +
  • +

    Example:

    + +
    +
    +
    let $v8 := int8("125")
    +let $v16 := int16("32765")
    +let $v32 := 294967295
    +let $v64 := int64("1700000000000000000")
    +return { "int8": $v8, "int16": $v16, "int32": $v32, "int64": $v64}
    +
  • +
+ +
    + +
  • +

    The expected result is:

    + +
    +
    +
    { "int8": 125i8, "int16": 32765i16, "int32": 294967295, "int64": 1700000000000000000i64 }
    +
  • +
+
+

Float [Back to TOC]

+

float represents approximate numeric data values using 4 bytes. The range of a float value can be from 2^(-149) to (2-2^(-23)·2^(127) for both positive and negative. Beyond these ranges will get INF or -INF.

+ +
    + +
  • +

    Example:

    + +
    +
    +
    let $v1 := float("NaN")
    +let $v2 := float("INF")
    +let $v3 := float("-INF")
    +let $v4 := float("-2013.5")
    +return { "v1": $v1, "v2": $v2, "v3": $v3, "v4": $v4 }
    +
  • +
+ +
    + +
  • +

    The expected result is:

    + +
    +
    +
    { "v1": NaNf, "v2": Infinityf, "v3": -Infinityf, "v4": -2013.5f }
    +
  • +
+
+

Double [Back to TOC]

+

double represents approximate numeric data values using 8 bytes. The range of a double value can be from (2^(-1022)) to (2-2^(-52))·2^(1023) for both positive and negative. Beyond these ranges will get INF or -INF.

+ +
    + +
  • +

    Example:

    + +
    +
    +
    let $v1 := double("NaN")
    +let $v2 := double("INF")
    +let $v3 := double("-INF")
    +let $v4 := double("-2013.593823748327284")
    +return { "v1": $v1, "v2": $v2, "v3": $v3, "v4": $v4 }
    +
  • +
+ +
    + +
  • +

    The expected result is:

    + +
    +
    +
    { "v1": NaNd, "v2": Infinityd, "v3": -Infinityd, "v4": -2013.5938237483274d }
    +
  • +
+
+

String [Back to TOC]

+

string represents a sequence of characters.

+ +
    + +
  • +

    Example:

    + +
    +
    +
    let $v1 := string("This is a string.")
    +let $v2 := string("\"This is a quoted string\"")
    +return { "v1": $v1, "v2": $v2 }
    +
  • +
+ +
    + +
  • +

    The expected result is:

    + +
    +
    +
    { "v1": "This is a string.", "v2": "\"This is a quoted string\"" }
    +
  • +
+
+

Point [Back to TOC]

+

point is the fundamental two-dimensional building block for spatial types. It consists of two double coordinates x and y.

+ +
    + +
  • +

    Example:

    + +
    +
    +
    let $v1 := point("80.10d, -10E5")
    +let $v2 := point("5.10E-10d, -10E5")
    +return { "v1": $v1, "v2": $v2 }
    +
  • +
+ +
    + +
  • +

    The expected result is:

    + +
    +
    +
    { "v1": point("80.1,-1000000.0"), "v2": point("5.1E-10,-1000000.0") }
    +
  • +
+
+

Line [Back to TOC]

+

line consists of two points that represent the start and the end points of a line segment.

+ +
    + +
  • +

    Example:

    + +
    +
    +
    let $v1 := line("10.1234,11.1e-1 +10.2E-2,-11.22")
    +let $v2 := line("0.1234,-1.00e-10 +10.5E-2,-01.02")
    +return { "v1": $v1, "v2": $v2 }
    +
  • +
+ +
    + +
  • +

    The expected result is:

    + +
    +
    +
    { "v1": line("10.1234,1.11 0.102,-11.22"), "v2": line("0.1234,-1.0E-10 0.105,-1.02") }
    +
  • +
+
+

Rectangle[Back to TOC]

+

rectangle consists of two points that represent the bottom left and upper right corners of a rectangle.

+ +
    + +
  • +

    Example:

    + +
    +
    +
    let $v1 := rectangle("5.1,11.8 87.6,15.6548")
    +let $v2 := rectangle("0.1234,-1.00e-10 5.5487,0.48765")
    +return { "v1": $v1, "v2": $v2 }
    +
  • +
+ +
    + +
  • +

    The expected result is:

    + +
    +
    +
    { "v1": rectangle("5.1,11.8 87.6,15.6548"), "v2": rectangle("0.1234,-1.0E-10 5.5487,0.48765") }
    +
  • +
+
+

Circle[Back to TOC]

+

circle consists of one point that represents the center of the circle and a radius of type double.

+ +
    + +
  • +

    Example:

    + +
    +
    +
    let $v1 := circle("10.1234,11.1e-1 +10.2E-2")
    +let $v2 := circle("0.1234,-1.00e-10 +10.5E-2")
    +return { "v1": $v1, "v2": $v2 }
    +
  • +
+ +
    + +
  • +

    The expected result is:

    + +
    +
    +
    { "v1": circle("10.1234,1.11 0.102"), "v2": circle("0.1234,-1.0E-10 0.105") }
    +
  • +
+
+

Polygon[Back to TOC]

+

polygon consists of n points that represent the vertices of a simple closed polygon.

+ +
    + +
  • +

    Example:

    + +
    +
    +
    let $v1 := polygon("-1.2,+1.3e2 -2.14E+5,2.15 -3.5e+2,03.6 -4.6E-3,+4.81")
    +let $v2 := polygon("-1.0,+10.5e2 -02.15E+50,2.5 -1.0,+3.3e3 -2.50E+05,20.15 +3.5e+2,03.6 -4.60E-3,+4.75 -2,+1.0e2 -2.00E+5,20.10 30.5,03.25 -4.33E-3,+4.75")
    +return { "v1": $v1, "v2": $v2 }
    +
  • +
+ +
    + +
  • +

    The expected result is:

    + +
    +
    +
    { "v1": polygon("-1.2,130.0 -214000.0,2.15 -350.0,3.6 -0.0046,4.81"), "v2": polygon("-1.0,1050.0 -2.15E50,2.5 -1.0,3300.0 -250000.0,20.15 350.0,3.6 -0.0046,4.75 -2.0,100.0 -200000.0,20.1 30.5,3.25 -0.00433,4.75") }
    +
  • +
+
+

Date[Back to TOC]

+

date represents a time point along the Gregorian calendar system specified by the year, month and day. ASTERIX supports the date from -9999-01-01 to 9999-12-31.

+

A date value can be represented in two formats, extended format and basic format.

+ +
    + +
  • Extended format is represented as [-]yyyy-mm-dd for year-month-day. Each field should be padded if there are less digits than the format specified.
  • + +
  • Basic format is in the format of [-]yyyymmdd.
  • + +
  • +

    Example:

    + +
    +
    +
    let $v1 := date("2013-01-01")
    +let $v2 := date("-19700101")
    +return { "v1": $v1, "v2": $v2 }
    +
  • +
+ +
    + +
  • +

    The expected result is:

    + +
    +
    +
    { "v1": date("2013-01-01"), "v2": date("-1970-01-01") }
    +
  • +
+
+

Time[Back to TOC]

+

time type describes the time within the range of a day. It is represented by three fields: hour, minute and second. Millisecond field is optional as the fraction of the second field. Its extended format is as hh:mm:ss[.mmm] and the basic format is hhmmss[mmm]. The value domain is from 00:00:00.000 to 23:59:59.999.

+

Timezone field is optional for a time value. Timezone is represented as [+|-]hh:mm for extended format or [+|-]hhmm for basic format. Note that the sign designators cannot be omitted. Z can also be used to represent the UTC local time. If no timezone information is given, it is UTC by default.

+ +
    + +
  • +

    Example:

    + +
    +
    +
    let $v1 := time("12:12:12.039Z")
    +let $v2 := time("000000000-0800")
    +return { "v1": $v1, "v2": $v2 }
    +
  • +
+ +
    + +
  • +

    The expected result is:

    + +
    +
    +
    { "v1": time("12:12:12.039Z"), "v2": time("08:00:00.000Z") }
    +
  • +
+
+

Datetime[Back to TOC]

+

A datetime value is a combination of an date and time, representing a fixed time point along the Gregorian calendar system. The value is among -9999-01-01 00:00:00.000 and 9999-12-31 23:59:59.999.

+

A datetime value is represented as a combination of the representation of its date part and time part, separated by a separator T. Either extended or basic format can be used, and the two parts should be the same format.

+

Millisecond field and timezone field are optional, as specified in the time type.

+ +
    + +
  • +

    Example:

    + +
    +
    +
    let $v1 := datetime("2013-01-01T12:12:12.039Z")
    +let $v2 := datetime("-19700101T000000000-0800")
    +return { "v1": $v1, "v2": $v2 }
    +
  • +
+ +
    + +
  • +

    The expected result is:

    + +
    +
    +
    { "v1": datetime("2013-01-01T12:12:12.039Z"), "v2": datetime("-1970-01-01T08:00:00.000Z") }
    +
  • +
+
+

Duration/Year-month-duration/Day-time-duration[Back to TOC]

+

duration represents a duration of time. A duration value is specified by integers on at least one of the following fields: year, month, day, hour, minute, second, and millisecond.

+

A duration value is in the format of [-]PnYnMnDTnHnMn.mmmS. The millisecond part (as the fraction of the second field) is optional, and when no millisecond field is used, the decimal point should also be absent.

+

Negative durations are also supported for the arithmetic operations between time instance types (date, time and datetime), and is used to roll the time back for the given duration. For example date("2012-01-01") + duration("-P3D") will return date("2011-12-29").

+

There are also two sub-duration types, namely year-month-duration and day-time-duration. year-month-duration represents only the years and months of a duration, while day-time-duration represents only the day to millisecond fields. Different from the duration type, both these two subtypes are totally ordered, so they can be used for comparison and index construction.

+

Note that a canonical representation of the duration is always returned, regardless whether the duration is in the canonical representation or not from the user’s input. More information about canonical representation can be found from XPath dayTimeDuration Canonical Representation and yearMonthDuration Canonical Representation.

+ +
    + +
  • +

    Example:

    + +
    +
    +
    let $v1 := duration("P100Y12MT12M")
    +let $v2 := duration("-PT20.943S")
    +return { "v1": $v1, "v2": $v2 }
    +
  • +
+ +
    + +
  • +

    The expected result is:

    + +
    +
    +
    { "v1": duration("P101YT12M"), "v2": duration("-PT20.943S") }
    +
  • +
+
+

Interval[Back to TOC]

+

interval represents inclusive-exclusive ranges of time. It is defined by two time point values with the same temporal type(date, time or datetime).

+ +
    + +
  • +

    Example:

    + +
    +
    +
    let $v1 := interval-from-date(date("2013-01-01"), date("20130505"))
    +let $v2 := interval-from-time(time("00:01:01"), time("213901049+0800"))
    +let $v3 := interval-from-datetime(datetime("2013-01-01T00:01:01"), datetime("20130505T213901049+0800"))
    +return { "v1": $v1, "v2": $v2, "v3": $v3 }
    +
  • +
+ +
    + +
  • +

    The expected result is:

    + +
    +
    +
    { "v1": interval-date("2013-01-01, 2013-05-05"), "v2": interval-time("00:01:01.000Z, 13:39:01.049Z"), "v3": interval-datetime("2013-01-01T00:01:01.000Z, 2013-05-05T13:39:01.049Z") }
    +
  • +
+
+

UUID[Back to TOC]

+

uuid represents a UUID value, which stands for Universally unique identifier. It is defined by a canonical format using hexadecimal text with inserted hyphen characters. (E.g.: 5a28ce1e-6a74-4201-9e8f-683256e5706f). This type is generally used to store auto-generated primary key values.

+ +
    + +
  • +

    Example:

    + +
    +
    +
    let $v1 := uuid("5c848e5c-6b6a-498f-8452-8847a2957421")
    +return { "v1":$v1 }
    +
  • +
+ +
    + +
  • +

    The expected result is:

    + +
    +
    +
    { "v1": uuid("5c848e5c-6b6a-498f-8452-8847a2957421") }
    +
  • +
+
+

Derived Types[Back to TOC]

+
+

Record[Back to TOC]

+

A record contains a set of fields, where each field is described by its name and type. A record type is either open or closed. Open records can contain fields that are not part of the type definition, while closed records cannot. Syntactically, record constructors are surrounded by curly braces “{…}”.

+

An example would be

+ +
+
+
    { "id": 213508, "name": "Alice Bob" }
+
+
+

OrderedList[Back to TOC]

+

An orderedList is a sequence of values for which the order is determined by creation or insertion. OrderedList constructors are denoted by brackets: “[…]”.

+

An example would be

+ +
+
+
    ["alice", 123, "bob", null]
+
+
+

UnorderedList[Back to TOC]

+

An unorderedList is an unordered sequence of values, similar to bags in SQL. UnorderedList constructors are denoted by two opening flower braces followed by data and two closing flower braces, like “{{…}}”.

+

An example would be

+ +
+
+
    {{"hello", 9328, "world", [1, 2, null]}}
+
+
+
+
+ +
+ +
+
+
Copyright © 2016 + The Apache Software Foundation. + All Rights Reserved. + +
+ + +
Apache AsterixDB, AsterixDB, Apache, the Apache + feather logo, and the Apache AsterixDB project logo are either + registered trademarks or trademarks of The Apache Software + Foundation in the United States and other countries. + All other marks mentioned may be trademarks or registered + trademarks of their respective owners.
+ + +
+
+ + http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-site/blob/08953b2e/docs/0.8.8-incubating/aql/externaldata.html ---------------------------------------------------------------------- diff --git a/docs/0.8.8-incubating/aql/externaldata.html b/docs/0.8.8-incubating/aql/externaldata.html new file mode 100644 index 0000000..1266cb8 --- /dev/null +++ b/docs/0.8.8-incubating/aql/externaldata.html @@ -0,0 +1,633 @@ + + + + + + + + + AsterixDB – Accessing External Data in AsterixDB + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + + +
+ +

Accessing External Data in AsterixDB

+ +
+

Introduction [Back to TOC]

+

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 ‘‘external datasets’’ so that it is not necessary to “load” all data prior to using it. This also avoids creating multiple copies of data and the need to keep the copies in sync.

+
+

Adapter for an External Dataset [Back to TOC]

+

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.

+
+

Creating an External Dataset [Back to TOC]

+

As an example we consider the Lineitem dataset from the TPCH schema. We assume that you have successfully created an AsterixDB instance following the instructions at Installing AsterixDB Using Managix. For constructing an example, we assume a single machine setup..

+

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 http://127.0.0.1:19001 and hit ‘Execute’.

+ +
+
+
    create dataverse ExternalFileDemo;
+    use dataverse ExternalFileDemo;
+
+    create type LineitemType as closed {
+      l_orderkey:int32,
+      l_partkey: int32,
+      l_suppkey: int32,
+      l_linenumber: int32,
+      l_quantity: double,
+      l_extendedprice: double,
+      l_discount: double,
+      l_tax: double,
+      l_returnflag: string,
+      l_linestatus: string,
+      l_shipdate: string,
+      l_commitdate: string,
+      l_receiptdate: string,
+      l_shipinstruct: string,
+      l_shipmode: string,
+      l_comment: string}
+
+

Here, we describe two scenarios.

+
+

1) Data file resides on the local file system of a host

+

Prerequisite: The host is a part of the ASTERIX cluster.

+

Earlier, we assumed a single machine ASTERIX setup. To satisfy the prerequisite, log-in to the machine running ASTERIX.

+ +
    + +
  • Download the data file to an appropriate location. We denote this location by SOURCE_PATH.
  • +
+

ASTERIX provides a built-in adapter for data residing on the local file system. The adapter is referred by its alias- ‘localfs’. We create an external dataset named Lineitem and use the ‘localfs’ adapter.

+ +
+
+
    create external dataset Lineitem(LineitemType)
+    using localfs
+
+

Above, the definition is not complete as we need to provide a set of parameters that are specific to the source file.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Parameter Description
path A fully qualified path of the form host://<absolute path>. + Use a comma separated list if there are multiple files. + E.g. host1://<absolute path>, host2://<absolute path> and so forth.
format The format for the content. Use 'adm' for data in ADM (ASTERIX Data Model) or JSON format. Use 'delimited-text' if fields are separated by a delimiting character (eg., CSV).
delimiterThe delimiting character in the source file if format is 'delimited text'
+

As we are using a single single machine ASTERIX instance, we use 127.0.0.1 as host in the path parameter. We complete the create dataset statement as follows.

+ +
+
+
    use dataverse ExternalFileDemo;
+
+    create external dataset Lineitem(LineitemType)
+    using localfs
+    (("path"="127.0.0.1://SOURCE_PATH"),
+    ("format"="delimited-text"),
+    ("delimiter"="|"));
+
+

Please substitute SOURCE_PATH with the absolute path to the source file on the local file system.

+
+

Common source of error

+

An incorrect value for the path parameter will give the following exception message when the dataset is used in a query.

+ +
+
+
    org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: org.apache.hyracks.api.exceptions.HyracksDataException: org.apache.hyracks.api.exceptions.HyracksDataException: Job failed.
+
+

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

+ +
+
+
    127.0.0.1:///home/joe/lineitem.tbl.
+
+

In your web-browser, navigate to 127.0.0.1:19001 and paste the above to the query text box. Finally hit ‘Execute’.

+

Next we move over to the the section Writing Queries against an External Dataset and try a sample query against the external dataset.

+
+

2) Data file resides on an HDFS instance

+

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 - ‘hdfs’. We can create an external dataset named Lineitem and associate the HDFS adapter with it as follows;

+ +
+
+
    create external dataset Lineitem(LineitemType) 
+    using hdfs((“hdfs”:”hdfs://localhost:54310”),(“path”:”/asterix/Lineitem.tbl”),...,(“input- format”:”rc-format”));
+
+

The expected parameters are described below:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Parameter Description
hdfs The HDFS URL
path The absolute path to the source HDFS file or directory. Use a comma separated list if there are multiple files or directories.
input-format 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.
format The format of the input content. Use 'adm' for text data in ADM (ASTERIX Data Model) or JSON format, 'delimited-text' for text delimited data that has fields separated by a delimiting character, 'binary' for other data.
delimiter The delimiting character in the source file if format is 'delimited text'
parser 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.
hive-serde 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.
local-socket-path The UNIX domain socket path if local short-circuit reads are enabled in the HDFS instance
+

Difference between ‘input-format’ and ‘format’

+

input-format: 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 ‘input-format’ is used to distinguish between these and other HDFS input formats.

+

format: The parameter ‘format’ 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.

+

As an example. consider the data file. The file is a text file with each line representing a record. The fields in each record are separated by the ‘|’ character.

+

We assume the HDFS URL to be hdfs://localhost:54310. We further assume that the example data file is copied to HDFS at a path denoted by “/asterix/Lineitem.tbl”.

+

The complete set of parameters for our example file are as follows. ((“hdfs”=“hdfs://localhost:54310”,(“path”=“/asterix/Lineitem.tbl”),(“input-format”=“text- input-format”),(“format”=“delimited-text”),(“delimiter”=“|”))

+
+

Using the Hive Parser

+

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:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Hive AsterixDB
BOOLEANBoolean
BYTE(TINY INT)Int8
DOUBLEDouble
FLOATFloat
INTInt32
LONG(BIG INT)Int64
SHORT(SMALL INT)Int16
STRINGString
TIMESTAMPDatetime
DATEDate
STRUCTNested Record
LISTOrderedList or UnorderedList
+
+

Examples of dataset definitions for external datasets

+

Example 1: We can modify the create external dataset statement as follows:

+ +
+
+
    create external dataset Lineitem('LineitemType)
+    using hdfs(("hdfs"="hdfs://localhost:54310"),("path"="/asterix/Lineitem.tbl"),("input-format"="text- input-format"),("format"="delimited-text"),("delimiter"="|"));
+
+

Example 2: Here, we create an external dataset of lineitem records stored in sequence files that has content in ADM format:

+ +
+
+
    create external dataset Lineitem('LineitemType) 
+    using hdfs(("hdfs"="hdfs://localhost:54310"),("path"="/asterix/SequenceLineitem.tbl"),("input- format"="sequence-input-format"),("format"="adm"));
+
+

Example 3: 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:

+ +
+
+
    create external dataset Lineitem('LineitemType)
+    using hdfs(("hdfs"="hdfs://localhost:54310"),("path"="/asterix/RCLineitem.tbl"),("input-format"="rc-input-format"),("format"="binary"),("parser"="hive-parser"),("hive- serde"="org.apache.hadoop.hive.serde2.columnar.ColumnarSerde"));
+
+
+

Writing Queries against an External Dataset [Back to TOC]

+

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.

+ +
+
+
    use dataverse ExternalFileDemo;
+
+    for $c in dataset('Lineitem')
+    where $c.l_orderkey <= 3
+    order by $c.l_orderkey, $c.l_linenumber
+    return $c
+
+
+

Building Indexes over External Datasets [Back to TOC]

+

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

+ +
+
+
    create external dataset Lineitem(LineitemType) 
+    using hdfs(("hdfs"="hdfs://localhost:54310"),("path"="/asterix/Lineitem.tbl"),("input-format"="text-input- format"),("format"="delimited-text"),("delimiter"="|"));
+
+

You can then create a B-Tree index on this dataset instance as if the dataset was internally stored as follows:

+ +
+
+
    create index PartkeyIdx on Lineitem(l_partkey);
+
+

You could also create an R-Tree index as follows:

+ +
+
+
    create index IndexName on DatasetName(attribute-name) type rtree;
+
+

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 ‘text-input-format’, ‘sequence-input-format’ or ‘rc-input-format’.

+
+

External Data Snapshots [Back to TOC]

+

An external data snapshot represents the status of a dataset’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:

+ +
+
+
    refresh external dataset DatasetName;
+
+

After a refresh operation commits, all of the dataset’s indexes will reflect the status of the data as of the new snapshot capture time.

+
+

Frequently Asked Questions [Back to TOC]

+

Q. I added data to my dataset in HDFS, Will the dataset indexes in AsterixDB be updated automatically?

+

A. No, you must use the refresh external dataset statement to make the indexes aware of any changes in the dataset files in HDFS.

+

Q. Why doesn’t AsterixDB update external indexes automatically?

+

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.

+

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’t use the index?

+

A. No, queries’ results are access path independent and the stored snapshot is used to determines which data are going to be included when processing queries.

+

Q. I created an index over an external dataset and then deleted some of my dataset’s files in HDFS, Will indexed data access still return the records in deleted files?

+

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.

+

Q. I submitted a refresh command on a an external dataset and a failure occurred, What has happened to my indexes?

+

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.

+

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?

+

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.

+

Q. What happens when I try to create an additional index while a refresh operation is in progress or vice versa?

+

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.

+
+
+
+ +
+ + + +