Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D5F1E200C47 for ; Thu, 30 Mar 2017 23:37:55 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D4CD5160BA1; Thu, 30 Mar 2017 21:37:55 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id EFF2E160BB4 for ; Thu, 30 Mar 2017 23:37:53 +0200 (CEST) Received: (qmail 53663 invoked by uid 500); 30 Mar 2017 21:37:53 -0000 Mailing-List: contact commits-help@calcite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@calcite.apache.org Delivered-To: mailing list commits@calcite.apache.org Received: (qmail 52262 invoked by uid 99); 30 Mar 2017 21:37:51 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Mar 2017 21:37:51 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9AC66E93E1; Thu, 30 Mar 2017 21:37:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: elserj@apache.org To: commits@calcite.apache.org Date: Thu, 30 Mar 2017 21:38:03 -0000 Message-Id: <8f23387325004b79ab899f1a20164442@git.apache.org> In-Reply-To: <527873398b6d4f8988ad3d5d1c749b55@git.apache.org> References: <527873398b6d4f8988ad3d5d1c749b55@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [13/50] [abbrv] calcite-avatica git commit: [CALCITE-1686] Only allow FINAL and other functions inside MATCH_RECOGNIZE (Zhiqiang-He) archived-at: Thu, 30 Mar 2017 21:37:55 -0000 [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-avatica/repo Commit: http://git-wip-us.apache.org/repos/asf/calcite-avatica/commit/b20b7962 Tree: http://git-wip-us.apache.org/repos/asf/calcite-avatica/tree/b20b7962 Diff: http://git-wip-us.apache.org/repos/asf/calcite-avatica/diff/b20b7962 Branch: refs/heads/master Commit: b20b79621301507f53022184e7e77e807b038fa4 Parents: 8e0d76b Author: Zhiqiang-He Authored: Thu Mar 9 17:03:37 2017 +0800 Committer: Julian Hyde 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-avatica/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 PatternFunctionVariableCheck(String call); + + @BaseMessage("Function ''{0}'' can only be used in MATCH_RECOGNIZE") + ExInst FunctionMatchRecognizeOnly(String call); } // End CalciteResource.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/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-avatica/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-avatica/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..'.*"); 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 {