You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2017/03/10 00:38:17 UTC
[3/4] calcite git commit: [CALCITE-1686] Only allow FINAL and other
functions inside MATCH_RECOGNIZE (Zhiqiang-He)
[CALCITE-1686] Only allow FINAL and other functions inside MATCH_RECOGNIZE (Zhiqiang-He)
Close apache/calcite#396
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/b20b7962
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/b20b7962
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/b20b7962
Branch: refs/heads/master
Commit: b20b79621301507f53022184e7e77e807b038fa4
Parents: 8e0d76b
Author: Zhiqiang-He <ab...@qq.com>
Authored: Thu Mar 9 17:03:37 2017 +0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Thu Mar 9 13:56:43 2017 -0800
----------------------------------------------------------------------
.../apache/calcite/runtime/CalciteResource.java | 3 +++
.../calcite/sql/validate/SqlValidatorImpl.java | 7 ++++++
.../calcite/runtime/CalciteResource.properties | 1 +
.../apache/calcite/test/SqlValidatorTest.java | 24 +++++++++-----------
4 files changed, 22 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/b20b7962/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
index 685344d..7bc99eb 100644
--- a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
+++ b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
@@ -683,6 +683,9 @@ public interface CalciteResource {
@BaseMessage("Multiple pattern variables in ''{0}''")
ExInst<SqlValidatorException> PatternFunctionVariableCheck(String call);
+
+ @BaseMessage("Function ''{0}'' can only be used in MATCH_RECOGNIZE")
+ ExInst<SqlValidatorException> FunctionMatchRecognizeOnly(String call);
}
// End CalciteResource.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/b20b7962/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
index 5ae0def..f9045a2 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
@@ -4418,6 +4418,13 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
SqlValidatorScope operandScope = scope.getOperandScope(call);
+ if (operator instanceof SqlFunction
+ && ((SqlFunction) operator).getFunctionType()
+ == SqlFunctionCategory.MATCH_RECOGNIZE
+ && !(operandScope instanceof MatchRecognizeScope)) {
+ throw newValidationError(call,
+ Static.RESOURCE.FunctionMatchRecognizeOnly(call.toString()));
+ }
// Delegate validation to the operator.
operator.validateCall(call, this, scope, operandScope);
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/b20b7962/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
----------------------------------------------------------------------
diff --git a/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties b/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
index 792ba2a..75cbe07 100644
--- a/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
+++ b/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
@@ -222,4 +222,5 @@ PatternAggregationInNavigation=Cannot use aggregation in navigation ''{0}''
PatternCountFunctionArg=Invalid number of parameters to COUNT method
PatternRunningFunctionInDefine=Cannot use RUNNING/FINAL in DEFINE ''{0}''
PatternFunctionVariableCheck=Multiple pattern variables in ''{0}''
+FunctionMatchRecognizeOnly=Function ''{0}'' can only be used in MATCH_RECOGNIZE
# End CalciteResource.properties
http://git-wip-us.apache.org/repos/asf/calcite/blob/b20b7962/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index f218064..45d8bf3 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -6992,7 +6992,7 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
checkFails("select ^fusion(deptno)^ from emp",
"(?s).*Cannot apply 'FUSION' to arguments of type 'FUSION.<INTEGER>.'.*");
check("select fusion(multiset[3]) from emp");
- // todo. FUSION is an aggregate function. test that validator only can
+ // todo. FUSION is an aggregate function. test that validator can only
// take set operators in its select list once aggregation support is
// complete
}
@@ -8953,20 +8953,18 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
.fails("No match found for function signature .*");
sql("values ^\"|\"(1, 2)^")
.fails("No match found for function signature .*");
- if (TODO) {
// FINAL and other functions should not be visible outside of
// MATCH_RECOGNIZE
- sql("values ^\"FINAL\"(1, 2)^")
- .fails("No match found for function signature .*");
- sql("values ^\"RUNNING\"(1, 2)^")
- .fails("No match found for function signature .*");
- sql("values ^\"FIRST\"(1, 2)^")
- .fails("No match found for function signature .*");
- sql("values ^\"LAST\"(1, 2)^")
- .fails("No match found for function signature .*");
- sql("values ^\"PREV\"(1, 2)^")
- .fails("No match found for function signature .*");
- }
+ sql("values ^\"FINAL\"(1, 2)^")
+ .fails("Function 'FINAL\\(1, 2\\)' can only be used in MATCH_RECOGNIZE");
+ sql("values ^\"RUNNING\"(1, 2)^")
+ .fails("Function 'RUNNING\\(1, 2\\)' can only be used in MATCH_RECOGNIZE");
+ sql("values ^\"FIRST\"(1, 2)^")
+ .fails("Function 'FIRST\\(1, 2\\)' can only be used in MATCH_RECOGNIZE");
+ sql("values ^\"LAST\"(1, 2)^")
+ .fails("Function 'LAST\\(1, 2\\)' can only be used in MATCH_RECOGNIZE");
+ sql("values ^\"PREV\"(1, 2)^")
+ .fails("Function 'PREV\\(1, 2\\)' can only be used in MATCH_RECOGNIZE");
}
@Test public void testMatchRecognizeDefines() throws Exception {