[NO ISSUE][FUN] Allow frame in RATIO_TO_REPORT()
- user model changes: yes
- storage format changes: no
- interface changes: no
Details:
- Support frame specification in RATIO_TO_REPORT()
window function call
Change-Id: Ibc3686bebaf791aa84ef34d8fd143e53edc7856a
Reviewed-on: https://asterix-gerrit.ics.uci.edu/3449
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
index 1c5750c..988723f 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
@@ -1228,11 +1228,6 @@
createOperatorExpr(fargs.get(1), OperatorType.MINUS, new IntegerLiteral(1), sourceLoc);
} else if (BuiltinFunctions.RATIO_TO_REPORT_IMPL.equals(fi)) {
// ratio_to_report(x) over (...) --> x / sum(x) over (...)
- winFrameMode = WindowExpression.FrameMode.RANGE;
- winFrameStartKind = WindowExpression.FrameBoundaryKind.UNBOUNDED_PRECEDING;
- winFrameEndKind = WindowExpression.FrameBoundaryKind.CURRENT_ROW;
- winFrameExclusionKind = WindowExpression.FrameExclusionKind.NO_OTHERS;
-
nestedAggFunc = BuiltinFunctions.SCALAR_SQL_SUM;
postWinResultFunc = BuiltinFunctions.NUMERIC_DIVIDE;
postWinExpr = fargs.get(1);
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/ratio_to_report_01/ratio_to_report_01.8.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/ratio_to_report_01/ratio_to_report_01.8.query.sqlpp
new file mode 100644
index 0000000..9408641
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/window/ratio_to_report_01/ratio_to_report_01.8.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 RATIO_TO_REPORT() with frame specification
+ * Expected Res : SUCCESS
+ */
+
+FROM range(1, 2) x, range(1, 4) y
+SELECT x, y,
+ round_half_to_even(ratio_to_report(y) over (partition by x order by y rows between 1 preceding and 1 following), 2) rr
+ORDER BY x, y
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ratio_to_report_01/ratio_to_report_01.8.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ratio_to_report_01/ratio_to_report_01.8.adm
new file mode 100644
index 0000000..5ff1afc
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/window/ratio_to_report_01/ratio_to_report_01.8.adm
@@ -0,0 +1,8 @@
+{ "x": 1, "y": 1, "rr": 0.33 }
+{ "x": 1, "y": 2, "rr": 0.33 }
+{ "x": 1, "y": 3, "rr": 0.33 }
+{ "x": 1, "y": 4, "rr": 0.57 }
+{ "x": 2, "y": 1, "rr": 0.33 }
+{ "x": 2, "y": 2, "rr": 0.33 }
+{ "x": 2, "y": 3, "rr": 0.33 }
+{ "x": 2, "y": 4, "rr": 0.57 }
\ No newline at end of file
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
index 7afda20..5e2257a 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
@@ -2967,7 +2967,7 @@
addWindowFunction(NTILE, NTILE_IMPL, NO_FRAME_CLAUSE, MATERIALIZE_PARTITION);
addWindowFunction(PERCENT_RANK, PERCENT_RANK_IMPL, NO_FRAME_CLAUSE, INJECT_ORDER_ARGS, MATERIALIZE_PARTITION);
addWindowFunction(RANK, RANK_IMPL, NO_FRAME_CLAUSE, INJECT_ORDER_ARGS);
- addWindowFunction(RATIO_TO_REPORT, RATIO_TO_REPORT_IMPL, NO_FRAME_CLAUSE, HAS_LIST_ARG);
+ addWindowFunction(RATIO_TO_REPORT, RATIO_TO_REPORT_IMPL, HAS_LIST_ARG);
addWindowFunction(ROW_NUMBER, ROW_NUMBER_IMPL, NO_FRAME_CLAUSE);
addWindowFunction(WIN_PARTITION_LENGTH, WIN_PARTITION_LENGTH_IMPL, NO_FRAME_CLAUSE, MATERIALIZE_PARTITION);
}