You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by dl...@apache.org on 2018/11/01 03:54:42 UTC
[4/5] asterixdb git commit: [ASTERIXDB-2466][FUN] Implement window
functions
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/ntile_01/ntile_01.6.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/ntile_01/ntile_01.6.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/ntile_01/ntile_01.6.query.sqlpp
new file mode 100644
index 0000000..8bf71a8
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/ntile_01/ntile_01.6.query.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test NTILE()
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+from q0_rnd() rnd
+select q1_ntile(rnd.p, rnd.n, 5) res, rnd.p, rnd.n
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/ntile_01/ntile_01.7.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/ntile_01/ntile_01.7.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/ntile_01/ntile_01.7.query.sqlpp
new file mode 100644
index 0000000..e47db20
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/ntile_01/ntile_01.7.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test NTILE() without partition clause
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+q2_ntile_no_partition(7, 11)
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/ntile_02/ntile_02.1.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/ntile_02/ntile_02.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/ntile_02/ntile_02.1.query.sqlpp
new file mode 100644
index 0000000..3a46f18
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/ntile_02/ntile_02.1.query.sqlpp
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test NTILE() with a non-integer argument
+ * Expected Res : FAILURE
+ */
+
+from range(1,10) t
+select ntile("string") over (order by t desc)
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.1.ddl.sqlpp
new file mode 100644
index 0000000..841d9b0
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.1.ddl.sqlpp
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test PERCENT_RANK()
+ * Expected Res : SUCCESS
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use test;
+
+create type test.t1Type as open {
+ c1 : bigint
+};
+
+create dataset t1(t1Type) primary key c1;
+
+create dataset tRnd(t1Type) primary key c1;
+
+create function q0_rnd() {
+ let
+ rnd = tobigint((select value tRnd.rnd from tRnd where c1 = 1)[0] * 1000),
+ p = case when rnd >= 10 then rnd else 10 end,
+ n = tobigint( 1000 * 100 / p)
+ select p, n
+};
+
+create function q1_percent_rank(P, N, D) {
+ from
+ t1,
+ range(t1.one, P) p,
+ range(t1.one, N) n,
+ range(t1.one, D) d
+ let
+ rank = (N - n) * D + 1,
+ result_expected = (rank - 1) / (N * D - 1),
+ result_actual = percent_rank() over ( partition by t1.c2, p order by n desc ),
+ result_delta_raw = result_expected - result_actual,
+ result_delta = case when result_delta_raw < 0.001 then 0 else result_delta_raw end
+ select
+ min(result_delta) min_delta,
+ max(result_delta) max_delta
+};
+
+create function q2_percent_rank_no_partition(N, D) {
+ from
+ t1,
+ range(t1.one, N) n,
+ range(t1.one, D) d
+ let
+ rank = ((t1.c2 - 1) * N * D) + (N - n) * D + 1,
+ result_expected = (rank - 1) / (4 * N * D - 1),
+ result_actual = percent_rank() over ( order by t1.c2, n desc ),
+ result_delta_raw = result_expected - result_actual,
+ result_delta = case when result_delta_raw < 0.001 then 0 else result_delta_raw end
+ select
+ min(result_delta) min_delta,
+ max(result_delta) max_delta
+};
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.2.update.sqlpp
new file mode 100644
index 0000000..5c6d500
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.2.update.sqlpp
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test PERCENT_RANK()
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+set `import-private-functions` `true`;
+
+insert into t1
+select element { "c1":1, "c2": 1, "one": 1 };
+
+insert into t1
+select v c1, v c2, 1 one
+from range(2, (select value count(*) from storage_components("test","t1") t)[0]) v;
+
+insert into tRnd
+select 1 c1, random() rnd;
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.3.query.sqlpp
new file mode 100644
index 0000000..e091953
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.3.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test PERCENT_RANK()
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+q1_percent_rank(1, 2, 4)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.4.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.4.query.sqlpp
new file mode 100644
index 0000000..62f68dd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.4.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test PERCENT_RANK()
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+q1_percent_rank(1000, 10, 3)
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.5.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.5.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.5.query.sqlpp
new file mode 100644
index 0000000..3120eb3
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.5.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test PERCENT_RANK()
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+q1_percent_rank(10, 1000, 3)
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.6.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.6.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.6.query.sqlpp
new file mode 100644
index 0000000..8f38718
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.6.query.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test PERCENT_RANK()
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+from q0_rnd() rnd
+select q1_percent_rank(rnd.p, rnd.n, 3) res, rnd.p, rnd.n
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.7.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.7.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.7.query.sqlpp
new file mode 100644
index 0000000..a3b9352
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/percent_rank_01/percent_rank_01.7.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test PERCENT_RANK() without partition clause
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+q2_percent_rank_no_partition(7, 11)
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.1.ddl.sqlpp
new file mode 100644
index 0000000..020fe8d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.1.ddl.sqlpp
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test RANK()
+ * Expected Res : SUCCESS
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use test;
+
+create type test.t1Type as open {
+ c1 : bigint
+};
+
+create dataset t1(t1Type) primary key c1;
+
+create dataset tRnd(t1Type) primary key c1;
+
+create function q0_rnd() {
+ let
+ rnd = tobigint((select value tRnd.rnd from tRnd where c1 = 1)[0] * 1000),
+ p = case when rnd >= 10 then rnd else 10 end,
+ n = tobigint( 1000 * 100 / p)
+ select p, n
+};
+
+create function q1_rank(P, N, D) {
+ from
+ t1,
+ range(t1.one, P) p,
+ range(t1.one, N) n,
+ range(t1.one, D) d
+ let
+ result_expected = (N - n) * D + 1,
+ result_actual = rank() over ( partition by t1.c2, p order by n desc ),
+ result_delta = result_expected - result_actual
+ select
+ min(result_delta) min_delta,
+ max(result_delta) max_delta
+};
+
+create function q2_rank_no_partition(N, D) {
+ from
+ t1,
+ range(t1.one, N) n,
+ range(t1.one, D) d
+ let
+ result_expected = ((t1.c2 - 1) * N * D) + (N - n) * D + 1,
+ result_actual = rank() over ( order by t1.c2, n desc ),
+ result_delta = result_expected - result_actual
+ select
+ min(result_delta) min_delta,
+ max(result_delta) max_delta
+};
+
+
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.2.update.sqlpp
new file mode 100644
index 0000000..8c4147f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.2.update.sqlpp
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test RANK()
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+set `import-private-functions` `true`;
+
+insert into t1
+select element { "c1":1, "c2": 1, "one": 1 };
+
+insert into t1
+select v c1, v c2, 1 one
+from range(2, (select value count(*) from storage_components("test","t1") t)[0]) v;
+
+insert into tRnd
+select 1 c1, random() rnd;
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.3.query.sqlpp
new file mode 100644
index 0000000..914d7c2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.3.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test RANK()
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+q1_rank(1, 1, 3)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.4.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.4.query.sqlpp
new file mode 100644
index 0000000..2c34967
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.4.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test RANK()
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+q1_rank(1000, 10, 3)
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.5.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.5.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.5.query.sqlpp
new file mode 100644
index 0000000..b489f29
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.5.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test RANK()
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+q1_rank(10, 1000, 3)
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.6.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.6.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.6.query.sqlpp
new file mode 100644
index 0000000..eb214f5
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.6.query.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test RANK()
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+from q0_rnd() rnd
+select q1_rank(rnd.p, rnd.n, 3) res, rnd.p, rnd.n
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.7.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.7.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.7.query.sqlpp
new file mode 100644
index 0000000..83687ab
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/rank_01/rank_01.7.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test RANK() without partition clause
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+q2_rank_no_partition(7, 11)
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.1.ddl.sqlpp
new file mode 100644
index 0000000..5943177
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.1.ddl.sqlpp
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test ROW_NUMBER()
+ * Expected Res : SUCCESS
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use test;
+
+create type test.t1Type as open {
+ c1 : bigint
+};
+
+create dataset t1(t1Type) primary key c1;
+
+create dataset tRnd(t1Type) primary key c1;
+
+create function q0_rnd() {
+ let
+ rnd = tobigint((select value tRnd.rnd from tRnd where c1 = 1)[0] * 1000),
+ p = case when rnd >= 10 then rnd else 10 end,
+ n = tobigint( 1000 * 100 / p)
+ select p, n
+};
+
+create function q1_row_number(P, N, D) {
+ from
+ t1,
+ range(t1.one, P) p,
+ range(t1.one, N) n,
+ range(t1.one, D) d
+ let
+ result_expected = (N - n) * D + d,
+ result_actual = row_number() over ( partition by t1.c2, p order by n desc, d ),
+ result_delta = result_expected - result_actual
+ select
+ min(result_delta) min_delta,
+ max(result_delta) max_delta
+};
+
+create function q2_row_number_no_partition(N, D) {
+ from
+ t1,
+ range(t1.one, N) n,
+ range(t1.one, D) d
+ let
+ result_expected = ((t1.c2 - 1) * N * D) + ((N - n) * D + d),
+ result_actual = row_number() over ( order by t1.c2, n desc, d ),
+ result_delta = result_expected - result_actual
+ select
+ min(result_delta) min_delta,
+ max(result_delta) max_delta
+};
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.2.update.sqlpp
new file mode 100644
index 0000000..3691f05
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.2.update.sqlpp
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test ROW_NUMBER()
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+set `import-private-functions` `true`;
+
+insert into t1
+select element { "c1":1, "c2": 1, "one": 1 };
+
+insert into t1
+select v c1, v c2, 1 one
+from range(2, (select value count(*) from storage_components("test","t1") t)[0]) v;
+
+insert into tRnd
+select 1 c1, random() rnd;
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.3.query.sqlpp
new file mode 100644
index 0000000..659d3e7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.3.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test ROW_NUMBER()
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+q1_row_number(1, 1, 3)
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.4.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.4.query.sqlpp
new file mode 100644
index 0000000..e8122d7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.4.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test ROW_NUMBER()
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+q1_row_number(1000, 10, 3)
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.5.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.5.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.5.query.sqlpp
new file mode 100644
index 0000000..381871b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.5.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test ROW_NUMBER()
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+q1_row_number(10, 1000, 3)
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.6.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.6.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.6.query.sqlpp
new file mode 100644
index 0000000..672511c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.6.query.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test ROW_NUMBER()
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+from q0_rnd() rnd
+select q1_row_number(rnd.p, rnd.n, 3) res, rnd.p, rnd.n
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.7.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.7.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.7.query.sqlpp
new file mode 100644
index 0000000..80c54f4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/row_number_01/row_number_01.7.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test ROW_NUMBER() without partition clause
+ * Expected Res : SUCCESS
+ */
+
+use test;
+
+q2_row_number_no_partition(7, 11)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.3.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.3.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.3.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.4.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.4.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.4.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.5.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.5.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.5.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.5.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.6.regexadm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.6.regexadm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.6.regexadm
new file mode 100644
index 0000000..7278103
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.6.regexadm
@@ -0,0 +1 @@
+.*"min_delta": 0, "max_delta": 0.*
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.7.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.7.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.7.adm
new file mode 100644
index 0000000..6115ead
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/dense_rank_01/dense_rank_01.7.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/misc_01/misc_01.3.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/misc_01/misc_01.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/misc_01/misc_01.3.adm
new file mode 100644
index 0000000..42b9daf
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/misc_01/misc_01.3.adm
@@ -0,0 +1 @@
+{ "rank_min_delta": 0, "rank_max_delta": 0, "percent_rank_min_delta": 0, "percent_rank_max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/misc_01/misc_01.4.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/misc_01/misc_01.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/misc_01/misc_01.4.adm
new file mode 100644
index 0000000..711a89b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/misc_01/misc_01.4.adm
@@ -0,0 +1,4 @@
+{ "p": 1, "rn": 4 }
+{ "p": 2, "rn": 3 }
+{ "p": 3, "rn": 2 }
+{ "p": 4, "rn": 1 }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/misc_01/misc_01.5.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/misc_01/misc_01.5.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/misc_01/misc_01.5.adm
new file mode 100644
index 0000000..4e533c1
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/misc_01/misc_01.5.adm
@@ -0,0 +1,4 @@
+{ "p": 1, "gg": [ { "c1": 1, "rn": 4 }, { "c1": 2, "rn": 3 }, { "c1": 3, "rn": 2 }, { "c1": 4, "rn": 1 } ] }
+{ "p": 2, "gg": [ { "c1": 1, "rn": 4 }, { "c1": 2, "rn": 3 }, { "c1": 3, "rn": 2 }, { "c1": 4, "rn": 1 } ] }
+{ "p": 3, "gg": [ { "c1": 1, "rn": 4 }, { "c1": 2, "rn": 3 }, { "c1": 3, "rn": 2 }, { "c1": 4, "rn": 1 } ] }
+{ "p": 4, "gg": [ { "c1": 1, "rn": 4 }, { "c1": 2, "rn": 3 }, { "c1": 3, "rn": 2 }, { "c1": 4, "rn": 1 } ] }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.3.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.3.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.3.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.4.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.4.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.4.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.5.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.5.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.5.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.5.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.6.regexadm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.6.regexadm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.6.regexadm
new file mode 100644
index 0000000..7278103
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.6.regexadm
@@ -0,0 +1 @@
+.*"min_delta": 0, "max_delta": 0.*
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.7.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.7.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.7.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ntile_01/ntile_01.7.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.3.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.3.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.3.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.4.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.4.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.4.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.5.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.5.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.5.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.5.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.6.regexadm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.6.regexadm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.6.regexadm
new file mode 100644
index 0000000..7278103
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.6.regexadm
@@ -0,0 +1 @@
+.*"min_delta": 0, "max_delta": 0.*
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.7.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.7.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.7.adm
new file mode 100644
index 0000000..6115ead
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/percent_rank_01/percent_rank_01.7.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.3.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.3.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.3.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.4.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.4.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.4.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.5.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.5.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.5.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.5.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.6.regexadm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.6.regexadm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.6.regexadm
new file mode 100644
index 0000000..7278103
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.6.regexadm
@@ -0,0 +1 @@
+.*"min_delta": 0, "max_delta": 0.*
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.7.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.7.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.7.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/rank_01/rank_01.7.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.3.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.3.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.3.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.4.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.4.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.4.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.5.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.5.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.5.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.5.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.6.regexadm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.6.regexadm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.6.regexadm
new file mode 100644
index 0000000..7278103
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.6.regexadm
@@ -0,0 +1 @@
+.*"min_delta": 0, "max_delta": 0.*
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.7.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.7.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.7.adm
new file mode 100644
index 0000000..6a071d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/row_number_01/row_number_01.7.adm
@@ -0,0 +1 @@
+{ "min_delta": 0, "max_delta": 0 }
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 1a9c7dd..591d441 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -8933,6 +8933,45 @@
</compilation-unit>
</test-case>
</test-group>
+ <test-group name="window">
+ <test-case FilePath="window">
+ <compilation-unit name="dense_rank_01">
+ <output-dir compare="Text">dense_rank_01</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="window">
+ <compilation-unit name="misc_01">
+ <output-dir compare="Text">misc_01</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="window">
+ <compilation-unit name="ntile_01">
+ <output-dir compare="Text">ntile_01</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="window">
+ <compilation-unit name="ntile_02">
+ <output-dir compare="Text">ntile_01</output-dir>
+ <expected-error>ASX0002: Type mismatch</expected-error>
+ <source-location>false</source-location>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="window">
+ <compilation-unit name="percent_rank_01">
+ <output-dir compare="Text">percent_rank_01</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="window">
+ <compilation-unit name="rank_01">
+ <output-dir compare="Text">rank_01</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="window">
+ <compilation-unit name="row_number_01">
+ <output-dir compare="Text">row_number_01</output-dir>
+ </compilation-unit>
+ </test-case>
+ </test-group>
<test-group name="writers">
<test-case FilePath="writers">
<compilation-unit name="print_01">
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
index 1bf2447..0bf446e 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
@@ -180,6 +180,7 @@ public class ErrorCode {
public static final int ILLEGAL_SET_PARAMETER = 1092;
public static final int COMPILATION_TRANSLATION_ERROR = 1093;
public static final int RANGE_MAP_ERROR = 1094;
+ public static final int COMPILATION_EXPECTED_FUNCTION_CALL = 1095;
// Feed errors
public static final int DATAFLOW_ILLEGAL_STATE = 3001;
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
index 5629b97..8c17ec6 100644
--- a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
+++ b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
@@ -167,6 +167,7 @@
1092 = Parameter %1$s cannot be set
1093 = A parser error has occurred. The detail exception: %1$s
1094 = Cannot parse range map: %1$s
+1095 = Expected function call
# Feed Errors
3001 = Illegal state.
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/Expression.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/Expression.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/Expression.java
index 3afff76..1066408 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/Expression.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/Expression.java
@@ -38,6 +38,7 @@ public interface Expression extends ILangExpression {
UNION_EXPRESSION,
SELECT_EXPRESSION,
PRIMARY_EXPRESSION,
- CASE_EXPRESSION
+ CASE_EXPRESSION,
+ WINDOW_EXPRESSION
}
}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/CloneAndSubstituteVariablesVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/CloneAndSubstituteVariablesVisitor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/CloneAndSubstituteVariablesVisitor.java
index e415a63..0b907bc 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/CloneAndSubstituteVariablesVisitor.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/CloneAndSubstituteVariablesVisitor.java
@@ -242,7 +242,7 @@ public class CloneAndSubstituteVariablesVisitor extends
VariableSubstitutionEnvironment env) throws CompilationException {
List<Expression> exprList =
VariableCloneAndSubstitutionUtil.visitAndCloneExprList(oc.getOrderbyList(), env, this);
- OrderbyClause oc2 = new OrderbyClause(exprList, oc.getModifierList());
+ OrderbyClause oc2 = new OrderbyClause(exprList, new ArrayList<>(oc.getModifierList()));
oc2.setNumFrames(oc.getNumFrames());
oc2.setNumTuples(oc.getNumTuples());
oc2.setRangeMap(oc.getRangeMap());
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/FormatPrintVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/FormatPrintVisitor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/FormatPrintVisitor.java
index 7ba01ce..c7f2a5d 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/FormatPrintVisitor.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/FormatPrintVisitor.java
@@ -295,20 +295,7 @@ public class FormatPrintVisitor implements ILangVisitor<Void, Integer> {
@Override
public Void visit(OrderbyClause oc, Integer step) throws CompilationException {
out.print(skip(step) + "order by ");
- List<OrderModifier> mlist = oc.getModifierList();
- List<Expression> list = oc.getOrderbyList();
- int index = 0;
- int size = list.size();
- for (Expression expr : oc.getOrderbyList()) {
- expr.accept(this, step);
- OrderModifier orderModifier = mlist.get(index);
- if (orderModifier != OrderModifier.ASC) {
- out.print(" " + orderModifier.toString().toLowerCase());
- }
- if (++index < size) {
- out.print(COMMA);
- }
- }
+ printDelimitedObyExpressions(oc.getOrderbyList(), oc.getModifierList(), step);
out.println();
return null;
}
@@ -897,6 +884,22 @@ public class FormatPrintVisitor implements ILangVisitor<Void, Integer> {
}
}
+ protected void printDelimitedObyExpressions(List<Expression> list, List<OrderModifier> mlist, Integer step)
+ throws CompilationException {
+ int index = 0;
+ int size = list.size();
+ for (Expression expr : list) {
+ expr.accept(this, step);
+ OrderModifier orderModifier = mlist.get(index);
+ if (orderModifier != OrderModifier.ASC) {
+ out.print(orderModifier.toString().toLowerCase());
+ }
+ if (++index < size) {
+ out.print(COMMA);
+ }
+ }
+ }
+
protected void printDelimitedExpressions(List<? extends Expression> exprs, String delimiter, int step)
throws CompilationException {
int index = 0;
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/WindowExpression.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/WindowExpression.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/WindowExpression.java
new file mode 100644
index 0000000..d1c4e59
--- /dev/null
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/WindowExpression.java
@@ -0,0 +1,105 @@
+/*
+ * 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.
+ */
+
+package org.apache.asterix.lang.sqlpp.expression;
+
+import java.util.List;
+
+import org.apache.asterix.common.exceptions.CompilationException;
+import org.apache.asterix.lang.common.base.AbstractExpression;
+import org.apache.asterix.lang.common.base.Expression;
+import org.apache.asterix.lang.common.clause.OrderbyClause;
+import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
+import org.apache.asterix.lang.sqlpp.visitor.base.ISqlppVisitor;
+
+public class WindowExpression extends AbstractExpression {
+ private Expression expr;
+ private List<Expression> partitionList;
+ private List<Expression> orderbyList;
+ private List<OrderbyClause.OrderModifier> orderbyModifierList;
+
+ public WindowExpression(Expression expr, List<Expression> partitionList, List<Expression> orderbyList,
+ List<OrderbyClause.OrderModifier> orderbyModifierList) {
+ if (expr == null || orderbyList == null) {
+ throw new NullPointerException();
+ }
+ this.expr = expr;
+ this.partitionList = partitionList;
+ this.orderbyList = orderbyList;
+ this.orderbyModifierList = orderbyModifierList;
+ }
+
+ @Override
+ public Kind getKind() {
+ return Kind.WINDOW_EXPRESSION;
+ }
+
+ public Expression getExpr() {
+ return expr;
+ }
+
+ public void setExpr(Expression expr) {
+ if (expr == null) {
+ throw new NullPointerException();
+ }
+ this.expr = expr;
+ }
+
+ public boolean hasPartitionList() {
+ return partitionList != null && !partitionList.isEmpty();
+ }
+
+ public List<Expression> getPartitionList() {
+ return partitionList;
+ }
+
+ public void setPartitionList(List<Expression> partitionList) {
+ if (partitionList == null) {
+ throw new NullPointerException();
+ }
+ this.partitionList = partitionList;
+ }
+
+ public List<Expression> getOrderbyList() {
+ return orderbyList;
+ }
+
+ public void setOrderbyList(List<Expression> orderbyList) {
+ if (orderbyList == null) {
+ throw new NullPointerException();
+ }
+ this.orderbyList = orderbyList;
+ }
+
+ public List<OrderbyClause.OrderModifier> getOrderbyModifierList() {
+ return orderbyModifierList;
+ }
+
+ public void setOrderbyModifierList(List<OrderbyClause.OrderModifier> orderbyModifierList) {
+ if (orderbyModifierList == null) {
+ throw new NullPointerException();
+ }
+ this.orderbyModifierList = orderbyModifierList;
+ }
+
+ @Override
+ public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
+ return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
+ }
+}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
index ec8b011..5aa5a8c 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
@@ -50,6 +50,7 @@ import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation;
import org.apache.asterix.lang.sqlpp.clause.UnnestClause;
import org.apache.asterix.lang.sqlpp.expression.CaseExpression;
import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
+import org.apache.asterix.lang.sqlpp.expression.WindowExpression;
import org.apache.asterix.lang.sqlpp.parser.FunctionParser;
import org.apache.asterix.lang.sqlpp.parser.SqlppParserFactory;
import org.apache.asterix.lang.sqlpp.rewrites.visitor.GenerateColumnNameVisitor;
@@ -392,5 +393,18 @@ public class SqlppQueryRewriter implements IQueryRewriter {
return null;
}
+ @Override
+ public Void visit(WindowExpression winExpr, Void arg) throws CompilationException {
+ winExpr.getExpr().accept(this, arg);
+ if (winExpr.hasPartitionList()) {
+ for (Expression expr : winExpr.getPartitionList()) {
+ expr.accept(this, arg);
+ }
+ }
+ for (Expression expr : winExpr.getOrderbyList()) {
+ expr.accept(this, arg);
+ }
+ return null;
+ }
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppInlineUdfsVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppInlineUdfsVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppInlineUdfsVisitor.java
index db5b780..c9b2dea 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppInlineUdfsVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppInlineUdfsVisitor.java
@@ -44,6 +44,7 @@ import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation;
import org.apache.asterix.lang.sqlpp.clause.UnnestClause;
import org.apache.asterix.lang.sqlpp.expression.CaseExpression;
import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
+import org.apache.asterix.lang.sqlpp.expression.WindowExpression;
import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
import org.apache.asterix.lang.sqlpp.util.SqlppRewriteUtil;
import org.apache.asterix.lang.sqlpp.visitor.SqlppCloneAndSubstituteVariablesVisitor;
@@ -243,6 +244,22 @@ public class SqlppInlineUdfsVisitor extends AbstractInlineUdfsVisitor
return inlined || result.first;
}
+ @Override
+ public Boolean visit(WindowExpression winExpr, List<FunctionDecl> funcs) throws CompilationException {
+ Pair<Boolean, Expression> result = inlineUdfsInExpr(winExpr.getExpr(), funcs);
+ winExpr.setExpr(result.second);
+ boolean inlined = result.first;
+ if (winExpr.hasPartitionList()) {
+ Pair<Boolean, List<Expression>> inlinedList = inlineUdfsInExprList(winExpr.getPartitionList(), funcs);
+ winExpr.setPartitionList(inlinedList.second);
+ inlined |= inlinedList.first;
+ }
+ Pair<Boolean, List<Expression>> inlinedList = inlineUdfsInExprList(winExpr.getOrderbyList(), funcs);
+ winExpr.setOrderbyList(inlinedList.second);
+ inlined |= inlinedList.first;
+ return inlined;
+ }
+
private Map<Expression, Expression> extractLetBindingVariableExpressionMappings(List<LetClause> letClauses)
throws CompilationException {
Map<Expression, Expression> varExprMap = new HashMap<>();
@@ -253,5 +270,4 @@ public class SqlppInlineUdfsVisitor extends AbstractInlineUdfsVisitor
}
return varExprMap;
}
-
}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckDatasetOnlyResolutionVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckDatasetOnlyResolutionVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckDatasetOnlyResolutionVisitor.java
index fe0c3a9..42b43e8 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckDatasetOnlyResolutionVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckDatasetOnlyResolutionVisitor.java
@@ -54,6 +54,7 @@ import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation;
import org.apache.asterix.lang.sqlpp.clause.UnnestClause;
import org.apache.asterix.lang.sqlpp.expression.CaseExpression;
import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
+import org.apache.asterix.lang.sqlpp.expression.WindowExpression;
import org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppQueryExpressionVisitor;
/**
@@ -228,4 +229,9 @@ public class CheckDatasetOnlyResolutionVisitor extends AbstractSqlppQueryExpress
public Boolean visit(CaseExpression caseExpr, ILangExpression arg) throws CompilationException {
return false;
}
+
+ @Override
+ public Boolean visit(WindowExpression windowExpression, ILangExpression arg) throws CompilationException {
+ return false;
+ }
}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java
index cd91405..6ea21a6 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java
@@ -57,6 +57,7 @@ import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation;
import org.apache.asterix.lang.sqlpp.clause.UnnestClause;
import org.apache.asterix.lang.sqlpp.expression.CaseExpression;
import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
+import org.apache.asterix.lang.sqlpp.expression.WindowExpression;
import org.apache.asterix.lang.sqlpp.util.FunctionMapUtil;
import org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppQueryExpressionVisitor;
@@ -274,4 +275,10 @@ public class CheckSql92AggregateVisitor extends AbstractSqlppQueryExpressionVisi
|| visitExprList(caseExpr.getThenExprs(), arg) || caseExpr.getElseExpr().accept(this, arg);
}
+ @Override
+ public Boolean visit(WindowExpression winExpr, ILangExpression arg) throws CompilationException {
+ return winExpr.getExpr().accept(this, arg)
+ || (winExpr.hasPartitionList() && visitExprList(winExpr.getPartitionList(), arg))
+ || visitExprList(winExpr.getOrderbyList(), arg);
+ }
}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSubqueryVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSubqueryVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSubqueryVisitor.java
index c53d8d2..34e918e 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSubqueryVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSubqueryVisitor.java
@@ -61,6 +61,7 @@ import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation;
import org.apache.asterix.lang.sqlpp.clause.UnnestClause;
import org.apache.asterix.lang.sqlpp.expression.CaseExpression;
import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
+import org.apache.asterix.lang.sqlpp.expression.WindowExpression;
import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
import org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppQueryExpressionVisitor;
import org.apache.hyracks.algebricks.common.utils.Pair;
@@ -287,6 +288,12 @@ public class CheckSubqueryVisitor extends AbstractSqlppQueryExpressionVisitor<Bo
}
@Override
+ public Boolean visit(WindowExpression winExpr, ILangExpression arg) throws CompilationException {
+ return visit(winExpr.getExpr(), arg) || (winExpr.hasPartitionList() && visit(winExpr.getPartitionList(), arg))
+ || visit(winExpr.getOrderbyList(), arg);
+ }
+
+ @Override
public Boolean visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
return visit(callExpr.getExprList(), arg);
}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fdedf626/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/DeepCopyVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/DeepCopyVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/DeepCopyVisitor.java
index 766540e..7dca268 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/DeepCopyVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/DeepCopyVisitor.java
@@ -65,6 +65,7 @@ import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation;
import org.apache.asterix.lang.sqlpp.clause.UnnestClause;
import org.apache.asterix.lang.sqlpp.expression.CaseExpression;
import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
+import org.apache.asterix.lang.sqlpp.expression.WindowExpression;
import org.apache.asterix.lang.sqlpp.struct.SetOperationInput;
import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
import org.apache.asterix.lang.sqlpp.visitor.base.AbstractSqlppQueryExpressionVisitor;
@@ -283,7 +284,7 @@ public class DeepCopyVisitor extends AbstractSqlppQueryExpressionVisitor<ILangEx
for (Expression orderExpr : oc.getOrderbyList()) {
newOrderbyList.add((Expression) orderExpr.accept(this, arg));
}
- OrderbyClause copy = new OrderbyClause(newOrderbyList, oc.getModifierList());
+ OrderbyClause copy = new OrderbyClause(newOrderbyList, new ArrayList<>(oc.getModifierList()));
copy.setSourceLocation(oc.getSourceLocation());
return copy;
}
@@ -495,6 +496,19 @@ public class DeepCopyVisitor extends AbstractSqlppQueryExpressionVisitor<ILangEx
return copy;
}
+ @Override
+ public ILangExpression visit(WindowExpression winExpr, Void arg) throws CompilationException {
+ Expression newExpr = (Expression) winExpr.getExpr().accept(this, arg);
+ List<Expression> newPartitionList =
+ winExpr.hasPartitionList() ? copyExprList(winExpr.getPartitionList(), arg) : null;
+ List<Expression> newOrderbyList = copyExprList(winExpr.getOrderbyList(), arg);
+ List<OrderbyClause.OrderModifier> newOrderbyModifierList = new ArrayList<>(winExpr.getOrderbyModifierList());
+ WindowExpression copy = new WindowExpression(newExpr, newPartitionList, newOrderbyList, newOrderbyModifierList);
+ copy.setSourceLocation(winExpr.getSourceLocation());
+ copy.addHints(winExpr.getHints());
+ return copy;
+ }
+
private List<Expression> copyExprList(List<Expression> exprs, Void arg) throws CompilationException {
List<Expression> newExprList = new ArrayList<>();
for (Expression expr : exprs) {