Return-Path: X-Original-To: apmail-asterixdb-notifications-archive@minotaur.apache.org Delivered-To: apmail-asterixdb-notifications-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 346D7183EE for ; Fri, 26 Feb 2016 18:53:25 +0000 (UTC) Received: (qmail 17827 invoked by uid 500); 26 Feb 2016 18:53:25 -0000 Delivered-To: apmail-asterixdb-notifications-archive@asterixdb.apache.org Received: (qmail 17795 invoked by uid 500); 26 Feb 2016 18:53:25 -0000 Mailing-List: contact notifications-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 notifications@asterixdb.incubator.apache.org Received: (qmail 17782 invoked by uid 99); 26 Feb 2016 18:53:25 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Feb 2016 18:53:25 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id AC6E7C1030 for ; Fri, 26 Feb 2016 18:53:24 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.126 X-Spam-Level: ** X-Spam-Status: No, score=2.126 tagged_above=-999 required=6.31 tests=[MISSING_HEADERS=1.207, SPF_FAIL=0.919] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id Cn7847Fa8cwa for ; Fri, 26 Feb 2016 18:53:22 +0000 (UTC) Received: from unhygienix.ics.uci.edu (unhygienix.ics.uci.edu [128.195.14.130]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 4A8555FB25 for ; Fri, 26 Feb 2016 18:53:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by unhygienix.ics.uci.edu (Postfix) with ESMTP id 14D8B2419D8; Fri, 26 Feb 2016 10:48:47 -0800 (PST) Date: Fri, 26 Feb 2016 10:48:46 -0800 From: "Yingyi Bu (Code Review)" CC: Jenkins , Till Westmann Reply-To: buyingyi@gmail.com X-Gerrit-MessageType: merged Subject: Change in asterixdb[master]: ASTERIXDB-1322: fix the AQL translator and add tests. X-Gerrit-Change-Id: I994bb69ca989c8c9e2ce417d62739a859e5ae94b X-Gerrit-ChangeURL: X-Gerrit-Commit: e3d0ecd260e50c5ddf344acc06ed3b50e5c7df3d In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Disposition: inline User-Agent: Gerrit/2.8.4 Message-Id: <20160226184847.14D8B2419D8@unhygienix.ics.uci.edu> Yingyi Bu has submitted this change and it was merged. Change subject: ASTERIXDB-1322: fix the AQL translator and add tests. ...................................................................... ASTERIXDB-1322: fix the AQL translator and add tests. Change-Id: I994bb69ca989c8c9e2ce417d62739a859e5ae94b Reviewed-on: https://asterix-gerrit.ics.uci.edu/663 Tested-by: Jenkins Reviewed-by: Till Westmann --- A asterix-app/data/csv/55.csv A asterix-app/src/test/resources/optimizerts/queries/udfs/query-ASTERIXDB-1308-1.aql A asterix-app/src/test/resources/optimizerts/queries/udfs/query-ASTERIXDB-1308-2.aql A asterix-app/src/test/resources/optimizerts/results/udfs/query-ASTERIXDB-1308-1.plan A asterix-app/src/test/resources/optimizerts/results/udfs/query-ASTERIXDB-1308-2.plan A asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-1/query-ASTERIXDB-1308-1.1.ddl.aql A asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-1/query-ASTERIXDB-1308-2.2.update.aql A asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-1/query-ASTERIXDB-1308-3.3.query.aql A asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-2/query-ASTERIXDB-1308-2.1.ddl.aql A asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-2/query-ASTERIXDB-1308.2.update.aql A asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-2/query-ASTERIXDB-1308.3.query.aql A asterix-app/src/test/resources/runtimets/results/user-defined-functions/query-ASTERIXDB-1308-1/query-ASTERIXDB-1308-1.1.adm M asterix-app/src/test/resources/runtimets/testsuite.xml M asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLCloneAndSubstituteVariablesVisitor.java 14 files changed, 515 insertions(+), 3 deletions(-) Approvals: Till Westmann: Looks good to me, approved Jenkins: Verified diff --git a/asterix-app/data/csv/55.csv b/asterix-app/data/csv/55.csv new file mode 100644 index 0000000..d154dc6 --- /dev/null +++ b/asterix-app/data/csv/55.csv @@ -0,0 +1,55 @@ +11,55,20140108,1,11:45:06,90,0.666666667 +12,55,20140108,1,11:45:07,90,0.666666667 +13,55,20140108,1,11:45:08,90,0.666666667 +14,55,20140108,1,11:45:08,90,0.666666667 +15,55,20140108,1,11:45:09,90,0.666666667 +16,55,20140108,1,11:45:10,90,0.666666667 +17,55,20140108,1,11:45:10,90,0.666666667 +18,55,20140108,1,11:45:11,90,0.666666667 +19,55,20140108,1,11:45:12,89,0.674157303 +20,55,20140108,1,11:45:12,90,0.666666667 +21,55,20140108,1,11:45:13,87,0.689655172 +22,55,20140108,1,11:45:14,86,0.697674419 +23,55,20140108,1,11:45:14,87,0.689655172 +24,55,20140108,1,11:45:15,92,0.652173913 +25,55,20140108,1,11:45:16,94,0.638297872 +26,55,20140108,1,11:45:16,97,0.618556701 +27,55,20140108,1,11:45:17,97,0.618556701 +28,55,20140108,1,11:45:17,95,0.631578947 +29,55,20140108,1,11:45:18,97,0.618556701 +30,55,20140108,1,11:45:19,99,0.606060606 +31,55,20140108,1,11:45:19,101,0.594059406 +32,55,20140108,1,11:45:20,103,0.582524272 +33,55,20140108,1,11:45:21,110,0.545454545 +34,55,20140108,1,11:45:21,104,0.576923077 +35,55,20140108,1,11:45:22,110,0.545454545 +36,55,20140108,1,11:45:22,117,0.512820513 +37,55,20140108,1,11:45:23,121,0.495867769 +38,55,20140108,1,11:45:23,125,0.48 +39,55,20140108,1,11:45:24,124,0.483870968 +40,55,20140108,1,11:45:24,123,0.487804878 +41,55,20140108,1,11:45:25,122,0.491803279 +42,55,20140108,1,11:45:25,121,0.495867769 +43,55,20140108,1,11:45:26,120,0.5 +44,55,20140108,1,11:45:26,119,0.504201681 +45,55,20140108,1,11:45:27,118,0.508474576 +46,55,20140108,1,11:45:27,117,0.512820513 +47,55,20140108,1,11:45:28,116,0.517241379 +48,55,20140108,1,11:45:28,115,0.52173913 +49,55,20140108,1,11:45:29,113,0.530973451 +50,55,20140108,1,11:45:29,113,0.530973451 +51,55,20140108,1,11:45:30,112,0.535714286 +52,55,20140108,1,11:45:30,111,0.540540541 +53,55,20140108,1,11:45:31,117,0.512820513 +54,55,20140108,1,11:45:31,115,0.52173913 +55,55,20140108,1,11:45:32,114,0.526315789 +56,55,20140108,1,11:45:32,113,0.530973451 +57,55,20140108,1,11:45:33,112,0.535714286 +58,55,20140108,1,11:45:33,105,0.571428571 +59,55,20140108,1,11:45:34,103,0.582524272 +60,55,20140108,1,11:45:35,103,0.582524272 +61,55,20140108,1,11:45:35,103,0.582524272 +62,55,20140108,1,11:45:36,103,0.582524272 +63,55,20140108,1,11:45:36,103,0.582524272 +64,55,20140108,1,11:45:37,103,0.582524272 +65,55,20140108,1,11:45:38,103,0.582524272 diff --git a/asterix-app/src/test/resources/optimizerts/queries/udfs/query-ASTERIXDB-1308-1.aql b/asterix-app/src/test/resources/optimizerts/queries/udfs/query-ASTERIXDB-1308-1.aql new file mode 100644 index 0000000..2f56f85 --- /dev/null +++ b/asterix-app/src/test/resources/optimizerts/queries/udfs/query-ASTERIXDB-1308-1.aql @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +declare function median($x) +{ + let $c := count($x) + return avg( + for $i at $p in (for $j in $x order by $j return $j) + where $p >= floor(($c-1)/2.0) and $p <= $c/2 + return $i + ) +} + + +declare function MAD($x) +{ + let $m := median($x) + return median(for $j in $x order by abs($j-$m) return abs($j-$m)) +} + +MAD([2, 3, 4, 1, 5, 6, 10, 0]) + diff --git a/asterix-app/src/test/resources/optimizerts/queries/udfs/query-ASTERIXDB-1308-2.aql b/asterix-app/src/test/resources/optimizerts/queries/udfs/query-ASTERIXDB-1308-2.aql new file mode 100644 index 0000000..028e436 --- /dev/null +++ b/asterix-app/src/test/resources/optimizerts/queries/udfs/query-ASTERIXDB-1308-2.aql @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +drop dataverse test if exists; +create dataverse test; +use dataverse test; + +create type HRMType as closed { + row_id: int32, + sid: int32, + date: date, + day: int32, + time: time, + bpm: int32, + RR: float +}; + +create dataset HRM(HRMType) primary key row_id; + +declare function median($x) +{ + let $c := count($x) + return avg( + for $i at $p in (for $j in $x order by $j return $j) + where $p >= floor(($c-1)/2.0) and $p <= $c/2 + return $i + ) +} + + +declare function MAD($x) +{ + let $m := median($x) + return median(for $j in $x order by abs($j-$m) return abs($j-$m)) +} + +for $i in dataset HRM +group by $sid := $i.sid, $gdate := $i.date, $gday := $i.day, +$timebin := interval-bin($i.time, time("00:00:00"), day-time-duration("PT15M")) with $i +return +{ + "sid": $sid, + "gdate": $gdate, + "gday": $gday, + "timebin": $timebin, + "stdv": (avg(for $ii in $i return $ii.RR * $ii.RR) - + avg(for $ii in $i return $ii.RR) * avg(for $ii in $i return $ii.RR))^(0.5), + "MAD": MAD(for $ii in $i return $ii.RR) +} + diff --git a/asterix-app/src/test/resources/optimizerts/results/udfs/query-ASTERIXDB-1308-1.plan b/asterix-app/src/test/resources/optimizerts/results/udfs/query-ASTERIXDB-1308-1.plan new file mode 100644 index 0000000..ebbee79 --- /dev/null +++ b/asterix-app/src/test/resources/optimizerts/results/udfs/query-ASTERIXDB-1308-1.plan @@ -0,0 +1,45 @@ +-- DISTRIBUTE_RESULT |LOCAL| + -- ONE_TO_ONE_EXCHANGE |LOCAL| + -- AGGREGATE |LOCAL| + -- AGGREGATE |LOCAL| + -- STREAM_PROJECT |UNPARTITIONED| + -- STREAM_SELECT |UNPARTITIONED| + -- STREAM_PROJECT |UNPARTITIONED| + -- ASSIGN |UNPARTITIONED| + -- STREAM_PROJECT |UNPARTITIONED| + -- UNNEST |UNPARTITIONED| + -- SUBPLAN |UNPARTITIONED| + { + -- AGGREGATE |UNPARTITIONED| + -- IN_MEMORY_STABLE_SORT [$$28(ASC)] |UNPARTITIONED| + -- UNNEST |UNPARTITIONED| + -- NESTED_TUPLE_SOURCE |UNPARTITIONED| + } + -- AGGREGATE |UNPARTITIONED| + -- ONE_TO_ONE_EXCHANGE |UNPARTITIONED| + -- STABLE_SORT [$$59(ASC)] |UNPARTITIONED| + -- ONE_TO_ONE_EXCHANGE |UNPARTITIONED| + -- STREAM_PROJECT |UNPARTITIONED| + -- ASSIGN |UNPARTITIONED| + -- STREAM_PROJECT |UNPARTITIONED| + -- UNNEST |UNPARTITIONED| + -- SUBPLAN |UNPARTITIONED| + { + -- SUBPLAN |UNPARTITIONED| + { + -- AGGREGATE |UNPARTITIONED| + -- STREAM_SELECT |UNPARTITIONED| + -- UNNEST |UNPARTITIONED| + -- SUBPLAN |UNPARTITIONED| + { + -- AGGREGATE |UNPARTITIONED| + -- IN_MEMORY_STABLE_SORT [$$21(ASC)] |UNPARTITIONED| + -- UNNEST |UNPARTITIONED| + -- NESTED_TUPLE_SOURCE |UNPARTITIONED| + } + -- NESTED_TUPLE_SOURCE |UNPARTITIONED| + } + -- NESTED_TUPLE_SOURCE |UNPARTITIONED| + } + -- ASSIGN |UNPARTITIONED| + -- EMPTY_TUPLE_SOURCE |UNPARTITIONED| diff --git a/asterix-app/src/test/resources/optimizerts/results/udfs/query-ASTERIXDB-1308-2.plan b/asterix-app/src/test/resources/optimizerts/results/udfs/query-ASTERIXDB-1308-2.plan new file mode 100644 index 0000000..a6e7496 --- /dev/null +++ b/asterix-app/src/test/resources/optimizerts/results/udfs/query-ASTERIXDB-1308-2.plan @@ -0,0 +1,75 @@ +-- DISTRIBUTE_RESULT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ASSIGN |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- SUBPLAN |PARTITIONED| + { + -- SUBPLAN |LOCAL| + { + -- SUBPLAN |LOCAL| + { + -- SUBPLAN |LOCAL| + { + -- AGGREGATE |LOCAL| + -- STREAM_SELECT |LOCAL| + -- ASSIGN |LOCAL| + -- UNNEST |LOCAL| + -- SUBPLAN |LOCAL| + { + -- AGGREGATE |LOCAL| + -- IN_MEMORY_STABLE_SORT [$$38(ASC)] |LOCAL| + -- UNNEST |LOCAL| + -- NESTED_TUPLE_SOURCE |LOCAL| + } + -- NESTED_TUPLE_SOURCE |LOCAL| + } + -- NESTED_TUPLE_SOURCE |LOCAL| + } + -- SUBPLAN |LOCAL| + { + -- AGGREGATE |LOCAL| + -- IN_MEMORY_STABLE_SORT [$$98(ASC)] |LOCAL| + -- ASSIGN |LOCAL| + -- UNNEST |LOCAL| + -- NESTED_TUPLE_SOURCE |LOCAL| + } + -- NESTED_TUPLE_SOURCE |LOCAL| + } + -- SUBPLAN |LOCAL| + { + -- SUBPLAN |LOCAL| + { + -- AGGREGATE |LOCAL| + -- STREAM_SELECT |LOCAL| + -- ASSIGN |LOCAL| + -- UNNEST |LOCAL| + -- SUBPLAN |LOCAL| + { + -- AGGREGATE |LOCAL| + -- IN_MEMORY_STABLE_SORT [$$31(ASC)] |LOCAL| + -- UNNEST |LOCAL| + -- NESTED_TUPLE_SOURCE |LOCAL| + } + -- NESTED_TUPLE_SOURCE |LOCAL| + } + -- NESTED_TUPLE_SOURCE |LOCAL| + } + -- NESTED_TUPLE_SOURCE |LOCAL| + } + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- PRE_CLUSTERED_GROUP_BY[$$94, $$95, $$96, $$97] |PARTITIONED| + { + -- AGGREGATE |LOCAL| + -- NESTED_TUPLE_SOURCE |LOCAL| + } + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- STABLE_SORT [$$94(ASC), $$95(ASC), $$96(ASC), $$97(ASC)] |PARTITIONED| + -- HASH_PARTITION_EXCHANGE [$$94, $$95, $$96, $$97] |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ASSIGN |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- DATASOURCE_SCAN |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- EMPTY_TUPLE_SOURCE |PARTITIONED| diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-1/query-ASTERIXDB-1308-1.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-1/query-ASTERIXDB-1308-1.1.ddl.aql new file mode 100644 index 0000000..042f3ce --- /dev/null +++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-1/query-ASTERIXDB-1308-1.1.ddl.aql @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-1/query-ASTERIXDB-1308-2.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-1/query-ASTERIXDB-1308-2.2.update.aql new file mode 100644 index 0000000..042f3ce --- /dev/null +++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-1/query-ASTERIXDB-1308-2.2.update.aql @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-1/query-ASTERIXDB-1308-3.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-1/query-ASTERIXDB-1308-3.3.query.aql new file mode 100644 index 0000000..9f7b9ec --- /dev/null +++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-1/query-ASTERIXDB-1308-3.3.query.aql @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +declare function median($x) +{ + let $c := count($x) + return avg( + for $i at $p in (for $j in $x order by $j return $j) + where $p-1 >= floor(($c-1)/2.0) and $p-1<= $c/2 + return $i + ) +} + + +declare function MAD($x) +{ + let $m := median($x) + return median(for $j in $x order by abs($j-$m) return abs($j-$m)) +} + + +median([2.0, 3.0, 4.0, 1.0, 5.0, 6.0, 10.0, 0.0]) +median([2.0, 3.0, 4.0, 1.0, 5.0, 6.0, 10.0]) + +MAD([2.0, 3.0, 4.0, 1.0, 5.0, 6.0, 10.0, 0.0]) +MAD([2.0, 3.0, 4.0, 1.0, 5.0, 6.0, 10.0]) + diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-2/query-ASTERIXDB-1308-2.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-2/query-ASTERIXDB-1308-2.1.ddl.aql new file mode 100644 index 0000000..6c4ede7 --- /dev/null +++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-2/query-ASTERIXDB-1308-2.1.ddl.aql @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +drop dataverse test if exists; +create dataverse test; +use dataverse test; + +create type HRMType_Raw as closed { + row_id: int32, + sid: int32, + date: string, + day: int32, + time: string, + bpm: int32, + RR: float +}; + +create dataset HRM_Raw(HRMType_Raw) primary key row_id; + + +create type HRMType as closed { + row_id: int32, + sid: int32, + date: date, + day: int32, + time: time, + bpm: int32, + RR: float +}; + +create dataset HRM(HRMType) primary key row_id; + diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-2/query-ASTERIXDB-1308.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-2/query-ASTERIXDB-1308.2.update.aql new file mode 100644 index 0000000..e97b903 --- /dev/null +++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-2/query-ASTERIXDB-1308.2.update.aql @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +use dataverse test; + +load dataset HRM_Raw using localfs + (("path"="asterix_nc1://data/csv/55.csv"), + ("format"="delimited-text"), + ("header"="true")); + +insert into dataset HRM +( + for $t in dataset HRM_Raw + return { + "row_id": $t.row_id, + "sid" : $t.sid, + "date" : parse-date($t.date, "YMD"), + "time" : parse-time($t.time, "h:m:s"), + "day" : $t.day, + "bpm" : $t.bpm, + "RR" : $t.RR +}) \ No newline at end of file diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-2/query-ASTERIXDB-1308.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-2/query-ASTERIXDB-1308.3.query.aql new file mode 100644 index 0000000..2d1ba32 --- /dev/null +++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/query-ASTERIXDB-1308-2/query-ASTERIXDB-1308.3.query.aql @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +use dataverse test; + +declare function median($x) +{ + let $c := count($x) + return avg( + for $i at $p in (for $j in $x order by $j return $j) + where $p >= floor(($c-1)/2.0) and $p <= $c/2 + return $i + ) +} + + +declare function MAD($x) +{ + let $m := median($x) + return median(for $j in $x order by abs($j-$m) return abs($j-$m)) +} + + +for $i in dataset HRM +group by $sid := $i.sid, $gdate := $i.date, $gday := $i.day, +$timebin := interval-bin($i.time, time("00:00:00"), day-time-duration("PT15M")) with $i +return +{ + "sid": $sid, + "gdate": $gdate, + "gday": $gday, + "timebin": $timebin, + "stdv": (avg(for $ii in $i return $ii.RR * $ii.RR) - + avg(for $ii in $i return $ii.RR) * avg(for $ii in $i return $ii.RR))^(0.5), + "MAD": MAD(for $ii in $i return $ii.RR) +} \ No newline at end of file diff --git a/asterix-app/src/test/resources/runtimets/results/user-defined-functions/query-ASTERIXDB-1308-1/query-ASTERIXDB-1308-1.1.adm b/asterix-app/src/test/resources/runtimets/results/user-defined-functions/query-ASTERIXDB-1308-1/query-ASTERIXDB-1308-1.1.adm new file mode 100644 index 0000000..c867567 --- /dev/null +++ b/asterix-app/src/test/resources/runtimets/results/user-defined-functions/query-ASTERIXDB-1308-1/query-ASTERIXDB-1308-1.1.adm @@ -0,0 +1,4 @@ +3.5d +4.0d +2.0d +2.0d diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml index 96a2c37..758c393 100644 --- a/asterix-app/src/test/resources/runtimets/testsuite.xml +++ b/asterix-app/src/test/resources/runtimets/testsuite.xml @@ -6053,6 +6053,16 @@ query-ASTERIXDB-1298 + + + query-ASTERIXDB-1308-1 + + +